udp-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_UDP_CHANNEL_HPP
27 #define NFD_DAEMON_FACE_UDP_CHANNEL_HPP
28 
29 #include "channel.hpp"
30 #include "udp-protocol.hpp"
31 
32 namespace nfd {
33 
37 class UdpChannel : public Channel
38 {
39 public:
50  UdpChannel(const udp::Endpoint& localEndpoint,
51  const time::seconds& timeout);
52 
56  size_t
57  size() const;
58 
64  void
65  connect(const udp::Endpoint& remoteEndpoint,
66  ndn::nfd::FacePersistency persistency,
67  const FaceCreatedCallback& onFaceCreated,
68  const FaceCreationFailedCallback& onConnectFailed);
69 
82  void
83  listen(const FaceCreatedCallback& onFaceCreated,
84  const FaceCreationFailedCallback& onReceiveFailed);
85 
86  bool
87  isListening() const;
88 
89 private:
90  void
91  waitForNewPeer(const FaceCreatedCallback& onFaceCreated,
92  const FaceCreationFailedCallback& onReceiveFailed);
93 
98  void
99  handleNewPeer(const boost::system::error_code& error,
100  size_t nBytesReceived,
101  const FaceCreatedCallback& onFaceCreated,
102  const FaceCreationFailedCallback& onReceiveFailed);
103 
104  std::pair<bool, shared_ptr<Face>>
105  createFace(const udp::Endpoint& remoteEndpoint, ndn::nfd::FacePersistency persistency);
106 
107 private:
108  std::map<udp::Endpoint, shared_ptr<Face>> m_channelFaces;
109 
110  udp::Endpoint m_localEndpoint;
111 
115  udp::Endpoint m_remoteEndpoint;
116 
120  boost::asio::ip::udp::socket m_socket;
121 
125  time::seconds m_idleFaceTimeout;
126 
127  uint8_t m_inputBuffer[ndn::MAX_NDN_PACKET_SIZE];
128 };
129 
130 inline bool
132 {
133  return m_socket.is_open();
134 }
135 
136 } // namespace nfd
137 
138 #endif // NFD_DAEMON_FACE_UDP_CHANNEL_HPP
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onReceiveFailed)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
Definition: udp-channel.cpp:75
void connect(const udp::Endpoint &remoteEndpoint, ndn::nfd::FacePersistency persistency, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a face by establishing connection to remote endpoint.
Definition: udp-channel.cpp:53
UdpChannel(const udp::Endpoint &localEndpoint, const time::seconds &timeout)
Create UDP channel for the local endpoint.
Definition: udp-channel.cpp:37
represent a channel that communicates on a local endpoint
Definition: channel.hpp:52
size_t size() const
Get number of faces in the channel.
Definition: udp-channel.cpp:47
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
bool isListening() const
boost::asio::ip::udp::endpoint Endpoint
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
Class implementing UDP-based channel to create faces.
Definition: udp-channel.hpp:37