Ejemplo n.º 1
0
void
Tlv0_2WireFormat::decodeInterest
  (Interest& interest, const uint8_t *input, size_t inputLength,
   size_t *signedPortionBeginOffset, size_t *signedPortionEndOffset)
{
  struct ndn_NameComponent nameComponents[100];
  struct ndn_ExcludeEntry excludeEntries[100];
  struct ndn_NameComponent keyNameComponents[100];
  InterestLite interestLite
    (nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]),
     excludeEntries, sizeof(excludeEntries) / sizeof(excludeEntries[0]),
     keyNameComponents, sizeof(keyNameComponents) / sizeof(keyNameComponents[0]));

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

  if (interestLite.getForwardingHintWireEncoding().buf()) {
    // Throw any decoding exceptions now before calling set.
    DelegationSet delegationSet;
    decodeDelegationSet
      (delegationSet, interestLite.getForwardingHintWireEncoding().buf(),
       interestLite.getForwardingHintWireEncoding().size());
  }

  interest.set(interestLite, *this);
}
Ejemplo n.º 2
0
// Imitate Interest::set(const InterestLite& interestLite).
static void
setInterest(PyObject* interest, const InterestLite& interestLite)
{
  PyObjectRef name(PyObject_CallMethodObjArgs(interest, str.getName, NULL));
  setName(name, interestLite.getName());

  // If the value is -1, Interest.setMinSuffixComponents will set to None as desired.
  callMethodFromLong
    (interest, str.setMinSuffixComponents, interestLite.getMinSuffixComponents());
  callMethodFromLong
    (interest, str.setMaxSuffixComponents, interestLite.getMaxSuffixComponents());

  PyObjectRef keyLocator(PyObject_CallMethodObjArgs
    (interest, str.getKeyLocator, NULL));
  setKeyLocator(keyLocator, interestLite.getKeyLocator());

  PyObjectRef exclude(PyObject_CallMethodObjArgs
    (interest, str.getExclude, NULL));
  setExclude(exclude, interestLite.getExclude());

  callMethodFromLong
    (interest, str.setChildSelector, interestLite.getChildSelector());
  callMethodFromBool
    (interest, str.setMustBeFresh, interestLite.getMustBeFresh());
  callMethodFromDouble
    (interest, str.setInterestLifetimeMilliseconds,
     interestLite.getInterestLifetimeMilliseconds());

  if (interestLite.getLinkWireEncoding().buf()) {
    PyObjectRef linkWireEncoding(makeBlob(interestLite.getLinkWireEncoding()));
    // TODO: Support the wireFormat param.
    PyObjectRef ignoreResult(PyObject_CallMethodObjArgs
      (interest, str.setLinkWireEncoding, linkWireEncoding.obj, NULL));
  }
  else
    PyObjectRef ignoreResult1(PyObject_CallMethodObjArgs
      (interest, str.unsetLink, NULL));

  callMethodFromLong
    (interest, str.setSelectedDelegationIndex,
     interestLite.getSelectedDelegationIndex());

  // Set the nonce last so that getNonceChangeCount_ is set correctly.
  PyObjectRef nonce(makeBlob(interestLite.getNonce()));
  PyObjectRef ignoreResult2(PyObject_CallMethodObjArgs
    (interest, str.setNonce, nonce.obj, NULL));
}
Ejemplo n.º 3
0
/**
 * Imitate Interest::get(InterestLite& interestLite).
 * @param interest The Python Interest object to get from.
 * @param interestLite The InterestLite to update.
 * @param pool1 This calls pool1.reset to store a temporary value which must
 * remain valid while interestLite is used.
 */
static void
toInterestLite
  (PyObject* interest, InterestLite& interestLite, PyObjectRef& pool1)
{
  PyObjectRef name(PyObject_CallMethodObjArgs(interest, str.getName, NULL));
  toNameLite(name, interestLite.getName());

  // If the value is None, PyInt_AsLong returns -1 as desired.
  interestLite.setMinSuffixComponents
    ((int)toLongByMethod(interest, str.getMinSuffixComponents));
  interestLite.setMaxSuffixComponents
    ((int)toLongByMethod(interest, str.getMaxSuffixComponents));

  PyObjectRef keyLocator(PyObject_CallMethodObjArgs(interest, str.getKeyLocator, NULL));
  toKeyLocatorLite(keyLocator, interestLite.getKeyLocator());

  PyObjectRef exclude(PyObject_CallMethodObjArgs(interest, str.getExclude, NULL));
  toExcludeLite(exclude, interestLite.getExclude());

  interestLite.setChildSelector
    ((int)toLongByMethod(interest, str.getChildSelector));
  interestLite.setMustBeFresh(toBoolByMethod(interest, str.getMustBeFresh));
  interestLite.setInterestLifetimeMilliseconds
    (toDoubleByMethod(interest, str.getInterestLifetimeMilliseconds));

  // TODO: Support the wireFormat param.
  // TODO: Catch exceptions from getLinkWireEncoding.
  pool1.reset(PyObject_CallMethodObjArgs(interest, str.getLinkWireEncoding, NULL));
  PyObjectRef linkWireEncodingArray(PyObject_GetAttr(pool1, str._array));
  if (linkWireEncodingArray.obj == Py_None)
    interestLite.setLinkWireEncoding(BlobLite());
  else
    interestLite.setLinkWireEncoding(toBlobLiteFromArray(linkWireEncodingArray));
  interestLite.setSelectedDelegationIndex
    ((int)toLongByMethod(interest, str.getSelectedDelegationIndex));
}
Ejemplo n.º 4
0
/**
 * Imitate Interest::get(InterestLite& interestLite).
 * @param interest The Python Interest object to get from.
 * @param interestLite The InterestLite to update.
 * @param pool1 This calls pool1.reset to store a temporary value which must
 * remain valid while interestLite is used.
 * @param pool2 This calls pool2.reset to store a temporary value which must
 * remain valid while interestLite is used.
 */
static void
toInterestLite
  (PyObject* interest, InterestLite& interestLite, PyObjectRef& pool1,
   PyObjectRef& pool2)
{
  PyObjectRef name(PyObject_CallMethodObjArgs(interest, str.getName, NULL));
  toNameLite(name, interestLite.getName());

  // If the value is None, PyInt_AsLong returns -1 as desired.
  interestLite.setMinSuffixComponents
    ((int)toLongByMethod(interest, str.getMinSuffixComponents));
  interestLite.setMaxSuffixComponents
    ((int)toLongByMethod(interest, str.getMaxSuffixComponents));

  PyObjectRef keyLocator(PyObject_CallMethodObjArgs(interest, str.getKeyLocator, NULL));
  toKeyLocatorLite(keyLocator, interestLite.getKeyLocator());

  PyObjectRef exclude(PyObject_CallMethodObjArgs(interest, str.getExclude, NULL));
  toExcludeLite(exclude, interestLite.getExclude());

  interestLite.setChildSelector
    ((int)toLongByMethod(interest, str.getChildSelector));
  interestLite.setMustBeFresh(toBoolByMethod(interest, str.getMustBeFresh));
  interestLite.setInterestLifetimeMilliseconds
    (toDoubleByMethod(interest, str.getInterestLifetimeMilliseconds));
  interestLite.setNonce(toBlobLiteByMethod(interest, str.getNonce));
  interestLite.setApplicationParameters(toBlobLiteByMethod(interest, str.getApplicationParameters));

  PyObjectRef forwardingHint
    (PyObject_CallMethodObjArgs(interest, str.getForwardingHint, NULL));
  if (toLongByMethod(forwardingHint, str.size) > 0) {
    // InterestLite only stores the encoded delegation set. Cache the wire
    // encoding in pool2 long enough to encode the Interest.
    // TODO: Support the wireFormat param.
    // TODO: Catch exceptions from wireEncode.
    pool2.reset(PyObject_CallMethodObjArgs
      (forwardingHint, str.wireEncode, NULL));
    PyObjectRef forwardingHintWireEncodingArray
      (PyObject_GetAttr(pool2, str._array));
    interestLite.setForwardingHintWireEncoding
      (toBlobLiteFromArray(forwardingHintWireEncodingArray));
  }
  else
    interestLite.setForwardingHintWireEncoding(BlobLite());

  // TODO: Support the wireFormat param.
  // TODO: Catch exceptions from getLinkWireEncoding.
  pool1.reset(PyObject_CallMethodObjArgs(interest, str.getLinkWireEncoding, NULL));
  PyObjectRef linkWireEncodingArray(PyObject_GetAttr(pool1, str._array));
  if (linkWireEncodingArray.obj == Py_None)
    interestLite.setLinkWireEncoding(BlobLite());
  else
    interestLite.setLinkWireEncoding(toBlobLiteFromArray(linkWireEncodingArray));
  interestLite.setSelectedDelegationIndex
    ((int)toLongByMethod(interest, str.getSelectedDelegationIndex));
}