31 namespace ip = boost::asio::ip;
39 static std::string id(
"websocket");
60 bool wantListen =
false;
67 for (
const auto& pair : *configSection) {
68 const std::string& key = pair.first;
70 if (key ==
"listen") {
73 else if (key ==
"port") {
74 port = ConfigFile::parseNumber<uint16_t>(pair,
"face_system.websocket");
76 else if (key ==
"enable_v4") {
79 else if (key ==
"enable_v6") {
83 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option face_system.websocket." + key));
88 if (!enableV4 && !enableV6) {
90 "IPv4 and IPv6 WebSocket channels have been disabled. Remove face_system.websocket section " 91 "to disable WebSocket channels or enable at least one channel type."));
94 if (!enableV4 && enableV6) {
96 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"NFD does not allow pure IPv6 WebSocket channel."));
101 if (!m_channels.empty()) {
102 NFD_LOG_WARN(
"Cannot close WebSocket channel after initialization");
107 BOOST_ASSERT(enableV4);
111 if (!channel->isListening()) {
112 channel->listen(this->
addFace);
113 if (m_channels.size() > 1) {
114 NFD_LOG_WARN(
"Adding WebSocket channel for new endpoint; cannot close existing channels");
125 onFailure(406,
"Unsupported protocol");
128 shared_ptr<WebSocketChannel>
131 auto it = m_channels.find(endpoint);
132 if (it != m_channels.end())
135 auto channel = make_shared<WebSocketChannel>(endpoint);
136 m_channels[endpoint] = channel;
141 std::vector<shared_ptr<const Channel>>
FaceCreatedCallback addFace
callback when a new face is created
static bool parseYesNo(const ConfigSection &node, const std::string &key, const std::string §ionName)
parse a config option that can be either "yes" or "no"
#define NFD_REGISTER_PROTOCOL_FACTORY(PF)
registers a protocol factory
WebSocketFactory(const CtorParams ¶ms)
#define NFD_LOG_WARN(expression)
context for processing a config section in ProtocolFactory
static std::vector< shared_ptr< const Channel > > getChannelsFromMap(const ChannelMap &channelMap)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
shared_ptr< WebSocketChannel > createChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket-based channel using websocket::Endpoint.
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
void createFace(const CreateFaceParams ¶ms, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
unicast face creation is not supported and will always fail
Provides support for an underlying protocol.
Parameters to ProtocolFactory constructor.
#define NFD_LOG_INIT(name)
std::vector< shared_ptr< const Channel > > getChannels() const override
Parameters to ProtocolFactory::createFace.
boost::asio::ip::tcp::endpoint Endpoint
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context) override
process face_system.websocket config section
static const std::string & getId()
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...