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)
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;
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());
140 auto* transport =
static_cast<UnicastUdpTransport*
>(face->getTransport());
141 transport->receiveDatagram(m_receiveBuffer.data(), nBytesReceived, error);
143 waitForNewPeer(onFaceCreated, onReceiveFailed);
146 std::pair<bool, shared_ptr<Face>>
148 const FaceParams& params)
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);
163 GenericLinkService::Options options;
164 options.allowFragmentation =
true;
165 options.allowReassembly =
true;
166 options.reliabilityOptions.isEnabled = params.wantLpReliability;
168 if (boost::logic::indeterminate(params.wantCongestionMarking)) {
170 options.allowCongestionMarking = m_wantCongestionMarking;
173 options.allowCongestionMarking = bool(params.wantCongestionMarking);
176 if (params.baseCongestionMarkingInterval) {
177 options.baseCongestionMarkingInterval = *params.baseCongestionMarkingInterval;
179 if (params.defaultCongestionThreshold) {
180 options.defaultCongestionThreshold = *params.defaultCongestionThreshold;
183 auto linkService = make_unique<GenericLinkService>(options);
184 auto transport = make_unique<UnicastUdpTransport>(
std::move(socket), params.persistency,
185 m_idleFaceTimeout, params.mtu);
188 m_channelFaces[remoteEndpoint] = face;