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>>
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"
shared_ptr< WebSocketChannel > createChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket-based channel using websocket::Endpoint.
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context) override
process face_system.websocket config section
NFD_REGISTER_PROTOCOL_FACTORY(EthernetFactory)
protocol factory for WebSocket
Parameters to ProtocolFactory::createFace.
FaceCreatedCallback addFace
callback when a new face is created
Provides support for an underlying protocol.
Copyright (c) 2011-2015 Regents of the University of California.
static const std::string & getId()
void createFace(const CreateFaceParams ¶ms, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
unicast face creation is not supported and will always fail
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
Parameters to ProtocolFactory constructor.
context for processing a config section in ProtocolFactory
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
#define NFD_LOG_WARN(expression)
WebSocketFactory(const CtorParams ¶ms)
std::vector< shared_ptr< const Channel > > getChannels() const override
static std::vector< shared_ptr< const Channel > > getChannelsFromMap(const ChannelMap &channelMap)
boost::asio::ip::tcp::endpoint Endpoint
#define NFD_LOG_INIT(name)
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...