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; -*- */
2 /*
3  * Copyright (c) 2014-2021, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
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 final : public Channel
44 {
45 public:
53  explicit
54  WebSocketChannel(const websocket::Endpoint& localEndpoint);
55 
56  bool
57  isListening() const final
58  {
59  return m_server.is_listening();
60  }
61 
62  size_t
63  size() const final
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,
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
Represents a channel that listens on a local endpoint.
Definition: channel.hpp:41
Class implementing WebSocket-based channel to create faces.
connection_type::message_ptr message_ptr
Type of message pointers that this endpoint uses.
Definition: endpoint.hpp:70
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:39
#define NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
bool isListening() const final
Returns whether the channel is listening.
std::function< void(const shared_ptr< Face > &)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
Definition: channel.hpp:86
size_t size() const final
Returns the number of faces in the channel.
boost::asio::ip::tcp::endpoint Endpoint
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48