36 namespace ip = boost::asio::ip;
39 : m_localEndpoint(localEndpoint)
42 , m_wantCongestionMarking(wantCongestionMarking)
58 m_acceptor.open(m_localEndpoint.protocol());
59 m_acceptor.set_option(ip::tcp::acceptor::reuse_address(
true));
60 if (m_localEndpoint.address().is_v6()) {
61 m_acceptor.set_option(ip::v6_only(
true));
63 m_acceptor.bind(m_localEndpoint);
64 m_acceptor.listen(backlog);
66 accept(onFaceCreated, onAcceptFailed);
75 time::nanoseconds timeout)
77 auto it = m_channelFaces.find(remoteEndpoint);
78 if (it != m_channelFaces.end()) {
80 onFaceCreated(it->second);
85 auto timeoutEvent =
scheduler::schedule(timeout, bind(&TcpChannel::handleConnectTimeout,
this,
86 remoteEndpoint, clientSocket, onConnectFailed));
89 clientSocket->async_connect(remoteEndpoint,
90 bind(&TcpChannel::handleConnect,
this,
91 boost::asio::placeholders::error, remoteEndpoint, clientSocket,
92 params, timeoutEvent, onFaceCreated, onConnectFailed));
96 TcpChannel::createFace(ip::tcp::socket&& socket,
100 shared_ptr<Face>
face;
103 auto it = m_channelFaces.find(remoteEndpoint);
104 if (it == m_channelFaces.end()) {
124 auto linkService = make_unique<GenericLinkService>(options);
125 auto transport = make_unique<TcpTransport>(std::move(socket), params.
persistency);
126 face = make_shared<Face>(std::move(linkService), std::move(transport));
128 m_channelFaces[remoteEndpoint] =
face;
136 boost::system::error_code error;
137 socket.shutdown(ip::tcp::socket::shutdown_both, error);
150 m_acceptor.async_accept(m_socket, bind(&TcpChannel::handleAccept,
this,
151 boost::asio::placeholders::error,
152 onFaceCreated, onAcceptFailed));
156 TcpChannel::handleAccept(
const boost::system::error_code& error,
161 if (error != boost::asio::error::operation_aborted) {
164 onAcceptFailed(500,
"Accept failed: " + error.message());
173 createFace(std::move(m_socket), params, onFaceCreated);
176 accept(onFaceCreated, onAcceptFailed);
180 TcpChannel::handleConnect(
const boost::system::error_code& error,
182 const shared_ptr<ip::tcp::socket>& socket,
183 const FaceParams& params,
190 #if (BOOST_VERSION == 105400) 193 boost::system::error_code anotherErrorCode;
194 socket->remote_endpoint(anotherErrorCode);
195 if (error || anotherErrorCode) {
199 if (error != boost::asio::error::operation_aborted) {
200 NFD_LOG_CHAN_DEBUG(
"Connection to " << remoteEndpoint <<
" failed: " << error.message());
202 onConnectFailed(504,
"Connection failed: " + error.message());
208 createFace(std::move(*socket), params, onFaceCreated);
212 TcpChannel::handleConnectTimeout(
const tcp::Endpoint& remoteEndpoint,
213 const shared_ptr<ip::tcp::socket>& socket,
219 boost::system::error_code error;
220 socket->close(error);
223 onConnectFailed(504,
"Connection timed out");
TcpChannel(const tcp::Endpoint &localEndpoint, bool wantCongestionMarking)
Create TCP channel for the local endpoint.
void setUri(const FaceUri &uri)
bool isListening() const override
Returns whether the channel is listening.
bool allowLocalFields
enables encoding of IncomingFaceId, and decoding of NextHopFaceId and CachePolicy ...
function< void(const shared_ptr< Face > &face)> FaceCreatedCallback
Prototype for the callback that is invoked when a face is created (in response to an incoming connect...
void cancel(const EventId &eventId)
cancel a scheduled event
size_t defaultCongestionThreshold
default congestion threshold in bytes
LpReliability::Options reliabilityOptions
options for reliability
detail::SimulatorIo & getGlobalIoService()
void listen(const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onAcceptFailed, int backlog=boost::asio::ip::tcp::acceptor::max_connections)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
function< void(uint32_t status, const std::string &reason)> FaceCreationFailedCallback
Prototype for the callback that is invoked when a face fails to be created.
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
bool isEnabled
enables link-layer reliability
std::shared_ptr< ns3::EventId > EventId
#define NFD_LOG_CHAN_DEBUG(msg)
Log a message at DEBUG level.
Parameters used to set Transport properties or LinkService options on a newly created face...
bool allowCongestionMarking
enables send queue congestion detection and marking
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.
time::nanoseconds baseCongestionMarkingInterval
starting value for congestion marking interval
boost::asio::ip::tcp::endpoint Endpoint
#define NFD_LOG_CHAN_WARN(msg)
Log a message at WARN level.
ndn::nfd::FacePersistency persistency
ndn::optional< uint64_t > defaultCongestionThreshold
represents the underlying protocol and address used by a Face
Options that control the behavior of GenericLinkService.
ndn::optional< time::nanoseconds > baseCongestionMarkingInterval
void connect(const tcp::Endpoint &remoteEndpoint, const FaceParams ¶ms, const FaceCreatedCallback &onFaceCreated, const FaceCreationFailedCallback &onConnectFailed, time::nanoseconds timeout=8_s)
Create a face by establishing a TCP connection to remoteEndpoint.
boost::logic::tribool wantCongestionMarking
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event
#define NFD_LOG_INIT(name)