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>>
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.
function< void(const shared_ptr< Face > &face)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
void processConfig(OptionalConfigSection configSection, FaceSystem::ConfigContext &context) override
process face_system.websocket config section
NFD_REGISTER_PROTOCOL_FACTORY(EthernetFactory)
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
protocol factory for WebSocket
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()
boost::optional< const ConfigSection & > OptionalConfigSection
an optional config file section
Parameters to ProtocolFactory constructor.
void createFace(const CreateFaceRequest &req, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
unicast face creation is not supported and will always fail
context for processing a config section in ProtocolFactory
#define NFD_LOG_WARN(expression)
WebSocketFactory(const CtorParams ¶ms)
std::vector< shared_ptr< const Channel > > getChannels() const override
Encapsulates a face creation request and all its parameters.
static std::vector< shared_ptr< const Channel > > getChannelsFromMap(const ChannelMap &channelMap)
boost::asio::ip::tcp::endpoint Endpoint
#define NFD_LOG_INIT(name)