26 #ifndef NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP 27 #define NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP 44 template<
class Protocol,
class Addressing = Unicast>
60 receiveDatagram(
const uint8_t* buffer,
size_t nBytesReceived,
61 const boost::system::error_code& error);
71 handleSend(
const boost::system::error_code& error,
72 size_t nBytesSent,
const Block& payload);
75 handleReceive(
const boost::system::error_code& error,
76 size_t nBytesReceived);
79 processErrorCode(
const boost::system::error_code& error);
82 hasRecentlyReceived()
const;
85 resetRecentlyReceived();
88 makeEndpointId(
const typename protocol::endpoint& ep);
97 std::array<uint8_t, ndn::MAX_NDN_PACKET_SIZE> m_receiveBuffer;
98 bool m_hasRecentlyReceived;
102 template<
class T,
class U>
104 : m_socket(
std::move(socket))
105 , m_hasRecentlyReceived(false)
109 boost::asio::placeholders::error,
110 boost::asio::placeholders::bytes_transferred));
113 template<
class T,
class U>
122 boost::system::error_code error;
134 template<
class T,
class U>
140 m_socket.async_send(boost::asio::buffer(packet.packet),
142 boost::asio::placeholders::error,
143 boost::asio::placeholders::bytes_transferred,
147 template<
class T,
class U>
150 const boost::system::error_code& error)
159 std::tie(isOk, element) = Block::fromBuffer(buffer, nBytesReceived);
165 if (element.size() != nBytesReceived) {
166 NFD_LOG_FACE_WARN(
"Received datagram size and decoded element size don't match");
170 m_hasRecentlyReceived =
true;
177 template<
class T,
class U>
180 size_t nBytesReceived)
187 boost::asio::placeholders::error,
188 boost::asio::placeholders::bytes_transferred));
191 template<
class T,
class U>
194 size_t nBytesSent,
const Block& payload)
203 template<
class T,
class U>
212 error == boost::asio::error::operation_aborted) {
227 template<
class T,
class U>
231 return m_hasRecentlyReceived;
234 template<
class T,
class U>
238 m_hasRecentlyReceived =
false;
241 template<
class T,
class U>
251 #endif // NFD_DAEMON_FACE_DATAGRAM_TRANSPORT_HPP void receiveDatagram(const uint8_t *buffer, size_t nBytesReceived, const boost::system::error_code &error)
Receive datagram, translate buffer into packet, deliver to parent class.
void doClose() override
performs Transport specific operations to close the transport
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
void resetRecentlyReceived()
protocol::socket m_socket
#define NFD_LOG_FACE_DEBUG(msg)
Log a message at DEBUG level.
#define NFD_LOG_INCLASS_DECLARE()
bool hasRecentlyReceived() const
void receive(Packet &&packet)
receive a link-layer packet
stores a packet along with the remote endpoint
the transport is being closed due to a failure
#define NFD_LOG_FACE_WARN(msg)
Log a message at WARN level.
void handleSend(const boost::system::error_code &error, size_t nBytesSent, const Block &payload)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
the transport is closed, and can be safely deallocated
static EndpointId makeEndpointId(const typename protocol::endpoint &ep)
uint64_t EndpointId
identifies an endpoint on the link
the transport is being closed gracefully, either by the peer or by a call to close() ...
ndn::nfd::FacePersistency getPersistency() const
Implements Transport for datagram-based protocols.
TransportState getState() const
EndpointId remoteEndpoint
identifies the remote endpoint
void setState(TransportState newState)
set transport state
void doSend(Transport::Packet &&packet) override
performs Transport specific operations to send a packet
void handleReceive(const boost::system::error_code &error, size_t nBytesReceived)
#define NFD_LOG_FACE_ERROR(msg)
Log a message at ERROR level.
protocol::endpoint m_sender
DatagramTransport(typename protocol::socket &&socket)
Construct datagram transport.
void processErrorCode(const boost::system::error_code &error)
boost::asio::io_service & getGlobalIoService()