예제 #1
0
파일: link.py 프로젝트: asystemsguy/PyNDN2
    def __init__(self, value=None):
        """
        Create a new Link with the optional values. There are 3 forms of the
        constructor:
        Link(name)
        Link(data)
        Link()

        :param Name name: The name for constructing the base Data.
        :param Data data: The Data object to copy values from. If the content
          can be decoded using the default wire encoding, then update the list
          of delegations.
        """
        self._delegations = DelegationSet()

        if isinstance(value, Data):
            super(Link, self).__init__(value)

            if not self.getContent().isNull():
                try:
                    self._delegations.wireDecode(self.getContent())
                    self.getMetaInfo().setType(ContentType.LINK)
                except:
                    self._delegations.clear()
        else:
            super(Link, self).__init__(value)
            self.getMetaInfo().setType(ContentType.LINK)
예제 #2
0
파일: interest.py 프로젝트: danome/PyNDN2
    def __init__(self, value=None):
        if isinstance(value, Interest):
            # Copy the values.
            self._name = ChangeCounter(Name(value.getName()))
            self._minSuffixComponents = value._minSuffixComponents
            self._maxSuffixComponents = value._maxSuffixComponents
            self._didSetCanBePrefix = value._didSetCanBePrefix
            self._keyLocator = ChangeCounter(KeyLocator(value.getKeyLocator()))
            self._exclude = ChangeCounter(Exclude(value.getExclude()))
            self._childSelector = value._childSelector
            self._mustBeFresh = value._mustBeFresh

            self._nonce = value.getNonce()
            self._interestLifetimeMilliseconds = value._interestLifetimeMilliseconds
            self._forwardingHint = ChangeCounter(
                DelegationSet(value.getForwardingHint()))
            self._applicationParameters = value._applicationParameters
            self._linkWireEncoding = value._linkWireEncoding
            self._linkWireEncodingFormat = value._linkWireEncodingFormat
            self._link = ChangeCounter(None)
            if value._link.get() != None:
                self._link.set(Link(value._link.get()))
            self._selectedDelegationIndex = value._selectedDelegationIndex
            self._defaultWireEncoding = value.getDefaultWireEncoding()
            self._defaultWireEncodingFormat = value._defaultWireEncodingFormat
        else:
            self._name = ChangeCounter(Name(value))
            self._minSuffixComponents = None
            self._maxSuffixComponents = None if Interest._defaultCanBePrefix else 1
            # _didSetCanBePrefix is True if the app already called setDefaultCanBePrefix().
            self._didSetCanBePrefix = Interest._didSetDefaultCanBePrefix
            self._keyLocator = ChangeCounter(KeyLocator())
            self._exclude = ChangeCounter(Exclude())
            self._childSelector = None
            self._mustBeFresh = False

            self._nonce = Blob()
            self._interestLifetimeMilliseconds = None
            self._forwardingHint = ChangeCounter(DelegationSet())
            self._applicationParameters = Blob()
            self._linkWireEncoding = Blob()
            self._linkWireEncodingFormat = None
            self._link = ChangeCounter(None)
            self._selectedDelegationIndex = None
            self._defaultWireEncoding = SignedBlob()
            self._defaultWireEncodingFormat = None

        self._getNonceChangeCount = 0
        self._getDefaultWireEncodingChangeCount = 0
        self._changeCount = 0
        self._lpPacket = None
예제 #3
0
    def __init__(self, value=None):
        if type(value) is Interest:
            # Copy the values.
            self._name = ChangeCounter(Name(value.getName()))
            self._minSuffixComponents = value._minSuffixComponents
            self._maxSuffixComponents = value._maxSuffixComponents
            self._keyLocator = ChangeCounter(KeyLocator(value.getKeyLocator()))
            self._exclude = ChangeCounter(Exclude(value.getExclude()))
            self._childSelector = value._childSelector
            self._mustBeFresh = value._mustBeFresh

            self._nonce = value.getNonce()
            self._interestLifetimeMilliseconds = value._interestLifetimeMilliseconds
            self._forwardingHint = ChangeCounter(
                DelegationSet(value.getForwardingHint()))
            self._linkWireEncoding = value._linkWireEncoding
            self._linkWireEncodingFormat = value._linkWireEncodingFormat
            self._link = ChangeCounter(None)
            if value._link.get() != None:
                self._link.set(Link(value._link.get()))
            self._selectedDelegationIndex = value._selectedDelegationIndex
            self._defaultWireEncoding = value.getDefaultWireEncoding()
            self._defaultWireEncodingFormat = value._defaultWireEncodingFormat
            self._content = value._content
        else:
            self._name = ChangeCounter(
                Name(value) if type(value) is Name else Name())
            self._minSuffixComponents = None
            self._maxSuffixComponents = None
            self._keyLocator = ChangeCounter(KeyLocator())
            self._exclude = ChangeCounter(Exclude())
            self._childSelector = None
            self._mustBeFresh = True

            self._nonce = Blob()
            self._interestLifetimeMilliseconds = None
            self._forwardingHint = ChangeCounter(DelegationSet())
            self._linkWireEncoding = Blob()
            self._linkWireEncodingFormat = None
            self._link = ChangeCounter(None)
            self._selectedDelegationIndex = None
            self._defaultWireEncoding = SignedBlob()
            self._defaultWireEncodingFormat = None
            self._content = Blob()

        self._getNonceChangeCount = 0
        self._getDefaultWireEncodingChangeCount = 0
        self._changeCount = 0
        self._lpPacket = None
예제 #4
0
    def __init__(self, value = None):
        """
        Create a new Link with the optional values. There are 3 forms of the
        constructor:
        Link(name)
        Link(data)
        Link()

        :param Name name: The name for constructing the base Data.
        :param Data data: The Data object to copy values from. If the content
          can be decoded using the default wire encoding, then update the list
          of delegations.
        """
        self._delegations = DelegationSet()

        if isinstance(value, Data):
            super(Link, self).__init__(value)

            if not self.getContent().isNull():
                try:
                    self._delegations.wireDecode(self.getContent())
                    self.getMetaInfo().setType(ContentType.LINK)
                except:
                    self._delegations.clear()
        else:
            super(Link, self).__init__(value)
            self.getMetaInfo().setType(ContentType.LINK)
예제 #5
0
파일: interest.py 프로젝트: tuple71/PyNDN2
    def __init__(self, value=None):
        if isinstance(value, Interest):
            # Copy the values.
            self._name = ChangeCounter(Name(value.getName()))
            self._canBePrefix = value._canBePrefix
            self._hopLimit = value._hopLimit
            self._keyLocator = ChangeCounter(KeyLocator(value.getKeyLocator()))
            self._mustBeFresh = value._mustBeFresh

            self._nonce = value.getNonce()
            self._interestLifetimeMilliseconds = value._interestLifetimeMilliseconds
            self._forwardingHint = ChangeCounter(
                DelegationSet(value.getForwardingHint()))
            self._applicationParameters = value._applicationParameters
            self._linkWireEncoding = value._linkWireEncoding
            self._linkWireEncodingFormat = value._linkWireEncodingFormat
            self._link = ChangeCounter(None)
            if value._link.get() != None:
                self._link.set(Link(value._link.get()))
            self._selectedDelegationIndex = value._selectedDelegationIndex
            self._defaultWireEncoding = value.getDefaultWireEncoding()
            self._defaultWireEncodingFormat = value._defaultWireEncodingFormat
        else:
            self._name = ChangeCounter(Name(value))
            self._canBePrefix = Interest._defaultCanBePrefix
            self._hopLimit = Interest._defaultHopLimit
            self._keyLocator = ChangeCounter(KeyLocator())
            self._mustBeFresh = False

            self._nonce = Blob()
            self._interestLifetimeMilliseconds = None
            self._forwardingHint = ChangeCounter(DelegationSet())
            self._applicationParameters = Blob()
            self._linkWireEncoding = Blob()
            self._linkWireEncodingFormat = None
            self._link = ChangeCounter(None)
            self._selectedDelegationIndex = None
            self._defaultWireEncoding = SignedBlob()
            self._defaultWireEncodingFormat = None

        self._getNonceChangeCount = 0
        self._getDefaultWireEncodingChangeCount = 0
        self._changeCount = 0
        self._lpPacket = None
예제 #6
0
    def setForwardingHint(self, forwardingHint):
        """
        Set this interest to use a copy of the given DelegationSet object as the
        forwarding hint.

        :note: You can also call getForwardingHint and change the forwarding
          hint directly.
        :param DelegationSet forwardingHint: The DelegationSet object to use as
          the forwarding  hint. This makes a copy of the object. If no
          forwarding hint is specified, set to a new default DelegationSet()
          with no entries.
        :return: This Interest so that you can chain calls to update values.
        :rtype: Interest
        """
        self._forwardingHint.set(
            DelegationSet(forwardingHint)
            if type(forwardingHint) is DelegationSet else DelegationSet())
        self._changeCount += 1
        return self
예제 #7
0
class Link(Data):
    def __init__(self, value = None):
        """
        Create a new Link with the optional values. There are 3 forms of the
        constructor:
        Link(name)
        Link(data)
        Link()

        :param Name name: The name for constructing the base Data.
        :param Data data: The Data object to copy values from. If the content
          can be decoded using the default wire encoding, then update the list
          of delegations.
        """
        self._delegations = DelegationSet()

        if isinstance(value, Data):
            super(Link, self).__init__(value)

            if not self.getContent().isNull():
                try:
                    self._delegations.wireDecode(self.getContent())
                    self.getMetaInfo().setType(ContentType.LINK)
                except:
                    self._delegations.clear()
        else:
            super(Link, self).__init__(value)
            self.getMetaInfo().setType(ContentType.LINK)

    def wireDecode(self, input, wireFormat = None):
        """
        Override to call the base class wireDecode then populate the list of
        delegations from the content.

        :param input: The array with the bytes to decode.
        :type input: A Blob or an array type with int elements
        :param wireFormat: (optional) A WireFormat object used to decode this
           DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
        :type wireFormat: A subclass of WireFormat
        """
        if wireFormat == None:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        Data.wireDecode(self, input, wireFormat)
        if self.getMetaInfo().getType() != ContentType.LINK:
            raise RuntimeError(
              "Link.wireDecode: MetaInfo ContentType is not LINK.")

        self._delegations.wireDecode(self.getContent())

    def addDelegation(self, preference, name, wireFormat = None):
        """
        Add a new delegation to the list of delegations, sorted by preference
        number then by name. Re-encode this object's content using the optional
        wireFormat.

        :param int preference: The preference number.
        :param Name name: The delegation name. This makes a copy of the name. If
          there is already a delegation with the same name, this updates its
          preference.
        :param wireFormat: (optional) A WireFormat object used to encode the
           DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
        :type wireFormat: A subclass of WireFormat
        :return: This Link so that you can chain calls to update values.
        :rtype: Link
        """
        if wireFormat == None:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        self._delegations.add(preference, name)
        self.encodeContent(wireFormat)

        return self

    def removeDelegation(self, name, wireFormat = None):
        """
        Remove every delegation with the given name. Re-encode this object's
        content using the optional wireFormat.

        :param Name name: Then name to match the name of the delegation(s) to be
          removed.
        :param wireFormat: (optional) A WireFormat object used to encode the
           DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
        :type wireFormat: A subclass of WireFormat
        :return: True if a delegation was removed, otherwise False.
        :rtype: bool
        """
        if wireFormat == None:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        wasRemoved = self._delegations.remove(name)
        if wasRemoved:
            self.encodeContent(wireFormat)

        return wasRemoved

    def getDelegations(self):
        """
        Get the list of delegation for read only.

        :return: The list of delegation, which you should treat as read-only. To
          modify it, call Link.addDelegation, etc.
        :rtype: DelegationSet
        """
        return self._delegations

    def encodeContent(self, wireFormat):
        """
        A private method to encode the delegations and set this object's
        content. Also set the meta info content type to LINK.

        :param WireFormat wireFormat: A WireFormat object used to encode the
          DelegationSet.
        """
        self.setContent(self._delegations.wireEncode(wireFormat))
        self.getMetaInfo().setType(ContentType.LINK)
예제 #8
0
파일: link.py 프로젝트: asystemsguy/PyNDN2
class Link(Data):
    def __init__(self, value=None):
        """
        Create a new Link with the optional values. There are 3 forms of the
        constructor:
        Link(name)
        Link(data)
        Link()

        :param Name name: The name for constructing the base Data.
        :param Data data: The Data object to copy values from. If the content
          can be decoded using the default wire encoding, then update the list
          of delegations.
        """
        self._delegations = DelegationSet()

        if isinstance(value, Data):
            super(Link, self).__init__(value)

            if not self.getContent().isNull():
                try:
                    self._delegations.wireDecode(self.getContent())
                    self.getMetaInfo().setType(ContentType.LINK)
                except:
                    self._delegations.clear()
        else:
            super(Link, self).__init__(value)
            self.getMetaInfo().setType(ContentType.LINK)

    def wireDecode(self, input, wireFormat=None):
        """
        Override to call the base class wireDecode then populate the list of
        delegations from the content.

        :param input: The array with the bytes to decode.
        :type input: A Blob or an array type with int elements
        :param wireFormat: (optional) A WireFormat object used to decode this
           DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
        :type wireFormat: A subclass of WireFormat
        """
        if wireFormat == None:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        Data.wireDecode(self, input, wireFormat)
        if self.getMetaInfo().getType() != ContentType.LINK:
            raise RuntimeError(
                "Link.wireDecode: MetaInfo ContentType is not LINK.")

        self._delegations.wireDecode(self.getContent())

    def addDelegation(self, preference, name, wireFormat=None):
        """
        Add a new delegation to the list of delegations, sorted by preference
        number then by name. Re-encode this object's content using the optional
        wireFormat.

        :param int preference: The preference number.
        :param Name name: The delegation name. This makes a copy of the name. If
          there is already a delegation with the same name, this updates its
          preference.
        :param wireFormat: (optional) A WireFormat object used to encode the
           DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
        :type wireFormat: A subclass of WireFormat
        :return: This Link so that you can chain calls to update values.
        :rtype: Link
        """
        if wireFormat == None:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        self._delegations.add(preference, name)
        self.encodeContent(wireFormat)

        return self

    def removeDelegation(self, name, wireFormat=None):
        """
        Remove every delegation with the given name. Re-encode this object's
        content using the optional wireFormat.

        :param Name name: Then name to match the name of the delegation(s) to be
          removed.
        :param wireFormat: (optional) A WireFormat object used to encode the
           DelegationSet. If omitted, use WireFormat.getDefaultWireFormat().
        :type wireFormat: A subclass of WireFormat
        :return: True if a delegation was removed, otherwise False.
        :rtype: bool
        """
        if wireFormat == None:
            # Don't use a default argument since getDefaultWireFormat can change.
            wireFormat = WireFormat.getDefaultWireFormat()

        wasRemoved = self._delegations.remove(name)
        if wasRemoved:
            self.encodeContent(wireFormat)

        return wasRemoved

    def getDelegations(self):
        """
        Get the list of delegation for read only.

        :return: The list of delegation, which you should treat as read-only. To
          modify it, call Link.addDelegation, etc.
        :rtype: DelegationSet
        """
        return self._delegations

    def encodeContent(self, wireFormat):
        """
        A private method to encode the delegations and set this object's
        content. Also set the meta info content type to LINK.

        :param WireFormat wireFormat: A WireFormat object used to encode the
          DelegationSet.
        """
        self.setContent(self._delegations.wireEncode(wireFormat))
        self.getMetaInfo().setType(ContentType.LINK)