internal-transport.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "internal-transport.hpp"
27 #include "core/global-io.hpp"
28 
29 namespace nfd {
30 namespace face {
31 
32 NFD_LOG_INCLASS_DEFINE(InternalForwarderTransport, "InternalForwarderTransport");
33 
35  const FaceUri& localUri, const FaceUri& remoteUri,
36  ndn::nfd::FaceScope scope, ndn::nfd::LinkType linkType)
37 {
38  this->setLocalUri(localUri);
39  this->setRemoteUri(remoteUri);
40  this->setScope(scope);
41  this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
42  this->setLinkType(linkType);
43  this->setMtu(MTU_UNLIMITED);
44 
45  NFD_LOG_FACE_INFO("Creating transport");
46 }
47 
48 void
50 {
51  NFD_LOG_FACE_TRACE(__func__);
52 
53  Packet p;
54  p.packet = packet;
55  this->receive(std::move(p));
56 }
57 
58 void
59 InternalForwarderTransport::doSend(Packet&& packet)
60 {
61  NFD_LOG_FACE_TRACE(__func__);
62 
63  this->emitSignal(afterSend, packet.packet);
64 }
65 
66 void
68 {
69  NFD_LOG_FACE_TRACE(__func__);
70 
72 }
73 
74 NFD_LOG_INCLASS_DEFINE(InternalClientTransport, "InternalClientTransport");
75 
76 static void
77 asyncReceive(InternalTransportBase* recipient, const Block& packet)
78 {
79  getGlobalIoService().post([packet, recipient] {
80  recipient->receiveFromLink(packet);
81  });
82 }
83 
84 void
86 {
87  NFD_LOG_DEBUG(__func__ << " " << forwarderTransport);
88 
89  m_fwToClientTransmitConn.disconnect();
90  m_clientToFwTransmitConn.disconnect();
91  m_fwTransportStateConn.disconnect();
92 
93  if (forwarderTransport != nullptr) {
94  m_fwToClientTransmitConn = forwarderTransport->afterSend.connect(bind(&asyncReceive, this, _1));
95  m_clientToFwTransmitConn = this->afterSend.connect(bind(&asyncReceive, forwarderTransport, _1));
96  m_fwTransportStateConn = forwarderTransport->afterStateChange.connect(
97  [this] (TransportState oldState, TransportState newState) {
98  if (newState == TransportState::CLOSED) {
99  this->connectToForwarder(nullptr);
100  }
101  });
102  }
103 }
104 
105 void
107 {
108  if (m_receiveCallback) {
109  m_receiveCallback(packet);
110  }
111 }
112 
113 void
115 {
116  this->emitSignal(afterSend, wire);
117 }
118 
119 void
120 InternalClientTransport::send(const Block& header, const Block& payload)
121 {
122  ndn::EncodingBuffer encoder(header.size() + payload.size(), header.size() + payload.size());
123  encoder.appendByteArray(header.wire(), header.size());
124  encoder.appendByteArray(payload.wire(), payload.size());
125 
126  this->send(encoder.block());
127 }
128 
129 } // namespace face
130 } // namespace nfd
void setLocalUri(const FaceUri &uri)
Definition: transport.hpp:384
static void asyncReceive(InternalTransportBase *recipient, const Block &packet)
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:161
#define NFD_LOG_FACE_TRACE(msg)
Log a message at TRACE level.
Definition: face-log.hpp:79
implements a forwarder-side transport that can be paired with another
void setScope(ndn::nfd::FaceScope scope)
Definition: transport.hpp:408
const ssize_t MTU_UNLIMITED
indicates the transport has no limit on payload size
Definition: transport.hpp:95
TransportState
indicates the state of a transport
Definition: transport.hpp:41
void setMtu(ssize_t mtu)
Definition: transport.hpp:438
Block packet
the packet as a TLV block
Definition: transport.hpp:124
signal::Signal< Transport, TransportState, TransportState > afterStateChange
signals when transport state changes
Definition: transport.hpp:265
virtual void receiveFromLink(const Block &packet)=0
causes the transport to receive a link-layer packet
void receive(Packet &&packet)
receive a link-layer packet
Definition: transport.cpp:117
stores a packet along with the remote endpoint
Definition: transport.hpp:113
InternalForwarderTransport(const FaceUri &localUri=FaceUri("internal://"), const FaceUri &remoteUri=FaceUri("internal://"), ndn::nfd::FaceScope scope=ndn::nfd::FACE_SCOPE_LOCAL, ndn::nfd::LinkType linkType=ndn::nfd::LINK_TYPE_POINT_TO_POINT)
#define NFD_LOG_INCLASS_DEFINE(cls, name)
Definition: logger.hpp:128
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
the transport is closed, and can be safely deallocated
#define NFD_LOG_FACE_INFO(msg)
Log a message at INFO level.
Definition: face-log.hpp:85
void connectToForwarder(InternalForwarderTransport *forwarderTransport)
connect to a forwarder-side transport
void setLinkType(ndn::nfd::LinkType linkType)
Definition: transport.hpp:426
void send(Packet &&packet)
send a link-layer packet
Definition: transport.cpp:97
void setPersistency(ndn::nfd::FacePersistency newPersistency)
changes face persistency setting
Definition: transport.cpp:151
void doClose() override
performs Transport specific operations to close the transport
void send(const Block &wire) override
void receiveFromLink(const Block &packet) override
causes the transport to receive a link-layer packet
void setState(TransportState newState)
set transport state
Definition: transport.cpp:174
void setRemoteUri(const FaceUri &uri)
Definition: transport.hpp:396
signal::Signal< InternalTransportBase, Block > afterSend
abstracts a transport that can be paired with another
implements a client-side transport that can be paired with another
void receiveFromLink(const Block &packet) override
causes the transport to receive a link-layer packet
boost::asio::io_service & getGlobalIoService()
Definition: global-io.cpp:41