NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 ConnectFailedCallback& onAcceptFailed,
69  int backlog = boost::asio::ip::tcp::acceptor::max_connections);
70 
74  void
75  connect(const tcp::Endpoint& remoteEndpoint,
76  const FaceCreatedCallback& onFaceCreated,
77  const ConnectFailedCallback& onConnectFailed,
78  const time::seconds& timeout = time::seconds(4));
79 
83  size_t
84  size() const;
85 
86  bool
87  isListening() const;
88 
89 private:
90  void
91  createFace(boost::asio::ip::tcp::socket socket,
92  const FaceCreatedCallback& onFaceCreated,
93  bool isOnDemand);
94 
95  void
96  accept(const FaceCreatedCallback& onFaceCreated,
97  const ConnectFailedCallback& onConnectFailed);
98 
99  void
100  handleAccept(const boost::system::error_code& error,
101  const FaceCreatedCallback& onFaceCreated,
102  const ConnectFailedCallback& onConnectFailed);
103 
104  void
105  handleConnect(const boost::system::error_code& error,
106  const shared_ptr<boost::asio::ip::tcp::socket>& socket,
107  const scheduler::EventId& connectTimeoutEvent,
108  const FaceCreatedCallback& onFaceCreated,
109  const ConnectFailedCallback& onConnectFailed);
110 
111  void
112  handleConnectTimeout(const shared_ptr<boost::asio::ip::tcp::socket>& socket,
113  const ConnectFailedCallback& onConnectFailed);
114 
115 private:
116  std::map<tcp::Endpoint, shared_ptr<Face>> m_channelFaces;
117 
118  tcp::Endpoint m_localEndpoint;
119  boost::asio::ip::tcp::acceptor m_acceptor;
120  boost::asio::ip::tcp::socket m_acceptSocket;
121 };
122 
123 inline bool
125 {
126  return m_acceptor.is_open();
127 }
128 
129 } // namespace nfd
130 
131 #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:38
boost::asio::ip::tcp::endpoint Endpoint
Definition: tcp-channel.hpp:35
bool isListening() const
TcpChannel
Definition: tcp-channel.cpp:32
function< void(const std::string &reason)> ConnectFailedCallback
Prototype for the callback that is called when face is failed to get created.
Definition: channel.hpp:46
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback called when face is created (as a response to incoming connection or after...
Definition: channel.hpp:41