示例#1
0
文件: node.cpp 项目: susmit85/ndn-cpp
void
Node::expressInterestHelper
  (uint64_t pendingInterestId,
   const ptr_lib::shared_ptr<const Interest>& interestCopy,
   const OnData& onData, const OnTimeout& onTimeout, WireFormat* wireFormat,
   Face* face)
{
  ptr_lib::shared_ptr<PendingInterest> pendingInterest(new PendingInterest
    (pendingInterestId, interestCopy, onData, onTimeout));
  pendingInterestTable_.push_back(pendingInterest);
  if (interestCopy->getInterestLifetimeMilliseconds() >= 0.0)
    // Set up the timeout.
    face->callLater
      (interestCopy->getInterestLifetimeMilliseconds(),
       bind(&Node::processInterestTimeout, this, pendingInterest));

  // Special case: For timeoutPrefix_ we don't actually send the interest.
  if (!timeoutPrefix_.match(interestCopy->getName())) {
    Blob encoding = interestCopy->wireEncode(*wireFormat);
    if (encoding.size() > getMaxNdnPacketSize())
      throw runtime_error
        ("The encoded interest size exceeds the maximum limit getMaxNdnPacketSize()");
    transport_->send(*encoding);
  }
}
ptr_lib::shared_ptr<ValidationRequest>
SelfVerifyPolicyManager::checkVerificationPolicy
  (const ptr_lib::shared_ptr<Data>& data, int stepCount, const OnVerified& onVerified, const OnVerifyFailed& onVerifyFailed)
{
  // wireEncode returns the cached encoding if available.
  if (verify(data->getSignature(), data->wireEncode()))
    onVerified(data);
  else
    onVerifyFailed(data);

  // No more steps, so return a null ValidationRequest.
  return ptr_lib::shared_ptr<ValidationRequest>();
}
ptr_lib::shared_ptr<ValidationRequest>
SelfVerifyPolicyManager::checkVerificationPolicy
  (const ptr_lib::shared_ptr<Interest>& interest, int stepCount,
   const OnVerifiedInterest& onVerified,
   const OnVerifyInterestFailed& onVerifyFailed, WireFormat& wireFormat)
{
  // Decode the last two name components of the signed interest
  ptr_lib::shared_ptr<Signature> signature =
    wireFormat.decodeSignatureInfoAndValue
      (interest->getName().get(-2).getValue().buf(),
       interest->getName().get(-2).getValue().size(),
       interest->getName().get(-1).getValue().buf(),
       interest->getName().get(-1).getValue().size());

  // wireEncode returns the cached encoding if available.
  if (verify(signature.get(), interest->wireEncode()))
    onVerified(interest);
  else
    onVerifyFailed(interest);
  
  // No more steps, so return a null ValidationRequest.
  return ptr_lib::shared_ptr<ValidationRequest>();
}