Exemplo n.º 1
0
void
Node::RegisterResponse::operator()(const ptr_lib::shared_ptr<const Interest>& interest, const ptr_lib::shared_ptr<Data>& responseData)
{
  // Decode responseData->getContent() and check for a success code.
  // TODO: Move this into the TLV code.
  struct ndn_TlvDecoder decoder;
  ndn_TlvDecoder_initialize
    (&decoder, responseData->getContent().buf(),
     responseData->getContent().size());
  ndn_Error error;
  size_t endOffset;
  if ((error = ndn_TlvDecoder_readNestedTlvsStart
      (&decoder, ndn_Tlv_NfdCommand_ControlResponse, &endOffset))) {
    _LOG_DEBUG
      ("Register prefix failed: Error decoding the NFD response: " <<
       ndn_getErrorString(error));
    info_->onRegisterFailed_(info_->prefix_);
    return;
  }
  uint64_t statusCode;
  if ((error = ndn_TlvDecoder_readNonNegativeIntegerTlv
       (&decoder, ndn_Tlv_NfdCommand_StatusCode, &statusCode))) {
    _LOG_DEBUG
      ("Register prefix failed: Error decoding the NFD response: " <<
       ndn_getErrorString(error));
    info_->onRegisterFailed_(info_->prefix_);
    return;
  }

  // Status code 200 is "OK".
  if (statusCode != 200) {
    _LOG_DEBUG
      ("Register prefix failed: Expected NFD status code 200, got: " <<
       statusCode);
    info_->onRegisterFailed_(info_->prefix_);
    return;
  }

  _LOG_DEBUG("Register prefix succeeded with the NFD forwarder for prefix " <<
             info_->prefix_->toUri());
}
Exemplo n.º 2
0
void
UnixTransport::connect
  (const Transport::ConnectionInfo& connectionInfo,
   ElementListener& elementListener)
{
  const UnixTransport::ConnectionInfo& unixConnectionInfo =
    dynamic_cast<const UnixTransport::ConnectionInfo&>(connectionInfo);

  ndn_Error error;
  if ((error = ndn_UnixTransport_connect
       (transport_.get(), (char *)unixConnectionInfo.getFilePath().c_str(),
        &elementListener)))
    throw runtime_error(ndn_getErrorString(error));

  isConnected_ = true;
}
Exemplo n.º 3
0
void
TcpTransport::connect
  (const Transport::ConnectionInfo& connectionInfo,
   ElementListener& elementListener)
{
  const TcpTransport::ConnectionInfo& tcpConnectionInfo =
    dynamic_cast<const TcpTransport::ConnectionInfo&>(connectionInfo);

  ndn_Error error;
  if ((error = ndn_TcpTransport_connect
       (transport_.get(), (char *)tcpConnectionInfo.getHost().c_str(),
        tcpConnectionInfo.getPort(), &elementListener)))
    throw runtime_error(ndn_getErrorString(error));

  isConnected_ = true;
}
Exemplo n.º 4
0
void
Tlv0_2WireFormat::decodeName
  (Name& name, const uint8_t *input, size_t inputLength)
{
  struct ndn_NameComponent nameComponents[100];
  NameLite nameLite
    (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));

  ndn_Error error;
  size_t dummyBeginOffset, dummyEndOffset;
  if ((error = Tlv0_2WireFormatLite::decodeName
       (nameLite, input, inputLength, &dummyBeginOffset, &dummyEndOffset)))
    throw runtime_error(ndn_getErrorString(error));

  name.set(nameLite);
}
Exemplo n.º 5
0
void
UdpTransport::connect
  (const Transport::ConnectionInfo& connectionInfo,
   ElementListener& elementListener, const OnConnected& onConnected)
{
  const UdpTransport::ConnectionInfo& udpConnectionInfo =
    dynamic_cast<const UdpTransport::ConnectionInfo&>(connectionInfo);

  ndn_Error error;
  if ((error = ndn_UdpTransport_connect
       (transport_.get(), (char *)udpConnectionInfo.getHost().c_str(),
        udpConnectionInfo.getPort(), &elementListener)))
    throw runtime_error(ndn_getErrorString(error));

  isConnected_ = true;
  onConnected();
}
Exemplo n.º 6
0
Blob
Tlv0_2WireFormat::encodeSignatureValue(const Signature& signature)
{
  struct ndn_NameComponent keyNameComponents[100];
  SignatureLite signatureLite
    (keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
  signature.get(signatureLite);

  DynamicUInt8Vector output(300);
  ndn_Error error;
  size_t encodingLength;
  if ((error = Tlv0_2WireFormatLite::encodeSignatureValue
       (signatureLite, DynamicUInt8ArrayLite::downCast(output), &encodingLength)))
    throw runtime_error(ndn_getErrorString(error));

  return output.finish(encodingLength);
}
Exemplo n.º 7
0
void
Tlv0_2WireFormat::decodeEncryptedContentV2
  (EncryptedContent& encryptedContent, const uint8_t *input,
   size_t inputLength)
{
  struct ndn_NameComponent keyNameComponents[100];
  EncryptedContentLite encryptedContentLite
    (keyNameComponents,
     sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));

  ndn_Error error;
  if ((error = Tlv0_2WireFormatLite::decodeEncryptedContentV2
       (encryptedContentLite, input, inputLength)))
    throw runtime_error(ndn_getErrorString(error));

  encryptedContent.set(encryptedContentLite);
}
Exemplo n.º 8
0
Blob
Tlv0_2WireFormat::encodeName(const Name& name)
{
  struct ndn_NameComponent nameComponents[100];
  NameLite nameLite
    (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));
  name.get(nameLite);

  DynamicUInt8Vector output(256);
  ndn_Error error;
  size_t dummyBeginOffset, dummyEndOffset, encodingLength;
  if ((error = Tlv0_2WireFormatLite::encodeName
       (nameLite, &dummyBeginOffset, &dummyEndOffset,
        DynamicUInt8ArrayLite::downCast(output), &encodingLength)))
    throw runtime_error(ndn_getErrorString(error));

  return output.finish(encodingLength);
}
Exemplo n.º 9
0
void
Tlv0_2WireFormat::decodeData
  (Data& data, const uint8_t *input, size_t inputLength, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
{
  struct ndn_NameComponent nameComponents[100];
  struct ndn_NameComponent keyNameComponents[100];
  DataLite dataLite
    (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
     keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));

  ndn_Error error;
  if ((error = Tlv0_2WireFormatLite::decodeData
       (dataLite, input, inputLength, signedPortionBeginOffset,
        signedPortionEndOffset)))
    throw runtime_error(ndn_getErrorString(error));

  data.set(dataLite);
}
Exemplo n.º 10
0
void
Tlv0_2WireFormat::decodeControlResponse
  (ControlResponse& controlResponse, const uint8_t *input,
   size_t inputLength)
{
  struct ndn_NameComponent nameComponents[100];
  struct ndn_NameComponent strategyNameComponents[100];
  ControlResponseLite controlResponseLite
    (nameComponents,
     sizeof(nameComponents) / sizeof(nameComponents[0]), strategyNameComponents,
     sizeof(strategyNameComponents) / sizeof(strategyNameComponents[0]));

  ndn_Error error;
  if ((error = Tlv0_2WireFormatLite::decodeControlResponse
       (controlResponseLite, input, inputLength)))
    throw runtime_error(ndn_getErrorString(error));

  controlResponse.set(controlResponseLite);
}
Exemplo n.º 11
0
Blob
Tlv0_2WireFormat::encodeEncryptedContentV2
  (const EncryptedContent& encryptedContent)
{
  struct ndn_NameComponent keyNameComponents[100];
  EncryptedContentLite encryptedContentLite
    (keyNameComponents,
     sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
  encryptedContent.get(encryptedContentLite);

  DynamicUInt8Vector output(256);
  ndn_Error error;
  size_t encodingLength;
  if ((error = Tlv0_2WireFormatLite::encodeEncryptedContentV2
       (encryptedContentLite, DynamicUInt8ArrayLite::downCast(output),
        &encodingLength)))
    throw runtime_error(ndn_getErrorString(error));

  return output.finish(encodingLength);
}
Exemplo n.º 12
0
Blob
Tlv0_2WireFormat::encodeData(const Data& data, size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
{
  struct ndn_NameComponent nameComponents[100];
  struct ndn_NameComponent keyNameComponents[100];
  DataLite dataLite
    (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
     keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));
  data.get(dataLite);

  DynamicUInt8Vector output(1500);
  ndn_Error error;
  size_t encodingLength;
  if ((error = Tlv0_2WireFormatLite::encodeData
       (dataLite, signedPortionBeginOffset, signedPortionEndOffset,
        DynamicUInt8ArrayLite::downCast(output), &encodingLength)))
    throw runtime_error(ndn_getErrorString(error));

  return output.finish(encodingLength);
}
Exemplo n.º 13
0
bool
TcpTransport::isLocal(const Transport::ConnectionInfo& connectionInfo)
{
  const TcpTransport::ConnectionInfo& tcpConnectionInfo =
    dynamic_cast<const TcpTransport::ConnectionInfo&>(connectionInfo);

  if (connectionInfo_.getHost() == "" ||
      connectionInfo_.getHost() != tcpConnectionInfo.getHost()) {
    ndn_Error error;
    int intIsLocal;
    if ((error = ndn_TcpTransport_isLocal
         ((char *)tcpConnectionInfo.getHost().c_str(), &intIsLocal)))
      throw runtime_error(ndn_getErrorString(error));

    // Cache the result in isLocal_ and save connectionInfo_ for next time.
    connectionInfo_ = tcpConnectionInfo;
    isLocal_ = (intIsLocal != 0);
  }

  return isLocal_;
}
Exemplo n.º 14
0
Blob
Tlv0_2WireFormat::encodeControlResponse(const ControlResponse& controlResponse)
{
  struct ndn_NameComponent nameComponents[100];
  struct ndn_NameComponent strategyNameComponents[100];
  ControlResponseLite controlResponseLite
    (nameComponents,
     sizeof(nameComponents) / sizeof(nameComponents[0]), strategyNameComponents,
     sizeof(strategyNameComponents) / sizeof(strategyNameComponents[0]));
  controlResponse.get(controlResponseLite);

  DynamicUInt8Vector output(256);
  ndn_Error error;
  size_t encodingLength;
  if ((error = Tlv0_2WireFormatLite::encodeControlResponse
       (controlResponseLite, DynamicUInt8ArrayLite::downCast(output),
        &encodingLength)))
    throw runtime_error(ndn_getErrorString(error));

  return output.finish(encodingLength);
}
Exemplo n.º 15
0
void
Tlv0_2WireFormat::decodeDelegationSet
  (DelegationSet& delegationSet, const uint8_t *input, size_t inputLength)
{
  delegationSet.clear();

  // Decode a series of Delegation
  size_t offset = 0;
  while (offset < inputLength) {
    struct ndn_NameComponent nameComponents[100];
    DelegationSetLite::Delegation delegationLite
      (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));

    size_t encodingLength;
    ndn_Error error;
    if ((error = Tlv0_2WireFormatLite::decodeDelegationSet_Delegation
         (delegationLite, input + offset, inputLength - offset, &encodingLength)))
      throw runtime_error(ndn_getErrorString(error));

    offset += encodingLength;
    delegationSet.addUnsorted
      (ptr_lib::make_shared<DelegationSet::Delegation>(delegationLite));
  }
}