nfd::face::TcpTransport Class Referencefinal

A Transport that communicates on a connected TCP socket. More...

#include <daemon/face/tcp-transport.hpp>

+ Inheritance diagram for nfd::face::TcpTransport:
+ Collaboration diagram for nfd::face::TcpTransport:

Public Types

using Counters = TransportCounters
 Counters provided by a transport. More...
 
typedef boost::asio::ip::tcp protocol
 

Public Member Functions

 TcpTransport (protocol::socket &&socket, ndn::nfd::FacePersistency persistency, ndn::nfd::FaceScope faceScope)
 
bool canChangePersistencyTo (ndn::nfd::FacePersistency newPersistency) const
 check whether the face persistency can be changed to newPersistency More...
 
void close ()
 Request the transport to be closed. More...
 
virtual const CountersgetCounters () const
 
time::steady_clock::TimePoint getExpirationTime () const
 
const FacegetFace () const
 
const LinkServicegetLinkService () const
 
LinkServicegetLinkService ()
 
ndn::nfd::LinkType getLinkType () const
 
FaceUri getLocalUri () const
 
ssize_t getMtu () const
 
ndn::nfd::FacePersistency getPersistency () const
 
FaceUri getRemoteUri () const
 
ndn::nfd::FaceScope getScope () const
 
ssize_t getSendQueueCapacity () const
 
ssize_t getSendQueueLength () final
 
TransportState getState () const
 
void send (const Block &packet, const EndpointId &endpoint=0)
 Send a link-layer packet. More...
 
void setFaceAndLinkService (Face &face, LinkService &service)
 set Face and LinkService for Transport More...
 
void setPersistency (ndn::nfd::FacePersistency newPersistency)
 changes face persistency setting More...
 

Public Attributes

signal::Signal< Transport, TransportState, TransportStateafterStateChange
 signals when transport state changes More...
 

Static Public Attributes

static constexpr ssize_t MIN_MTU = 64
 minimum MTU that may be set on a transport More...
 

Protected Member Functions

void afterChangePersistency (ndn::nfd::FacePersistency oldPersistency) final
 invoked after the persistency has been changed More...
 
bool canChangePersistencyToImpl (ndn::nfd::FacePersistency newPersistency) const final
 invoked by canChangePersistencyTo to perform the check More...
 
void deferredClose ()
 
void doClose () final
 performs Transport specific operations to close the transport More...
 
void doSend (const Block &packet, const EndpointId &endpoint) override
 performs Transport specific operations to send a packet More...
 
size_t getSendQueueBytes () const
 
void handleError (const boost::system::error_code &error) final
 
void handleReceive (const boost::system::error_code &error, size_t nBytesReceived)
 
void handleSend (const boost::system::error_code &error, size_t nBytesSent)
 
void processErrorCode (const boost::system::error_code &error)
 
void receive (const Block &packet, const EndpointId &endpoint=0)
 Pass a received link-layer packet to the upper layer for further processing. More...
 
void resetReceiveBuffer ()
 
void resetSendQueue ()
 
void sendFromQueue ()
 
void setExpirationTime (const time::steady_clock::TimePoint &expirationTime)
 
void setLinkType (ndn::nfd::LinkType linkType)
 
void setLocalUri (const FaceUri &uri)
 
void setMtu (ssize_t mtu)
 
void setRemoteUri (const FaceUri &uri)
 
void setScope (ndn::nfd::FaceScope scope)
 
void setSendQueueCapacity (ssize_t sendQueueCapacity)
 
void setState (TransportState newState)
 set transport state More...
 
void startReceive ()
 

Protected Attributes

protocol::socket m_socket
 
ByteCounter nInBytes
 total incoming bytes More...
 
PacketCounter nInPackets
 count of incoming packets More...
 
ByteCounter nOutBytes
 total outgoing bytes More...
 
PacketCounter nOutPackets
 count of outgoing packets More...
 

Detailed Description

A Transport that communicates on a connected TCP socket.

When persistency is set to permanent, whenever the TCP connection is severed, the transport state is set to DOWN, and the connection is retried periodically with exponential backoff until it is reestablished

Definition at line 43 of file tcp-transport.hpp.

Member Typedef Documentation

Counters provided by a transport.

See also
TransportCounters

Definition at line 114 of file transport.hpp.

typedef boost::asio::ip::tcp nfd::face::StreamTransport< boost::asio::ip::tcp >::protocol
inherited

Definition at line 46 of file stream-transport.hpp.

Constructor & Destructor Documentation

nfd::face::TcpTransport::TcpTransport ( protocol::socket &&  socket,
ndn::nfd::FacePersistency  persistency,
ndn::nfd::FaceScope  faceScope 
)

Definition at line 43 of file tcp-transport.cpp.

Member Function Documentation

void nfd::face::TcpTransport::afterChangePersistency ( ndn::nfd::FacePersistency  oldPersistency)
finalprotectedvirtual

invoked after the persistency has been changed

The base class implementation does nothing. When overridden in a subclass, the function should update internal states after persistency setting has been changed.

Reimplemented from nfd::face::Transport.

Definition at line 89 of file tcp-transport.cpp.

bool nfd::face::Transport::canChangePersistencyTo ( ndn::nfd::FacePersistency  newPersistency) const
inherited

check whether the face persistency can be changed to newPersistency

This function serves as the external API, and invokes the protected function canChangePersistencyToImpl to perform further checks if newPersistency differs from the current persistency.

Returns
true if the change can be performed, false otherwise

Definition at line 128 of file transport.cpp.

bool nfd::face::TcpTransport::canChangePersistencyToImpl ( ndn::nfd::FacePersistency  newPersistency) const
finalprotectedvirtual

invoked by canChangePersistencyTo to perform the check

Base class implementation returns false.

Parameters
newPersistencythe new persistency, guaranteed to be different from current persistency

Reimplemented from nfd::face::Transport.

Definition at line 83 of file tcp-transport.cpp.

void nfd::face::Transport::close ( )
inherited

Request the transport to be closed.

This operation is effective only if transport is in UP or DOWN state, otherwise it has no effect. The transport changes state to CLOSING, and performs cleanup procedure. The state will be changed to CLOSED when cleanup is complete, which may happen synchronously or asynchronously.

Definition at line 81 of file transport.cpp.

void nfd::face::StreamTransport< boost::asio::ip::tcp >::deferredClose ( )
protectedinherited
void nfd::face::TcpTransport::doClose ( )
finalprotectedvirtual

performs Transport specific operations to close the transport

This is invoked once by close() after changing state to CLOSING. It will not be invoked by Transport class if the transport is already CLOSING or CLOSED.

When the cleanup procedure is complete, this method should change state to CLOSED. This transition can happen synchronously or asynchronously.

Implements nfd::face::Transport.

Definition at line 193 of file tcp-transport.cpp.

void nfd::face::StreamTransport< boost::asio::ip::tcp >::doSend ( const Block &  packet,
const EndpointId endpoint 
)
overrideprotectedvirtualinherited

performs Transport specific operations to send a packet

Parameters
packetthe packet to be sent, can be assumed to be valid and well-formed
endpointthe destination endpoint
Precondition
transport state is either UP or DOWN

Implements nfd::face::Transport.

const Transport::Counters & nfd::face::Transport::getCounters ( ) const
inlinevirtualinherited

Reimplemented in nfd::face::WebSocketTransport.

Definition at line 382 of file transport.hpp.

time::steady_clock::TimePoint nfd::face::Transport::getExpirationTime ( ) const
inlineinherited
Returns
expiration time of the transport
Return values
time::steady_clock::TimePoint::max()the transport has indefinite lifetime

Definition at line 473 of file transport.hpp.

const Face * nfd::face::Transport::getFace ( ) const
inlineinherited
Returns
Face to which this Transport is attached

Definition at line 364 of file transport.hpp.

const LinkService * nfd::face::Transport::getLinkService ( ) const
inlineinherited
Returns
LinkService to which this Transport is attached

Definition at line 370 of file transport.hpp.

LinkService * nfd::face::Transport::getLinkService ( )
inlineinherited
Returns
LinkService to which this Transport is attached

Definition at line 376 of file transport.hpp.

ndn::nfd::LinkType nfd::face::Transport::getLinkType ( ) const
inlineinherited
Returns
the link type of the transport

Definition at line 430 of file transport.hpp.

FaceUri nfd::face::Transport::getLocalUri ( ) const
inlineinherited
Returns
a FaceUri representing local endpoint

Definition at line 388 of file transport.hpp.

ssize_t nfd::face::Transport::getMtu ( ) const
inlineinherited
Returns
maximum payload size
Return values
MTU_UNLIMITEDtransport has no limit on payload size

This size is the maximum packet size that can be sent or received through this transport.

For a datagram-based transport, this is typically the Maximum Transmission Unit (MTU), after the overhead of headers introduced by the transport has been accounted for. For a stream-based transport, this is typically unlimited (MTU_UNLIMITED).

Definition at line 442 of file transport.hpp.

ndn::nfd::FacePersistency nfd::face::Transport::getPersistency ( ) const
inlineinherited
Returns
face persistency setting

Definition at line 424 of file transport.hpp.

FaceUri nfd::face::Transport::getRemoteUri ( ) const
inlineinherited
Returns
a FaceUri representing remote endpoint

Definition at line 400 of file transport.hpp.

ndn::nfd::FaceScope nfd::face::Transport::getScope ( ) const
inlineinherited
Returns
whether face is local or non-local for scope control purpose

Definition at line 412 of file transport.hpp.

size_t nfd::face::StreamTransport< boost::asio::ip::tcp >::getSendQueueBytes ( ) const
protectedinherited
ssize_t nfd::face::Transport::getSendQueueCapacity ( ) const
inlineinherited
Returns
capacity of the send queue (in bytes)
Return values
QUEUE_UNSUPPORTEDtransport does not support queue capacity retrieval
QUEUE_ERRORtransport was unable to retrieve the queue capacity

Definition at line 455 of file transport.hpp.

ssize_t nfd::face::TcpTransport::getSendQueueLength ( )
finalvirtual
Returns
current send queue length of the transport (in octets)
Return values
QUEUE_UNSUPPORTEDtransport does not support queue length retrieval
QUEUE_ERRORtransport was unable to retrieve the queue length

Reimplemented from nfd::face::Transport.

Definition at line 61 of file tcp-transport.cpp.

TransportState nfd::face::Transport::getState ( ) const
inlineinherited
Returns
transport state

Definition at line 467 of file transport.hpp.

void nfd::face::TcpTransport::handleError ( const boost::system::error_code &  error)
finalprotectedvirtual

Reimplemented from nfd::face::StreamTransport< boost::asio::ip::tcp >.

Definition at line 102 of file tcp-transport.cpp.

void nfd::face::StreamTransport< boost::asio::ip::tcp >::handleReceive ( const boost::system::error_code &  error,
size_t  nBytesReceived 
)
protectedinherited
void nfd::face::StreamTransport< boost::asio::ip::tcp >::handleSend ( const boost::system::error_code &  error,
size_t  nBytesSent 
)
protectedinherited
void nfd::face::StreamTransport< boost::asio::ip::tcp >::processErrorCode ( const boost::system::error_code &  error)
protectedinherited
void nfd::face::Transport::receive ( const Block &  packet,
const EndpointId endpoint = 0 
)
protectedinherited

Pass a received link-layer packet to the upper layer for further processing.

Parameters
packetthe received packet, must be a valid and well-formed TLV block
endpointthe source endpoint
Warning
Behavior is undefined if packet size exceeds the MTU limit

Definition at line 115 of file transport.cpp.

void nfd::face::StreamTransport< boost::asio::ip::tcp >::resetReceiveBuffer ( )
protectedinherited
void nfd::face::StreamTransport< boost::asio::ip::tcp >::resetSendQueue ( )
protectedinherited
void nfd::face::Transport::send ( const Block &  packet,
const EndpointId endpoint = 0 
)
inherited

Send a link-layer packet.

Parameters
packetthe packet to be sent, must be a valid and well-formed TLV block
endpointthe destination endpoint
Note
This operation has no effect if getState() is neither UP nor DOWN
Warning
Behavior is undefined if packet size exceeds the MTU limit

Definition at line 94 of file transport.cpp.

void nfd::face::StreamTransport< boost::asio::ip::tcp >::sendFromQueue ( )
protectedinherited
void nfd::face::Transport::setExpirationTime ( const time::steady_clock::TimePoint &  expirationTime)
inlineprotectedinherited

Definition at line 479 of file transport.hpp.

void nfd::face::Transport::setFaceAndLinkService ( Face face,
LinkService service 
)
inherited

set Face and LinkService for Transport

Precondition
setFaceAndLinkService has not been called

Definition at line 71 of file transport.cpp.

void nfd::face::Transport::setLinkType ( ndn::nfd::LinkType  linkType)
inlineprotectedinherited

Definition at line 436 of file transport.hpp.

void nfd::face::Transport::setLocalUri ( const FaceUri &  uri)
inlineprotectedinherited

Definition at line 394 of file transport.hpp.

void nfd::face::Transport::setMtu ( ssize_t  mtu)
inlineprotectedinherited

Definition at line 448 of file transport.hpp.

void nfd::face::Transport::setPersistency ( ndn::nfd::FacePersistency  newPersistency)
inherited

changes face persistency setting

Definition at line 150 of file transport.cpp.

void nfd::face::Transport::setRemoteUri ( const FaceUri &  uri)
inlineprotectedinherited

Definition at line 406 of file transport.hpp.

void nfd::face::Transport::setScope ( ndn::nfd::FaceScope  scope)
inlineprotectedinherited

Definition at line 418 of file transport.hpp.

void nfd::face::Transport::setSendQueueCapacity ( ssize_t  sendQueueCapacity)
inlineprotectedinherited

Definition at line 461 of file transport.hpp.

void nfd::face::Transport::setState ( TransportState  newState)
protectedinherited

set transport state

Only the following transitions are valid: UP->DOWN, DOWN->UP, UP/DOWN->CLOSING/FAILED, CLOSING/FAILED->CLOSED

Exceptions
std::runtime_errortransition is invalid.

Definition at line 173 of file transport.cpp.

void nfd::face::StreamTransport< boost::asio::ip::tcp >::startReceive ( )
protectedinherited

Member Data Documentation

signal::Signal<Transport, TransportState, TransportState> nfd::face::Transport::afterStateChange
inherited

signals when transport state changes

Definition at line 244 of file transport.hpp.

protocol::socket nfd::face::StreamTransport< boost::asio::ip::tcp >::m_socket
protectedinherited

Definition at line 98 of file stream-transport.hpp.

const ssize_t nfd::face::Transport::MIN_MTU = 64
staticinherited

minimum MTU that may be set on a transport

This is done to ensure the NDNLPv2 fragmentation feature functions properly.

Definition at line 347 of file transport.hpp.

ByteCounter nfd::face::TransportCounters::nInBytes
inherited

total incoming bytes

This counter includes headers imposed by NFD (such as NDNLP), but excludes overhead of underlying protocol (such as IP header). For a datagram-based transport, an incoming packet that cannot be parsed as TLV would not be counted.

Definition at line 78 of file transport.hpp.

PacketCounter nfd::face::TransportCounters::nInPackets
inherited

count of incoming packets

A 'packet' typically means a top-level TLV block. For a datagram-based transport, an incoming packet that cannot be parsed as TLV would not be counted.

Definition at line 62 of file transport.hpp.

ByteCounter nfd::face::TransportCounters::nOutBytes
inherited

total outgoing bytes

This counter includes headers imposed by NFD (such as NDNLP), but excludes overhead of underlying protocol (such as IP header). This counter is increased only if transport is UP.

Definition at line 86 of file transport.hpp.

PacketCounter nfd::face::TransportCounters::nOutPackets
inherited

count of outgoing packets

A 'packet' typically means a top-level TLV block. This counter is incremented only if transport is UP.

Definition at line 69 of file transport.hpp.