Пример #1
0
void
Manifest::encode()
{
    EncodingEstimator estimator;
    size_t estimatedSize = wireEncode(estimator);

    EncodingBuffer buffer(estimatedSize, 0);
    wireEncode(buffer);

    setContentType(tlv::ContentType_Manifest);
    setContent(const_cast<uint8_t*>(buffer.buf()), buffer.size());
}
Пример #2
0
const Block
Response::wireEncode() const
{
  if (m_contentType == NDNS_BLOB || m_contentType == NDNS_KEY) {
    return m_appContent;
  }

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);
  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);
  return buffer.block();
}
Пример #3
0
  Block
  wireEncode() const
  {
    Block block;

    EncodingEstimator estimator;
    size_t estimatedSize = wireEncode(estimator);

    EncodingBuffer buffer(estimatedSize);
    wireEncode(buffer);

    return buffer.block();
  }
Пример #4
0
const Block&
ChatroomInfo::wireEncode() const
{
  ndn::EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  ndn::EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_wire = buffer.block();
  m_wire.parse();

  return m_wire;
}
 const Block& NdnTagVerificationRequest::wireEncode() const
  {
      if( m_wire.hasWire() )
          return m_wire;
      
      EncodingEstimator estimator;
      size_t size = wireEncode( estimator );
      
      EncodingBuffer buffer( size, 0 );
      wireEncode( buffer );
      
      m_wire = buffer.block(true);
      
      return m_wire;
  };
Пример #6
0
const Block&
KeyLocator::wireEncode() const
{
  if (m_wire.hasWire())
    return m_wire;

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_wire = buffer.block();
  return m_wire;
}
  const Block&
  wireEncode()
  {
    if (m_block.hasWire())
      return m_block;
  
    EncodingEstimator estimator;
    size_t estimatedSize = wireEncode(estimator);

    EncodingBuffer buffer(estimatedSize, 0);
    wireEncode(buffer);

    m_block = buffer.block();
    return m_block;
  }
Пример #8
0
const Block&
Data::wireEncode() const
{
  if (m_wire.hasWire())
    return m_wire;

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  const_cast<Data*>(this)->wireDecode(buffer.block());
  return m_wire;
}
Пример #9
0
const Block&
Component::wireEncode() const
{
  if (this->hasWire())
    return *this;

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  const_cast<Component&>(*this) = buffer.block();
  return *this;
}
const Block&
NextHopRecord::wireEncode() const
{
  if (m_wire.hasWire()) {
    return m_wire;
  }

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_wire = buffer.block();
  return m_wire;
}
Пример #11
0
const Block&
Name::wireEncode() const
{
  if (m_nameBlock.hasWire())
    return m_nameBlock;

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_nameBlock = buffer.block();
  m_nameBlock.parse();

  return m_nameBlock;
}
Пример #12
0
const ndn::Block&
CoordinateLsa::wireEncode() const
{
  if (m_wire.hasWire()) {
    return m_wire;
  }

  ndn::EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  ndn::EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_wire = buffer.block();

  return m_wire;
}
Пример #13
0
const Block&
Interest::wireEncode() const
{
  if (m_wire.hasWire())
    return m_wire;

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  // to ensure that Nonce block points to the right memory location
  const_cast<Interest*>(this)->wireDecode(buffer.block());

  return m_wire;
}
Пример #14
0
const Block&
AdditionalDescription::wireEncode() const
{
    if (m_wire.hasWire())
        return m_wire;

    EncodingEstimator estimator;
    size_t estimatedSize = wireEncode(estimator);

    EncodingBuffer buffer(estimatedSize, 0);
    wireEncode(buffer);

    m_wire = buffer.block();
    m_wire.parse();

    return m_wire;
}
Пример #15
0
uint32_t
PacketHeader<Pkt>::Deserialize(ns3::Buffer::Iterator start)
{
  auto packet = make_shared<Pkt>();
  io::stream<Ns3BufferIteratorSource> is(start);
  packet->wireDecode(::ndn::Block::fromStream(is));
  m_packet = packet;
  return packet->wireEncode().size();
}
Пример #16
0
bool
Exclude::operator==(const Exclude& other) const
{
  if (empty() && other.empty())
    return true;
  if (empty() || other.empty())
    return false;

  return wireEncode() == other.wireEncode();
}
Пример #17
0
 static shared_ptr<Data>
 makeData(const Name& name)
 {
   auto data = make_shared<Data>(name);
   ndn::SignatureSha256WithRsa fakeSignature;
   fakeSignature.setValue(ndn::encoding::makeEmptyBlock(tlv::SignatureValue));
   data->setSignature(fakeSignature);
   data->wireEncode();
   return data;
 }
    shared_ptr<ndn::Data>
    NdnDataManager::makeNack( const Data& data )
    {
        auto nack = make_shared<Data>( data.getName() );
        nack->setContentType( tlv::ContentType_Nack );
        nack->setContent( data.wireEncode() );
        nack->setAccessLevel( 0 );

        m_signer.sign( *nack );
        nack->wireEncode();
        return nack;
    }
Пример #19
0
const Block&
CachePolicy::wireEncode() const
{
  if (m_policy == CachePolicyType::NONE) {
    BOOST_THROW_EXCEPTION(Error("CachePolicyType must be set"));
  }

  if (m_wire.hasWire()) {
    return m_wire;
  }

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_wire = buffer.block();

  return m_wire;
}
size_t
FibEntry::wireEncode(EncodingImpl<TAG>& block) const
{
  size_t totalLength = 0;

  for (auto i = m_nextHopRecords.rbegin(); i != m_nextHopRecords.rend(); ++i) {
    totalLength += i->wireEncode(block);
  }

  totalLength += m_prefix.wireEncode(block);
  totalLength += block.prependVarNumber(totalLength);
  totalLength += block.prependVarNumber(tlv::nfd::FibEntry);

  return totalLength;
}
Пример #21
0
Block
Packet::wireEncode() const
{
  if (m_wire.hasWire()) {
    return m_wire;
  }

  // If no header or trailer, return bare network packet
  Block::element_container elements = m_wire.elements();
  if (elements.size() == 1 && elements.front().type() == FragmentField::TlvType::value) {
    elements.front().parse();
    elements.front().elements().front().parse();
    return elements.front().elements().front();
  }

  EncodingEstimator estimator;
  size_t estimatedSize = wireEncode(estimator);

  EncodingBuffer buffer(estimatedSize, 0);
  wireEncode(buffer);

  m_wire = buffer.block();
  return m_wire;
}
Пример #22
0
BOOST_FIXTURE_TEST_CASE(StatusDataset, DispatcherFixture)
{
    static Block smallBlock("\x81\x01\0x01", 3);
    static Block largeBlock = [] () -> Block {
        EncodingBuffer encoder;
        for (size_t i = 0; i < 2500; ++i) {
            encoder.prependByte(1);
        }
        encoder.prependVarNumber(2500);
        encoder.prependVarNumber(129);
        return encoder.block();
    }();

    dispatcher.addStatusDataset("test/small",
                                makeTestAuthorization(),
                                [] (const Name& prefix, const Interest& interest,
    StatusDatasetContext& context) {
        context.append(smallBlock);
        context.append(smallBlock);
        context.append(smallBlock);
        context.end();
    });

    dispatcher.addStatusDataset("test/large",
                                makeTestAuthorization(),
                                [] (const Name& prefix, const Interest& interest,
    StatusDatasetContext& context) {
        context.append(largeBlock);
        context.append(largeBlock);
        context.append(largeBlock);
        context.end();
    });

    dispatcher.addStatusDataset("test/reject",
                                makeTestAuthorization(),
                                [] (const Name& prefix, const Interest& interest,
    StatusDatasetContext& context) {
        context.reject();
    });

    dispatcher.addTopPrefix("/root");
    advanceClocks(time::milliseconds(1));
    face.sentData.clear();

    face.receive(*util::makeInterest("/root/test/small/%80%00")); // returns 403
    face.receive(*util::makeInterest("/root/test/small/%80%00/invalid")); // returns 403
    face.receive(*util::makeInterest("/root/test/small/%80%00/silent")); // silently ignored
    advanceClocks(time::milliseconds(1), 20);
    BOOST_CHECK_EQUAL(face.sentData.size(), 2);

    BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Blob);
    BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 403);
    BOOST_CHECK(face.sentData[1].getContentType() == tlv::ContentType_Blob);
    BOOST_CHECK_EQUAL(ControlResponse(face.sentData[1].getContent().blockFromValue()).getCode(), 403);

    face.sentData.clear();

    auto interestSmall = *util::makeInterest("/root/test/small/valid");
    face.receive(interestSmall);
    advanceClocks(time::milliseconds(1), 10);

    // one data packet is generated and sent to both places
    BOOST_CHECK_EQUAL(face.sentData.size(), 1);
    BOOST_CHECK_EQUAL(storage.size(), 1);

    auto fetchedData = storage.find(interestSmall);
    BOOST_REQUIRE(fetchedData != nullptr);
    BOOST_CHECK(face.sentData[0].wireEncode() == fetchedData->wireEncode());

    face.receive(*util::makeInterest(Name("/root/test/small/valid").appendVersion(10))); // should be ignored
    face.receive(*util::makeInterest(Name("/root/test/small/valid").appendSegment(20))); // should be ignored
    advanceClocks(time::milliseconds(1), 10);
    BOOST_CHECK_EQUAL(face.sentData.size(), 1);
    BOOST_CHECK_EQUAL(storage.size(), 1);

    Block content = face.sentData[0].getContent();
    BOOST_CHECK_NO_THROW(content.parse());

    BOOST_CHECK_EQUAL(content.elements().size(), 3);
    BOOST_CHECK(content.elements()[0] == smallBlock);
    BOOST_CHECK(content.elements()[1] == smallBlock);
    BOOST_CHECK(content.elements()[2] == smallBlock);

    storage.erase("/", true); // clear the storage
    face.sentData.clear();
    face.receive(*util::makeInterest("/root/test/large/valid"));
    advanceClocks(time::milliseconds(1), 10);

    // two data packets are generated, the first one will be sent to both places
    // while the second one will only be inserted into the in-memory storage
    BOOST_CHECK_EQUAL(face.sentData.size(), 1);
    BOOST_CHECK_EQUAL(storage.size(), 2);

    // segment0 should be sent through the face
    const auto& component = face.sentData[0].getName().at(-1);
    BOOST_CHECK(component.isSegment());
    BOOST_CHECK_EQUAL(component.toSegment(), 0);

    std::vector<Data> dataInStorage;
    std::copy(storage.begin(), storage.end(), std::back_inserter(dataInStorage));

    // the Data sent through the face should be the same as the first Data in the storage
    BOOST_CHECK_EQUAL(face.sentData[0].getName(), dataInStorage[0].getName());
    BOOST_CHECK(face.sentData[0].getContent() == dataInStorage[0].getContent());

    content = [&dataInStorage] () -> Block {
        EncodingBuffer encoder;
        size_t valueLength = encoder.prependByteArray(dataInStorage[1].getContent().value(),
        dataInStorage[1].getContent().value_size());
        valueLength += encoder.prependByteArray(dataInStorage[0].getContent().value(),
        dataInStorage[0].getContent().value_size());
        encoder.prependVarNumber(valueLength);
        encoder.prependVarNumber(tlv::Content);
        return encoder.block();
    }();

    BOOST_CHECK_NO_THROW(content.parse());
    BOOST_CHECK_EQUAL(content.elements().size(), 3);
    BOOST_CHECK(content.elements()[0] == largeBlock);
    BOOST_CHECK(content.elements()[1] == largeBlock);
    BOOST_CHECK(content.elements()[2] == largeBlock);

    storage.erase("/", true);// clear the storage
    face.sentData.clear();
    face.receive(*util::makeInterest("/root/test/reject/%80%00/valid")); // returns nack
    advanceClocks(time::milliseconds(1));
    BOOST_CHECK_EQUAL(face.sentData.size(), 1);
    BOOST_CHECK(face.sentData[0].getContentType() == tlv::ContentType_Nack);
    BOOST_CHECK_EQUAL(ControlResponse(face.sentData[0].getContent().blockFromValue()).getCode(), 400);
    BOOST_CHECK_EQUAL(storage.size(), 0); // the nack packet will not be inserted into the in-memory storage
}
Пример #23
0
bool
KeyLocator::operator==(const KeyLocator& other) const
{
  return wireEncode() == other.wireEncode();
}