示例#1
0
void
DummyClientFace::construct(const Options& options)
{
  static_pointer_cast<Transport>(getTransport())->onSendBlock.connect([this] (const Block& blockFromDaemon) {
    Block packet(blockFromDaemon);
    packet.encode();
    lp::Packet lpPacket(packet);

    Buffer::const_iterator begin, end;
    std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
    Block block(&*begin, std::distance(begin, end));

    if (block.type() == tlv::Interest) {
      shared_ptr<Interest> interest = make_shared<Interest>(block);
      if (lpPacket.has<lp::NackField>()) {
        shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
        nack->setHeader(lpPacket.get<lp::NackField>());
        if (lpPacket.has<lp::NextHopFaceIdField>()) {
          nack->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
        }
        if (lpPacket.has<lp::CongestionMarkField>()) {
          nack->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
        }
        onSendNack(*nack);
      }
      else {
        if (lpPacket.has<lp::NextHopFaceIdField>()) {
          interest->setTag(make_shared<lp::NextHopFaceIdTag>(lpPacket.get<lp::NextHopFaceIdField>()));
        }
        if (lpPacket.has<lp::CongestionMarkField>()) {
          interest->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
        }
        onSendInterest(*interest);
      }
    }
    else if (block.type() == tlv::Data) {
      shared_ptr<Data> data = make_shared<Data>(block);

      if (lpPacket.has<lp::CachePolicyField>()) {
        data->setTag(make_shared<lp::CachePolicyTag>(lpPacket.get<lp::CachePolicyField>()));
      }
      if (lpPacket.has<lp::CongestionMarkField>()) {
        data->setTag(make_shared<lp::CongestionMarkTag>(lpPacket.get<lp::CongestionMarkField>()));
      }

      onSendData(*data);
    }
  });

  if (options.enablePacketLogging)
    this->enablePacketLogging();

  if (options.enableRegistrationReply)
    this->enableRegistrationReply();

  m_processEventsOverride = options.processEventsOverride;
}
示例#2
0
void NetworkClient::initialize(NetworkObject *object, QTcpSocket *client)
{
    client->setParent(this);
    this->client = client;
    ptrNetworkdObject = object;

    this->ip = client->peerAddress().toString();
    connect(this->client, SIGNAL(readyRead()), this, SLOT(onReceivedData()));
    connect(this->client, SIGNAL(bytesWritten(qint64)), this, SLOT(onSendData(qint64)));
    connect(this->client, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
}
void
DummyClientFace::construct(const Options& options)
{
  m_transport->onSendBlock.connect([this] (const Block& blockFromDaemon) {
    try {
      Block packet(blockFromDaemon);
      packet.encode();
      lp::Packet lpPacket(packet);

      Buffer::const_iterator begin, end;
      std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
      Block block(&*begin, std::distance(begin, end));

      if (block.type() == tlv::Interest) {
        shared_ptr<Interest> interest = make_shared<Interest>(block);
        if (lpPacket.has<lp::NackField>()) {
          shared_ptr<lp::Nack> nack = make_shared<lp::Nack>(std::move(*interest));
          nack->setHeader(lpPacket.get<lp::NackField>());
          if (lpPacket.has<lp::NextHopFaceIdField>()) {
            nack->getLocalControlHeader().setNextHopFaceId(lpPacket.get<lp::NextHopFaceIdField>());
          }
          onSendNack(*nack);
        }
        else {
          if (lpPacket.has<lp::NextHopFaceIdField>()) {
            interest->getLocalControlHeader().
              setNextHopFaceId(lpPacket.get<lp::NextHopFaceIdField>());
          }
          onSendInterest(*interest);
        }
      }
      else if (block.type() == tlv::Data) {
        shared_ptr<Data> data = make_shared<Data>(block);

        if (lpPacket.has<lp::CachePolicyField>()) {
          if (lpPacket.get<lp::CachePolicyField>().getPolicy() == lp::CachePolicyType::NO_CACHE) {
            data->getLocalControlHeader().setCachingPolicy(nfd::LocalControlHeader::CachingPolicy::NO_CACHE);
          }
        }

        onSendData(*data);
      }
    }
    catch (tlv::Error& e) {
      throw tlv::Error("Error decoding NDNLPv2 packet");
    }
  });

  if (options.enablePacketLogging)
    this->enablePacketLogging();

  if (options.enableRegistrationReply)
    this->enableRegistrationReply();
}
示例#4
0
void Day::tableDataCreated(int row, int col, QString value)
{
    emit onSendData(row, col, value);
}