38 : m_localEndpoint(localEndpoint)
39 , m_pingInterval(10_s)
45 m_server.clear_access_channels(websocketpp::log::alevel::all);
46 m_server.clear_error_channels(websocketpp::log::elevel::all);
50 m_server.set_tcp_pre_bind_handler([isV6 = m_localEndpoint.address().is_v6()] (
const auto& acceptor) {
52 acceptor->set_option(boost::asio::ip::v6_only(true));
54 return websocketpp::lib::error_code{};
56 m_server.set_open_handler(bind(&WebSocketChannel::handleOpen,
this, _1));
57 m_server.set_close_handler(bind(&WebSocketChannel::handleClose,
this, _1));
58 m_server.set_message_handler(bind(&WebSocketChannel::handleMessage,
this, _1, _2));
61 m_server.set_pong_handler(bind(&WebSocketChannel::handlePong,
this, _1));
62 m_server.set_pong_timeout_handler(bind(&WebSocketChannel::handlePongTimeout,
this, _1));
65 m_server.set_reuse_addr(
true);
69 WebSocketChannel::setPingInterval(time::milliseconds interval)
71 BOOST_ASSERT(!m_server.is_listening());
73 m_pingInterval = interval;
77 WebSocketChannel::setPongTimeout(time::milliseconds timeout)
79 BOOST_ASSERT(!m_server.is_listening());
81 m_server.set_pong_timeout(
static_cast<long>(timeout.count()));
85 WebSocketChannel::handlePongTimeout(websocketpp::connection_hdl hdl)
87 auto it = m_channelFaces.find(hdl);
88 if (it != m_channelFaces.end()) {
97 WebSocketChannel::handlePong(websocketpp::connection_hdl hdl)
99 auto it = m_channelFaces.find(hdl);
100 if (it != m_channelFaces.end()) {
109 WebSocketChannel::handleMessage(websocketpp::connection_hdl hdl,
110 websocket::Server::message_ptr msg)
112 auto it = m_channelFaces.find(hdl);
113 if (it != m_channelFaces.end()) {
114 static_cast<WebSocketTransport*
>(it->second->getTransport())->receiveMessage(msg->get_payload());
122 WebSocketChannel::handleOpen(websocketpp::connection_hdl hdl)
124 NFD_LOG_CHAN_TRACE(
"Incoming connection from " << m_server.get_con_from_hdl(hdl)->get_remote_endpoint());
126 auto linkService = make_unique<GenericLinkService>();
127 auto transport = make_unique<WebSocketTransport>(hdl, m_server, m_pingInterval);
130 BOOST_ASSERT(m_channelFaces.count(hdl) == 0);
131 m_channelFaces[hdl] = face;
134 m_onFaceCreatedCallback(face);
138 WebSocketChannel::handleClose(websocketpp::connection_hdl hdl)
140 auto it = m_channelFaces.find(hdl);
141 if (it != m_channelFaces.end()) {
157 m_onFaceCreatedCallback = onFaceCreated;
159 m_server.listen(m_localEndpoint);
160 m_server.start_accept();