32 namespace ip = boost::asio::ip;
40 static std::string id(
"websocket");
57 bool wantListen =
false;
64 for (
const auto& pair : *configSection) {
65 const std::string& key = pair.first;
67 if (key ==
"listen") {
70 else if (key ==
"port") {
71 port = ConfigFile::parseNumber<uint16_t>(pair,
"face_system.websocket");
73 else if (key ==
"enable_v4") {
76 else if (key ==
"enable_v6") {
80 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"Unrecognized option face_system.websocket." + key));
85 if (!enableV4 && !enableV6) {
87 "IPv4 and IPv6 WebSocket channels have been disabled. Remove face_system.websocket section "
88 "to disable WebSocket channels or enable at least one channel type."));
91 if (!enableV4 && enableV6) {
93 BOOST_THROW_EXCEPTION(
ConfigFile::Error(
"NFD does not allow pure IPv6 WebSocket channel."));
98 if (!m_channels.empty()) {
99 NFD_LOG_WARN(
"Cannot close WebSocket channel after initialization");
104 BOOST_ASSERT(enableV4);
108 if (!channel->isListening()) {
109 channel->listen(context.
addFace);
110 if (m_channels.size() > 1) {
111 NFD_LOG_WARN(
"Adding WebSocket channel for new endpoint; cannot close existing channels");
119 ndn::nfd::FacePersistency persistency,
120 bool wantLocalFieldsEnabled,
124 onFailure(406,
"Unsupported protocol");
127 shared_ptr<WebSocketChannel>
130 auto channel = findChannel(endpoint);
134 channel = make_shared<WebSocketChannel>(endpoint);
135 m_channels[endpoint] = channel;
140 shared_ptr<WebSocketChannel>
144 boost::lexical_cast<uint16_t>(localPort));
148 std::vector<shared_ptr<const Channel>>
154 shared_ptr<WebSocketChannel>
157 auto i = m_channels.find(endpoint);
158 if (i != m_channels.end())
FaceCreatedCallback addFace
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"
std::vector< shared_ptr< const Channel > > getChannels() const override
#define NFD_REGISTER_PROTOCOL_FACTORY(PF)
registers a protocol factory
#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 the face fails to be created.
#define NFD_LOG_INIT(name)
void createFace(const FaceUri &uri, ndn::nfd::FacePersistency persistency, bool wantLocalFieldsEnabled, const FaceCreatedCallback &onCreated, const FaceCreationFailedCallback &onFailure) override
unicast face creation is not supported and will always fail
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
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()