NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
tcp-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_TCP_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_TCP_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "core/scheduler.hpp"
31 
32 namespace nfd {
33 
34 namespace tcp {
35 typedef boost::asio::ip::tcp::endpoint Endpoint;
36 } // namespace tcp
37 
45 class TcpChannel : public Channel
46 {
47 public:
54  explicit
55  TcpChannel(const tcp::Endpoint& localEndpoint);
56 
66  void
67  listen(const FaceCreatedCallback& onFaceCreated,
68  const FaceCreationFailedCallback& onAcceptFailed,
69  int backlog = boost::asio::ip::tcp::acceptor::max_connections);
70 
74  void
75  connect(const tcp::Endpoint& remoteEndpoint,
76  bool wantLocalFieldsEnabled,
77  const FaceCreatedCallback& onFaceCreated,
78  const FaceCreationFailedCallback& onConnectFailed,
79  const time::seconds& timeout = time::seconds(4));
80 
84  size_t
85  size() const;
86 
87  bool
88  isListening() const;
89 
90 private:
91  void
92  createFace(boost::asio::ip::tcp::socket&& socket,
93  bool isOnDemand,
94  bool wantLocalFieldsEnabled,
95  const FaceCreatedCallback& onFaceCreated);
96 
97  void
98  accept(const FaceCreatedCallback& onFaceCreated,
99  const FaceCreationFailedCallback& onAcceptFailed);
100 
101  void
102  handleAccept(const boost::system::error_code& error,
103  const FaceCreatedCallback& onFaceCreated,
104  const FaceCreationFailedCallback& onAcceptFailed);
105 
106  void
107  handleConnect(const boost::system::error_code& error,
108  const shared_ptr<boost::asio::ip::tcp::socket>& socket,
109  bool wantLocalFieldsEnabled,
110  const scheduler::EventId& connectTimeoutEvent,
111  const FaceCreatedCallback& onFaceCreated,
112  const FaceCreationFailedCallback& onConnectFailed);
113 
114  void
115  handleConnectTimeout(const shared_ptr<boost::asio::ip::tcp::socket>& socket,
116  const FaceCreationFailedCallback& onConnectFailed);
117 
118 private:
119  std::map<tcp::Endpoint, shared_ptr<Face>> m_channelFaces;
120 
121  tcp::Endpoint m_localEndpoint;
122  boost::asio::ip::tcp::acceptor m_acceptor;
123  boost::asio::ip::tcp::socket m_acceptSocket;
124 };
125 
126 inline bool
128 {
129  return m_acceptor.is_open();
130 }
131 
132 } // namespace nfd
133 
134 #endif // NFD_DAEMON_FACE_TCP_CHANNEL_HPP
Class implementing TCP-based channel to create faces.
Definition: tcp-channel.hpp:45
std::shared_ptr< ns3::EventId > EventId
Definition: scheduler.hpp:39
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp-channel.hpp:35
TcpChannel
Definition: tcp-channel.cpp:33
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when the face fails to be created.
Definition: channel.hpp:44
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...
Definition: channel.hpp:38
bool isListening() const