30 #include <boost/asio/io_service.hpp>
72 encoder.appendByteArray(header.
wire(), header.
size());
73 encoder.appendByteArray(payload.
wire(), payload.
size());
75 this->
send(encoder.block());
78 boost::asio::io_service&
90 std::vector<DummyClientFace*>
faces;
94 :
Error(
"Face has already been linked to another face")
103 this->construct(options);
108 , m_keyChain(keyChain)
110 this->construct(options);
115 , m_internalKeyChain(make_unique<
KeyChain>())
116 , m_keyChain(*m_internalKeyChain)
118 this->construct(options);
123 , m_keyChain(keyChain)
125 this->construct(options);
134 DummyClientFace::construct(
const Options& options)
136 static_pointer_cast<Transport>(getTransport())->onSendBlock.connect([
this] (
const Block& blockFromDaemon) {
137 Block packet(blockFromDaemon);
141 Buffer::const_iterator begin, end;
143 Block block(&*begin, std::distance(begin, end));
146 shared_ptr<Interest> interest = make_shared<Interest>(block);
148 shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(
std::move(*interest));
150 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*nack, lpPacket);
154 addTagFromField<lp::NextHopFaceIdTag, lp::NextHopFaceIdField>(*interest, lpPacket);
155 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*interest, lpPacket);
160 shared_ptr<Data> data = make_shared<Data>(block);
161 addTagFromField<lp::CachePolicyTag, lp::CachePolicyField>(*data, lpPacket);
162 addTagFromField<lp::CongestionMarkTag, lp::CongestionMarkField>(*data, lpPacket);
167 if (options.enablePacketLogging)
168 this->enablePacketLogging();
170 if (options.enableRegistrationReply)
171 this->enableRegistrationReply();
175 enableBroadcastLink();
179 DummyClientFace::enableBroadcastLink()
184 if (otherFace != this) {
185 otherFace->receive(interest);
190 this->onSendData.connect([
this] (
const Data& data) {
191 if (m_bcastLink !=
nullptr) {
192 for (
auto otherFace : m_bcastLink->faces) {
193 if (otherFace != this) {
194 otherFace->receive(data);
199 this->onSendNack.connect([
this] (
const lp::Nack& nack) {
200 if (m_bcastLink !=
nullptr) {
201 for (
auto otherFace : m_bcastLink->faces) {
202 if (otherFace != this) {
203 otherFace->receive(nack);
211 DummyClientFace::enablePacketLogging()
213 onSendInterest.connect([
this] (
const Interest& interest) {
214 this->sentInterests.push_back(interest);
216 onSendData.connect([
this] (
const Data& data) {
217 this->sentData.push_back(data);
219 onSendNack.connect([
this] (
const lp::Nack& nack) {
220 this->sentNacks.push_back(nack);
225 DummyClientFace::enableRegistrationReply()
227 onSendInterest.connect([
this] (
const Interest& interest) {
228 static const Name localhostRegistration(
"/localhost/nfd/rib");
229 if (!localhostRegistration.isPrefixOf(interest.getName()))
241 resp.
setBody(params.wireEncode());
243 shared_ptr<Data> data = make_shared<Data>(interest.getName());
246 m_keyChain.sign(*data, security::SigningInfo(security::SigningInfo::SIGNER_TYPE_SHA256));
248 this->getIoService().post([
this, data] { this->receive(*data); });
257 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, interest);
258 addFieldFromTag<lp::NextHopFaceIdField, lp::NextHopFaceIdTag>(lpPacket, interest);
259 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, interest);
261 static_pointer_cast<Transport>(getTransport())->receive(lpPacket.
wireEncode());
265 DummyClientFace::receive(
const Data& data)
269 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, data);
270 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, data);
272 static_pointer_cast<Transport>(getTransport())->receive(lpPacket.
wireEncode());
283 addFieldFromTag<lp::IncomingFaceIdField, lp::IncomingFaceIdTag>(lpPacket, nack);
284 addFieldFromTag<lp::CongestionMarkField, lp::CongestionMarkTag>(lpPacket, nack);
286 static_pointer_cast<Transport>(getTransport())->receive(lpPacket.
wireEncode());
292 if (m_bcastLink !=
nullptr && other.
m_bcastLink !=
nullptr) {
298 else if (m_bcastLink ==
nullptr && other.
m_bcastLink !=
nullptr) {
300 m_bcastLink->faces.push_back(
this);
302 else if (m_bcastLink !=
nullptr && other.
m_bcastLink ==
nullptr) {
304 m_bcastLink->faces.push_back(&other);
307 m_bcastLink = other.
m_bcastLink = make_shared<BroadcastLink>();
308 m_bcastLink->faces.push_back(
this);
309 m_bcastLink->faces.push_back(&other);
314 DummyClientFace::unlink()
316 if (m_bcastLink ==
nullptr) {
320 auto it = std::find(m_bcastLink->faces.begin(), m_bcastLink->faces.end(),
this);
321 BOOST_ASSERT(it != m_bcastLink->faces.end());
322 m_bcastLink->faces.erase(it);
324 if (m_bcastLink->faces.size() == 1) {
325 m_bcastLink->faces[0]->m_bcastLink =
nullptr;
326 m_bcastLink->faces.clear();
328 m_bcastLink =
nullptr;
332 DummyClientFace::doProcessEvents(time::milliseconds timeout,
bool keepThread)
334 if (m_processEventsOverride !=
nullptr) {
335 m_processEventsOverride(timeout);
338 this->Face::doProcessEvents(timeout, keepThread);