37 namespace ip = boost::asio::ip;
41 bool wantCongestionMarking,
43 : m_localEndpoint(localEndpoint)
45 , m_idleFaceTimeout(idleTimeout)
46 , m_wantCongestionMarking(wantCongestionMarking)
59 shared_ptr<Face> face;
61 face = createFace(remoteEndpoint, params).second;
63 catch (
const boost::system::system_error& e) {
66 onConnectFailed(504,
"Face creation failed: "s + e.what());
84 m_socket.open(m_localEndpoint.protocol());
85 m_socket.set_option(ip::udp::socket::reuse_address(
true));
86 if (m_localEndpoint.address().is_v6()) {
87 m_socket.set_option(ip::v6_only(
true));
89 m_socket.bind(m_localEndpoint);
91 waitForNewPeer(onFaceCreated, onFaceCreationFailed);
99 m_socket.async_receive_from(boost::asio::buffer(m_receiveBuffer), m_remoteEndpoint,
100 [=] (
auto&&... args) {
101 this->handleNewPeer(std::forward<decltype(args)>(args)..., onFaceCreated, onReceiveFailed);
106 UdpChannel::handleNewPeer(
const boost::system::error_code& error,
107 size_t nBytesReceived,
115 onReceiveFailed(500,
"Receive failed: " + error.message());
122 bool isCreated =
false;
123 shared_ptr<Face> face;
128 std::tie(isCreated, face) = createFace(m_remoteEndpoint, params);
130 catch (
const boost::system::system_error& e) {
131 NFD_LOG_CHAN_DEBUG(
"Face creation for " << m_remoteEndpoint <<
" failed: " << e.what());
133 onReceiveFailed(504,
"Face creation failed: "s + e.what());
144 transport->
receiveDatagram(ndn::make_span(m_receiveBuffer).first(nBytesReceived), error);
146 waitForNewPeer(onFaceCreated, onReceiveFailed);
149 std::pair<bool, shared_ptr<Face>>
153 auto it = m_channelFaces.find(remoteEndpoint);
154 if (it != m_channelFaces.end()) {
157 return {
false, it->second};
162 socket.set_option(ip::udp::socket::reuse_address(
true));
163 socket.bind(m_localEndpoint);
164 socket.connect(remoteEndpoint);
166 GenericLinkService::Options options;
167 options.allowFragmentation =
true;
168 options.allowReassembly =
true;
173 options.allowCongestionMarking = m_wantCongestionMarking;
188 auto linkService = make_unique<GenericLinkService>(options);
192 face->setChannel(shared_from_this());
194 m_channelFaces[remoteEndpoint] = face;
optional< uint64_t > defaultCongestionThreshold
bool isListening() const final
Returns whether the channel is listening.
void connect(const udp::Endpoint &remoteEndpoint, const FaceParams ¶ms, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed)
Create a unicast UDP face toward remoteEndpoint.
void setUri(const FaceUri &uri)
#define NFD_LOG_INIT(name)
boost::logic::tribool wantCongestionMarking
ndn::nfd::FacePersistency persistency
detail::SimulatorIo & getGlobalIoService()
Returns the global io_service instance for the calling thread.
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.
size_t getDefaultMtu() const
Returns the default MTU for all faces created by this channel.
A Transport that communicates on a unicast UDP socket.
void connectFaceClosedSignal(Face &face, std::function< void()> f)
Invokes a callback when a face is closed.
UdpChannel(const udp::Endpoint &localEndpoint, time::nanoseconds idleTimeout, bool wantCongestionMarking, size_t defaultMtu)
Create a UDP channel on the given localEndpoint.
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
optional< time::nanoseconds > baseCongestionMarkingInterval
Copyright (c) 2011-2015 Regents of the University of California.
#define NFD_LOG_CHAN_INFO(msg)
Log a message at INFO level.
#define NFD_LOG_CHAN_TRACE(msg)
Log a message at TRACE level.
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
represents the underlying protocol and address used by a Face
boost::asio::ip::udp::endpoint Endpoint
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onFaceCreationFailed)
Start listening.
void setDefaultMtu(size_t mtu)
void receiveDatagram(span< const uint8_t > buffer, const boost::system::error_code &error)
Receive datagram, translate buffer into packet, deliver to parent class.
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...
Catch-all error for socket component errors that don't fit in other categories.
boost::chrono::nanoseconds nanoseconds
Parameters used to set Transport properties or LinkService options on a newly created face...
Class implementing UDP-based channel to create faces.