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...
 
using protocol = boost::asio::ip::tcp
 

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 persistency can be changed to newPersistency. More...
 
void close ()
 Request the transport to be closed. More...
 
virtual const CountersgetCounters () const
 
time::steady_clock::time_point getExpirationTime () const noexcept
 Returns the expiration time of the transport. More...
 
const FacegetFace () const noexcept
 Returns the Face to which this transport is attached. More...
 
const LinkServicegetLinkService () const noexcept
 Returns the LinkService to which this transport is attached. More...
 
LinkServicegetLinkService () noexcept
 Returns the LinkService to which this transport is attached. More...
 
ndn::nfd::LinkType getLinkType () const noexcept
 Returns the link type of the transport. More...
 
FaceUri getLocalUri () const noexcept
 Returns a FaceUri representing the local endpoint. More...
 
ssize_t getMtu () const noexcept
 Returns the maximum payload size. More...
 
ndn::nfd::FacePersistency getPersistency () const noexcept
 Returns the current persistency setting of the transport. More...
 
FaceUri getRemoteUri () const noexcept
 Returns a FaceUri representing the remote endpoint. More...
 
ndn::nfd::FaceScope getScope () const noexcept
 Returns whether the transport is local or non-local for scope control purposes. More...
 
ssize_t getSendQueueCapacity () const noexcept
 Returns the capacity of the send queue (in bytes). More...
 
ssize_t getSendQueueLength () final
 Returns the current send queue length of the transport (in octets). More...
 
TransportState getState () const noexcept
 Returns the current transport state. More...
 
void send (const Block &packet)
 Send a link-layer packet. More...
 
void setFaceAndLinkService (Face &face, LinkService &service) noexcept
 Set Face and LinkService for this transport. More...
 
void setPersistency (ndn::nfd::FacePersistency newPersistency)
 Changes the persistency setting of the transport. More...
 

Public Attributes

signal::Signal< Transport, TransportState, TransportStateafterStateChange
 Signals when the transport state changes. 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) 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={})
 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::time_point &expirationTime) noexcept
 
void setLinkType (ndn::nfd::LinkType linkType) noexcept
 
void setLocalUri (const FaceUri &uri) noexcept
 
void setMtu (ssize_t mtu) noexcept
 
void setRemoteUri (const FaceUri &uri) noexcept
 
void setScope (ndn::nfd::FaceScope scope) noexcept
 
void setSendQueueCapacity (ssize_t sendQueueCapacity) noexcept
 
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 44 of file tcp-transport.hpp.

Member Typedef Documentation

◆ Counters

Counters provided by a transport.

See also
TransportCounters

Definition at line 119 of file transport.hpp.

◆ protocol

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

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

Constructor & Destructor Documentation

◆ TcpTransport()

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

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

Member Function Documentation

◆ afterChangePersistency()

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 84 of file tcp-transport.cpp.

◆ canChangePersistencyTo()

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

Check whether the 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 130 of file transport.cpp.

◆ canChangePersistencyToImpl()

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 78 of file tcp-transport.cpp.

◆ close()

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 67 of file transport.cpp.

◆ deferredClose()

void nfd::face::StreamTransport< T >::deferredClose
protectedinherited

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

◆ doClose()

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 188 of file tcp-transport.cpp.

◆ doSend()

void nfd::face::StreamTransport< T >::doSend ( const Block &  packet)
overrideprotectedvirtualinherited

Performs Transport specific operations to send a packet.

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

Implements nfd::face::Transport.

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

◆ getCounters()

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

Reimplemented in nfd::face::WebSocketTransport.

Definition at line 170 of file transport.hpp.

◆ getExpirationTime()

time::steady_clock::time_point nfd::face::Transport::getExpirationTime ( ) const
inlinenoexceptinherited

Returns the expiration time of the transport.

Return values
time::steady_clock::time_point::max()The transport has an indefinite lifetime.

Definition at line 306 of file transport.hpp.

◆ getFace()

const Face* nfd::face::Transport::getFace ( ) const
inlinenoexceptinherited

Returns the Face to which this transport is attached.

Definition at line 146 of file transport.hpp.

◆ getLinkService() [1/2]

const LinkService* nfd::face::Transport::getLinkService ( ) const
inlinenoexceptinherited

Returns the LinkService to which this transport is attached.

Definition at line 155 of file transport.hpp.

◆ getLinkService() [2/2]

LinkService* nfd::face::Transport::getLinkService ( )
inlinenoexceptinherited

Returns the LinkService to which this transport is attached.

Definition at line 164 of file transport.hpp.

◆ getLinkType()

ndn::nfd::LinkType nfd::face::Transport::getLinkType ( ) const
inlinenoexceptinherited

Returns the link type of the transport.

Definition at line 254 of file transport.hpp.

◆ getLocalUri()

FaceUri nfd::face::Transport::getLocalUri ( ) const
inlinenoexceptinherited

Returns a FaceUri representing the local endpoint.

Definition at line 200 of file transport.hpp.

◆ getMtu()

ssize_t nfd::face::Transport::getMtu ( ) const
inlinenoexceptinherited

Returns the maximum payload size.

Return values
MTU_UNLIMITEDThe transport 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 270 of file transport.hpp.

◆ getPersistency()

ndn::nfd::FacePersistency nfd::face::Transport::getPersistency ( ) const
inlinenoexceptinherited

Returns the current persistency setting of the transport.

Definition at line 227 of file transport.hpp.

◆ getRemoteUri()

FaceUri nfd::face::Transport::getRemoteUri ( ) const
inlinenoexceptinherited

Returns a FaceUri representing the remote endpoint.

Definition at line 209 of file transport.hpp.

◆ getScope()

ndn::nfd::FaceScope nfd::face::Transport::getScope ( ) const
inlinenoexceptinherited

Returns whether the transport is local or non-local for scope control purposes.

Definition at line 218 of file transport.hpp.

◆ getSendQueueBytes()

size_t nfd::face::StreamTransport< T >::getSendQueueBytes
protectedinherited

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

◆ getSendQueueCapacity()

ssize_t nfd::face::Transport::getSendQueueCapacity ( ) const
inlinenoexceptinherited

Returns the capacity of the send queue (in bytes).

Return values
QUEUE_UNSUPPORTEDThe transport does not support queue capacity retrieval.
QUEUE_ERRORThe transport was unable to retrieve the queue capacity.

Definition at line 281 of file transport.hpp.

◆ getSendQueueLength()

ssize_t nfd::face::TcpTransport::getSendQueueLength ( )
finalvirtual

Returns the current send queue length of the transport (in octets).

Return values
QUEUE_UNSUPPORTEDThe transport does not support queue length retrieval.
QUEUE_ERRORThe transport was unable to retrieve the queue length.

Reimplemented from nfd::face::Transport.

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

◆ getState()

TransportState nfd::face::Transport::getState ( ) const
inlinenoexceptinherited

Returns the current transport state.

Definition at line 291 of file transport.hpp.

◆ handleError()

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

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

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

◆ handleReceive()

void nfd::face::StreamTransport< T >::handleReceive ( const boost::system::error_code &  error,
size_t  nBytesReceived 
)
protectedinherited

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

◆ handleSend()

void nfd::face::StreamTransport< T >::handleSend ( const boost::system::error_code &  error,
size_t  nBytesSent 
)
protectedinherited

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

◆ processErrorCode()

void nfd::face::StreamTransport< T >::processErrorCode ( const boost::system::error_code &  error)
protectedinherited

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

◆ receive()

void nfd::face::Transport::receive ( const Block &  packet,
const EndpointId endpoint = {} 
)
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, optional for unicast transports
Warning
Behavior is undefined if packet size exceeds the MTU limit.

Definition at line 101 of file transport.cpp.

◆ resetReceiveBuffer()

void nfd::face::StreamTransport< T >::resetReceiveBuffer
protectedinherited

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

◆ resetSendQueue()

void nfd::face::StreamTransport< T >::resetSendQueue
protectedinherited

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

◆ send()

void nfd::face::Transport::send ( const Block &  packet)
inherited

Send a link-layer packet.

Parameters
packetthe packet to be sent, must be a valid and well-formed TLV block
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 80 of file transport.cpp.

◆ sendFromQueue()

void nfd::face::StreamTransport< T >::sendFromQueue
protectedinherited

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

◆ setExpirationTime()

void nfd::face::Transport::setExpirationTime ( const time::steady_clock::time_point &  expirationTime)
inlineprotectednoexceptinherited

Definition at line 377 of file transport.hpp.

◆ setFaceAndLinkService()

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

Set Face and LinkService for this transport.

Precondition
setFaceAndLinkService() has not been called.

Definition at line 57 of file transport.cpp.

◆ setLinkType()

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

Definition at line 352 of file transport.hpp.

◆ setLocalUri()

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

Definition at line 334 of file transport.hpp.

◆ setMtu()

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

Definition at line 114 of file transport.cpp.

◆ setPersistency()

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

Changes the persistency setting of the transport.

Definition at line 152 of file transport.cpp.

◆ setRemoteUri()

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

Definition at line 340 of file transport.hpp.

◆ setScope()

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

Definition at line 346 of file transport.hpp.

◆ setSendQueueCapacity()

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

Definition at line 361 of file transport.hpp.

◆ setState()

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 175 of file transport.cpp.

◆ startReceive()

void nfd::face::StreamTransport< T >::startReceive
protectedinherited

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

Member Data Documentation

◆ afterStateChange

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

Signals when the transport state changes.

Definition at line 299 of file transport.hpp.

◆ m_socket

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

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

◆ nInBytes

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.

◆ nInPackets

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.

◆ nOutBytes

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.

◆ nOutPackets

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.