NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
websocket-channel.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "websocketpp.hpp"
31 
32 namespace nfd {
33 
34 namespace websocket {
35 typedef boost::asio::ip::tcp::endpoint Endpoint;
36 } // namespace websocket
37 
38 namespace face {
39 
43 class WebSocketChannel : public Channel
44 {
45 public:
53  explicit
54  WebSocketChannel(const websocket::Endpoint& localEndpoint);
55 
56  bool
57  isListening() const override
58  {
59  return m_server.is_listening();
60  }
61 
62  size_t
63  size() const override
64  {
65  return m_channelFaces.size();
66  }
67 
74  void
75  listen(const FaceCreatedCallback& onFaceCreated);
76 
80  void
81  setPingInterval(time::milliseconds interval);
82 
85  void
86  setPongTimeout(time::milliseconds timeout);
87 
88  void
89  handlePong(websocketpp::connection_hdl hdl);
90 
91  void
92  handlePongTimeout(websocketpp::connection_hdl hdl);
93 
94 private:
95  void
96  handleMessage(websocketpp::connection_hdl hdl,
97  websocket::Server::message_ptr msg);
98 
99  void
100  handleOpen(websocketpp::connection_hdl hdl);
101 
102  void
103  handleClose(websocketpp::connection_hdl hdl);
104 
105 private:
106  const websocket::Endpoint m_localEndpoint;
107  websocket::Server m_server;
108  std::map<websocketpp::connection_hdl, shared_ptr<Face>,
109  std::owner_less<websocketpp::connection_hdl>> m_channelFaces;
110  FaceCreatedCallback m_onFaceCreatedCallback;
111  time::milliseconds m_pingInterval;
112 };
113 
114 } // namespace face
115 } // namespace nfd
116 
117 #endif // NFD_DAEMON_FACE_WEBSOCKET_CHANNEL_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
void listen(const FaceCreatedCallback &onFaceCreated)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
represent a channel that communicates on a local endpoint
Definition: channel.hpp:52
Class implementing WebSocket-based channel to create faces.
websocketpp::server< websocketpp::config::asio > Server
Definition: websocketpp.hpp:46
std::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...
Definition: channel.hpp:40
WebSocketChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket channel for the local endpoint.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
bool isListening() const override
Returns whether the channel is listening.
boost::asio::ip::tcp::endpoint Endpoint
size_t size() const override
Returns the number of faces in the channel.