def decodeInterest(self, interest, input): """ Decode input as an NDN-TLV interest and set the fields of the interest object. :param Interest interest: The Interest object whose fields are updated. :param input: The array with the bytes to decode. :type input: An array type with int elements :return: A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest). :rtype: (int, int) """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.Interest) self._decodeName(interest.getName(), decoder) if decoder.peekType(Tlv.Selectors, endOffset): self._decodeSelectors(interest, decoder) # Require a Nonce, but don't force it to be 4 bytes. nonce = Blob(decoder.readBlobTlv(Tlv.Nonce)) interest.setScope( decoder.readOptionalNonNegativeIntegerTlv(Tlv.Scope, endOffset)) interest.setInterestLifetimeMilliseconds( decoder.readOptionalNonNegativeIntegerTlvAsFloat( Tlv.InterestLifetime, endOffset)) # Set the nonce last because setting other interest fields clears it. interest.setNonce(nonce) decoder.finishNestedTlvs(endOffset)
def decodeInterest(self, interest, input): """ Decode input as an NDN-TLV interest and set the fields of the interest object. :param Interest interest: The Interest object whose fields are updated. :param input: The array with the bytes to decode. :type input: An array type with int elements """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.Interest) self._decodeName(interest.getName(), decoder) if decoder.peekType(Tlv.Selectors, endOffset): self._decodeSelectors(interest, decoder) # Require a Nonce, but don't force it to be 4 bytes. nonce = Blob(decoder.readBlobTlv(Tlv.Nonce)) interest.setScope(decoder.readOptionalNonNegativeIntegerTlv( Tlv.Scope, endOffset)) interest.setInterestLifetimeMilliseconds( decoder.readOptionalNonNegativeIntegerTlvAsFloat (Tlv.InterestLifetime, endOffset)) # Set the nonce last because setting other interest fields clears it. interest.setNonce(nonce) decoder.finishNestedTlvs(endOffset)
def decodeInterest(self, interest, input): """ Decode input as an NDN-TLV interest and set the fields of the interest object. :param Interest interest: The Interest object whose fields are updated. :param input: The array with the bytes to decode. :type input: An array type with int elements :return: A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest). :rtype: (int, int) """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.Interest) self._decodeName(interest.getName(), decoder) if decoder.peekType(Tlv.Selectors, endOffset): self._decodeSelectors(interest, decoder) # Require a Nonce, but don't force it to be 4 bytes. nonce = Blob(decoder.readBlobTlv(Tlv.Nonce)) interest.setScope(decoder.readOptionalNonNegativeIntegerTlv( Tlv.Scope, endOffset)) interest.setInterestLifetimeMilliseconds( decoder.readOptionalNonNegativeIntegerTlvAsFloat (Tlv.InterestLifetime, endOffset)) # Set the nonce last because setting other interest fields clears it. interest.setNonce(nonce) decoder.finishNestedTlvs(endOffset)
def decodeInterest(self, interest, input): """ Decode input as an NDN-TLV interest and set the fields of the interest object. :param Interest interest: The Interest object whose fields are updated. :param input: The array with the bytes to decode. :type input: An array type with int elements :return: A Tuple of (signedPortionBeginOffset, signedPortionEndOffset) where signedPortionBeginOffset is the offset in the encoding of the beginning of the signed portion, and signedPortionEndOffset is the offset in the encoding of the end of the signed portion. The signed portion starts from the first name component and ends just before the final name component (which is assumed to be a signature for a signed interest). :rtype: (int, int) """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.Interest) offsets = self._decodeName(interest.getName(), decoder) if decoder.peekType(Tlv.Selectors, endOffset): self._decodeSelectors(interest, decoder) # Require a Nonce, but don't force it to be 4 bytes. nonce = Blob(decoder.readBlobTlv(Tlv.Nonce)) interest.setInterestLifetimeMilliseconds( decoder.readOptionalNonNegativeIntegerTlvAsFloat (Tlv.InterestLifetime, endOffset)) if decoder.peekType(Tlv.Data, endOffset): # Get the bytes of the Link TLV. linkBeginOffset = decoder.getOffset() linkEndOffset = decoder.readNestedTlvsStart(Tlv.Data) decoder.seek(linkEndOffset) interest.setLinkWireEncoding( Blob(decoder.getSlice(linkBeginOffset, linkEndOffset), True), self) else: interest.unsetLink() interest.setSelectedDelegationIndex( decoder.readOptionalNonNegativeIntegerTlv( Tlv.SelectedDelegation, endOffset)) if (interest.getSelectedDelegationIndex() != None and interest.getSelectedDelegationIndex() >= 0 and not interest.hasLink()): raise RuntimeError( "Interest has a selected delegation, but no link object") # Set the nonce last because setting other interest fields clears it. interest.setNonce(nonce) decoder.finishNestedTlvs(endOffset) return offsets
def decodeForwardingEntry(self, forwardingEntry, input): """ Decode input as an forwardingEntry and set the fields of the forwardingEntry object. :param forwardingEntry: The ForwardingEntry object whose fields are updated. :type forwardingEntry: ForwardingEntry :param input: The array with the bytes to decode. :type input: An array type with int elements """ decoder = TlvDecoder(input) endOffset = decoder.readNestedTlvsStart(Tlv.ForwardingEntry) actionBytes = decoder.readOptionalBlobTlv(Tlv.Action, endOffset) if actionBytes != None: # Convert bytes to a str. forwardingEntry.setAction("".join(map(chr, actionBytes))) else: forwardingEntry.setAction(None) if decoder.peekType(Tlv.Name, endOffset): self._decodeName(forwardingEntry.getPrefix(), decoder) else: forwardingEntry.getPrefix().clear() forwardingEntry.setFaceId( decoder.readOptionalNonNegativeIntegerTlv(Tlv.FaceID, endOffset)) forwardingEntryFlags = decoder.readOptionalNonNegativeIntegerTlv( Tlv.ForwardingFlags, endOffset) if forwardingEntryFlags != None: forwardingEntry.getForwardingFlags().setForwardingEntryFlags( forwardingEntryFlags) else: # This sets the default flags. forwardingEntry.setForwardingFlags(ForwardingFlags()) forwardingEntry.setFreshnessPeriod( decoder.readOptionalNonNegativeIntegerTlvAsFloat( Tlv.FreshnessPeriod, endOffset)) decoder.finishNestedTlvs(endOffset)