37 namespace ip = boost::asio::ip;
40 time::nanoseconds idleTimeout,
41 bool wantCongestionMarking)
42 : m_localEndpoint(localEndpoint)
44 , m_idleFaceTimeout(idleTimeout)
45 , m_wantCongestionMarking(wantCongestionMarking)
47 setUri(FaceUri(m_localEndpoint));
57 shared_ptr<Face> face;
59 face = createFace(remoteEndpoint, params).second;
61 catch (
const boost::system::system_error& e) {
64 onConnectFailed(504,
"Face creation failed: "s + e.what());
82 m_socket.open(m_localEndpoint.protocol());
83 m_socket.set_option(ip::udp::socket::reuse_address(
true));
84 if (m_localEndpoint.address().is_v6()) {
85 m_socket.set_option(ip::v6_only(
true));
87 m_socket.bind(m_localEndpoint);
89 waitForNewPeer(onFaceCreated, onFaceCreationFailed);
97 m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_remoteEndpoint,
98 [=] (
auto&&... args) {
99 this->handleNewPeer(std::forward<decltype(args)>(args)..., onFaceCreated, onReceiveFailed);
104 UdpChannel::handleNewPeer(
const boost::system::error_code& error,
105 size_t nBytesReceived,
110 if (error != boost::asio::error::operation_aborted) {
113 onReceiveFailed(500,
"Receive failed: " + error.message());
120 bool isCreated =
false;
121 shared_ptr<Face> face;
124 params.
persistency = ndn::nfd::FACE_PERSISTENCY_ON_DEMAND;
125 std::tie(isCreated, face) = createFace(m_remoteEndpoint, params);
127 catch (
const boost::system::system_error& e) {
128 NFD_LOG_CHAN_DEBUG(
"Face creation for " << m_remoteEndpoint <<
" failed: " << e.what());
130 onReceiveFailed(504,
"Face creation failed: "s + e.what());
141 transport->
receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
143 waitForNewPeer(onFaceCreated, onReceiveFailed);
146 std::pair<bool, shared_ptr<Face>>
150 auto it = m_channelFaces.find(remoteEndpoint);
151 if (it != m_channelFaces.end()) {
154 return {
false, it->second};
159 socket.set_option(ip::udp::socket::reuse_address(
true));
160 socket.bind(m_localEndpoint);
161 socket.connect(remoteEndpoint);
187 auto linkService = make_unique<GenericLinkService>(options);
188 auto transport = make_unique<UnicastUdpTransport>(std::move(socket), params.
persistency,
190 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
191 face->setChannel(shared_from_this());
193 m_channelFaces[remoteEndpoint] = face;
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
void receiveDatagram(const uint8_t *buffer, size_t nBytesReceived, const boost::system::error_code &error)
Receive datagram, translate buffer into packet, deliver to parent class.
bool allowFragmentation
enables fragmentation
bool isEnabled
enables link-layer reliability
boost::logic::tribool wantCongestionMarking
optional< uint64_t > defaultCongestionThreshold
A Transport that communicates on a unicast UDP socket.
std::function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
Parameters used to set Transport properties or LinkService options on a newly created face...
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a face is closed.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
optional< time::nanoseconds > baseCongestionMarkingInterval
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
ssize_t overrideMtu
overrides MTU provided by Transport
void connect(const udp::Endpoint &remoteEndpoint, const FaceParams ¶ms, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast UDP face toward remoteEndpoint.
LpReliability::Options reliabilityOptions
options for reliability
ndn::nfd::FacePersistency persistency
void setUri(const FaceUri &uri)
boost::asio::ip::udp::endpoint Endpoint
Options that control the behavior of GenericLinkService.
#define NFD_LOG_INIT(name)
UdpChannel(const udp::Endpoint &localEndpoint, time::nanoseconds idleTimeout, bool wantCongestionMarking)
Create a UDP channel on the given localEndpoint.
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...
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
time::nanoseconds baseCongestionMarkingInterval
starting value for congestion marking interval
size_t defaultCongestionThreshold
default congestion threshold in bytes
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
bool allowCongestionMarking
enables send queue congestion detection and marking
bool allowReassembly
enables reassembly
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
bool isListening() const override
Returns whether the channel is listening.
boost::asio::io_service & getGlobalIoService()
Returns the global io_service instance for the calling thread.