30 namespace ip = boost::asio::ip;
38 static std::string id(
"websocket");
54 bool wantListen =
false;
61 for (
const auto& pair : *configSection) {
62 const std::string& key = pair.first;
64 if (key ==
"listen") {
67 else if (key ==
"port") {
68 port = ConfigFile::parseNumber<uint16_t>(pair,
"face_system.websocket");
70 else if (key ==
"enable_v4") {
73 else if (key ==
"enable_v6") {
77 NDN_THROW(ConfigFile::Error(
"Unrecognized option face_system.websocket." + key));
82 if (!enableV4 && !enableV6) {
83 NDN_THROW(ConfigFile::Error(
84 "IPv4 and IPv6 WebSocket channels have been disabled. Remove face_system.websocket section "
85 "to disable WebSocket channels or enable at least one channel type."));
93 if (!m_channels.empty()) {
94 NFD_LOG_WARN(
"Cannot disable WebSocket channels after initialization");
102 if (!v4Channel->isListening()) {
103 v4Channel->listen(this->
addFace);
110 if (!v6Channel->isListening()) {
111 v6Channel->listen(this->
addFace);
116 shared_ptr<WebSocketChannel>
119 auto it = m_channels.find(endpoint);
120 if (it != m_channels.end())
123 auto channel = make_shared<WebSocketChannel>(endpoint);
124 m_channels[endpoint] = channel;
128 std::vector<shared_ptr<const Channel>>
129 WebSocketFactory::doGetChannels()
const
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".
Context for processing a config section in ProtocolFactory.
static std::vector< shared_ptr< const Channel > > getChannelsFromMap(const ChannelMap &channelMap)
FaceCreatedCallback addFace
callback when a new face is created
Protocol factory for WebSocket.
static const std::string & getId() noexcept
shared_ptr< WebSocketChannel > createChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket-based channel using websocket::Endpoint.
#define NFD_LOG_INIT(name)
boost::asio::ip::tcp::endpoint Endpoint
boost::optional< const ConfigSection & > OptionalConfigSection
An optional configuration file section.
#define NFD_REGISTER_PROTOCOL_FACTORY(PF)
Registers a protocol factory.