当前位置: 首页>>代码示例>>Python>>正文


Python Interest.setMustBeFresh方法代码示例

本文整理汇总了Python中pyndn.Interest.setMustBeFresh方法的典型用法代码示例。如果您正苦于以下问题:Python Interest.setMustBeFresh方法的具体用法?Python Interest.setMustBeFresh怎么用?Python Interest.setMustBeFresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyndn.Interest的用法示例。


在下文中一共展示了Interest.setMustBeFresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
def main():
    # Silence the warning from Interest wire encode.
    Interest.setDefaultCanBePrefix(True)

    interest = Interest()
    interest.wireDecode(TlvInterest)

    # Use a hard-wired secret for testing. In a real application the signer
    # ensures that the verifier knows the shared key and its keyName.
    key = Blob(bytearray([
       0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
      16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
    ]))

    if KeyChain.verifyInterestWithHmacWithSha256(interest, key):
      dump("Hard-coded interest signature verification: VERIFIED")
    else:
      dump("Hard-coded interest signature verification: FAILED")

    freshInterest = Interest(Name("/ndn/abc"))
    freshInterest.setMustBeFresh(False)
    keyName = Name("key1")
    dump("Signing fresh interest", freshInterest.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshInterest, key, keyName)

    if KeyChain.verifyInterestWithHmacWithSha256(freshInterest, key):
      dump("Freshly-signed interest signature verification: VERIFIED")
    else:
      dump("Freshly-signed interest signature verification: FAILED")
开发者ID:named-data,项目名称:PyNDN2,代码行数:31,代码来源:test_sign_verify_interest_hmac.py

示例2: reissueInterest

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
 def reissueInterest(self):
     BACKOFF_THRESHOLD = 10
     if self.backoffCounter > BACKOFF_THRESHOLD:
         self.TIMEOUT += 50
         self.backoffCounter = 0
         self.logger.debug('Backing off interval to ' + str(self.TIMEOUT))
     if self.backoffCounter < -BACKOFF_THRESHOLD:
         self.TIMEOUT -= 50
         self.backoffCounter = 0
         self.logger.debug('Reducing backoff interval to ' + str(self.TIMEOUT))
     if self.nextIssue is not None:
         now = time.clock()
         if self.nextIssue > now:
             pass
            # time.sleep(self.nextIssue-now)
     interest = Interest(Name(self.prefix))
     interest.setInterestLifetimeMilliseconds(self.interestLifetime)
     interest.setMustBeFresh(False)
     if self.lastVersion is not None:
         e = Exclude()
         e.appendAny()
         e.appendComponent(self.lastVersion)
         interest.setExclude(e)
     interest.setChildSelector(1) #rightmost == freshest
     self.face.expressInterest(interest, self.onData, self.onTimeout)
     self.nextIssue = time.clock()+self.TIMEOUT/2000
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:28,代码来源:consumer.py

示例3: main

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
def main():
    interest = Interest()
    interest.wireDecode(TlvInterest)
    dump("Interest:")
    dumpInterest(interest)
    
    encoding = interest.wireEncode()
    dump("")
    dump("Re-encoded interest", encoding.toHex())
    
    reDecodedInterest = Interest()
    reDecodedInterest.wireDecode(encoding)
    dump("Re-decoded Interest:")
    dumpInterest(reDecodedInterest)

    freshInterest = Interest(Name("/ndn/abc"))
    freshInterest.setMustBeFresh(False)
    dump(freshInterest.toUri())
    freshInterest.setMinSuffixComponents(4)
    freshInterest.setMaxSuffixComponents(6)
    freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
    freshInterest.getKeyLocator().setKeyData(bytearray(
      [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 
       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
    freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
    freshInterest.setInterestLifetimeMilliseconds(30000)
    freshInterest.setChildSelector(1)
    freshInterest.setMustBeFresh(True);
    freshInterest.setScope(2)

    reDecodedFreshInterest = Interest()
    reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
    dump("")
    dump("Re-decoded fresh Interest:")
    dumpInterest(reDecodedFreshInterest)
开发者ID:priestd09,项目名称:PyNDN2,代码行数:37,代码来源:test_encode_decode_interest.py

示例4: startPublishingAggregation

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def startPublishingAggregation(self, params, childrenList, dataType, aggregationType):
        if __debug__:
            print('Start publishing for ' + dataType + '-' + aggregationType)
        
        # aggregation calculating and publishing mechanism
        publishingPrefix = Name(self._identityName).append(DATA_COMPONENT).append(dataType).append(AGGREGATION_COMPONENT).append(aggregationType)
        self._dataQueue[dataType + aggregationType] = DataQueue(params, childrenList, publishingPrefix)

        if len(childrenList.keys()) == 0:
            # TODO: make start_time optional for leaf nodes
            self._loop.call_later(int(params['producer_interval']), self.calculateAggregation, dataType, aggregationType, childrenList, int(params['start_time']), int(params['producer_interval']), publishingPrefix, True)
        else:
            # express interest for children who produce the same data and aggregation type
            for childName in childrenList.keys():
                name = Name(self._identityName).append(childName).append(DATA_COMPONENT).append(dataType).append(AGGREGATION_COMPONENT).append(aggregationType)
                interest = Interest(name)
                # if start_time is specified, we ask for data starting at start_time; 
                # if not, we ask for the right most child and go from there
                if ('start_time' in childrenList[childName]):
                    endTime = int(childrenList[childName]['start_time']) + int(childrenList[childName]['producer_interval'])
                    interest.getName().append(str(childrenList[childName]['start_time'])).append(str(endTime))
                else:
                    # TODO: For now we are playing with historical data, for each run we don't want to miss any data, thus we start with leftMost
                    interest.setChildSelector(0)
                    interest.setMustBeFresh(True)
                interest.setInterestLifetimeMilliseconds(DEFAULT_INTEREST_LIFETIME)
                if __debug__:
                    print('  Issue interest: ' + interest.getName().toUri())
                self._face.expressInterest(interest, self.onData, self.onTimeout)

        return
开发者ID:zhehaowang,项目名称:bms-node,代码行数:33,代码来源:bms_node.py

示例5: main

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
def main():
    interest = Interest()
    interest.wireDecode(TlvInterest)
    dump("Interest:")
    dumpInterest(interest)

    # Set the name again to clear the cached encoding so we encode again.
    interest.setName(interest.getName())
    encoding = interest.wireEncode()
    dump("")
    dump("Re-encoded interest", encoding.toHex())

    reDecodedInterest = Interest()
    reDecodedInterest.wireDecode(encoding)
    dump("Re-decoded Interest:")
    dumpInterest(reDecodedInterest)

    freshInterest = Interest(Name("/ndn/abc"))
    freshInterest.setMustBeFresh(False)
    dump(freshInterest.toUri())
    freshInterest.setMinSuffixComponents(4)
    freshInterest.setMaxSuffixComponents(6)
    freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
    freshInterest.getKeyLocator().setKeyData(bytearray(
      [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
    freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
    freshInterest.setInterestLifetimeMilliseconds(30000)
    freshInterest.setChildSelector(1)
    freshInterest.setMustBeFresh(True);
    freshInterest.setScope(2)

    identityStorage = MemoryIdentityStorage()
    privateKeyStorage = MemoryPrivateKeyStorage()
    keyChain = KeyChain(IdentityManager(identityStorage, privateKeyStorage),
                        SelfVerifyPolicyManager(identityStorage))

    # Initialize the storage.
    keyName = Name("/testname/DSK-123")
    certificateName = keyName.getSubName(0, keyName.size() - 1).append(
      "KEY").append(keyName[-1]).append("ID-CERT").append("0")
    identityStorage.addKey(keyName, KeyType.RSA, Blob(DEFAULT_RSA_PUBLIC_KEY_DER))
    privateKeyStorage.setKeyPairForKeyName(
      keyName, KeyType.RSA, DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER)

    # Make a Face just so that we can sign the interest.
    face = Face("localhost")
    face.setCommandSigningInfo(keyChain, certificateName)
    face.makeCommandInterest(freshInterest)

    reDecodedFreshInterest = Interest()
    reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
    dump("")
    dump("Re-decoded fresh Interest:")
    dumpInterest(reDecodedFreshInterest)

    keyChain.verifyInterest(
      reDecodedFreshInterest, makeOnVerified("Freshly-signed Interest"),
      makeOnVerifyFailed("Freshly-signed Interest"))
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:61,代码来源:test_encode_decode_interest.py

示例6: _decryptAndPrintRecord

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def _decryptAndPrintRecord(self, recordData, keyName, parentDoc):
        keyUri = keyName.toUri()
        def cleanString(dirty):
            return ''.join(filter(string.printable.__contains__, str(dirty)))

        def onKeyDataReceived(keyInterest, keyData):
            self.log.debug('Got key for {}'.format(keyInterest.getName()))
            cipherText = str(keyData.getContent())
            symKeyRaw = self.privateKey.decrypt(cipherText)
            symKey = symKeyRaw[-64:].decode('hex')

            msg = recordData[8:]
            iv = msg[:16]
            cipherText = msg[16:]

            cipher = AES.new(key=symKey, IV=iv, mode=AES.MODE_CBC)
            decData = cleanString(cipher.decrypt(cipherText))

            fromJson = json.loads(decData)
            fromJson.update(parentDoc)
            self.knownKeys[keyUri] = keyData
            try:
                self.pendingKeys.remove(keyUri)
            except ValueError:
                pass # already removed

            self.resultQueue.put_nowait(fromJson)

        def onKeyTimeout(keyInterest):
            self.log.error('Could not get decryption key for {}'.format(keyInterest.getName()))
            self.resultQueue.put_nowait({})

        i = Interest(keyName)
        i.setMustBeFresh(False)
        i.setInterestLifetimeMilliseconds(2000)

        if keyUri in self.knownKeys:
            self.log.debug('Using known key')
            onKeyDataReceived(i, self.knownKeys[keyUri])
        elif keyUri in self.pendingKeys:
            self.log.debug('Waiting on pending key')
            timeout = 0
            while keyUri not in self.knownKeys:
                yield From(asyncio.sleep(0.5))
                timeout += 1
                if timeout > 5:
                    self.log.warn('Timed out on key {}'.format(keyUri))
                    onKeyTimeout(i)
                    break
            else:
                onKeyDataReceived(i, self.knownKeys[keyUri])
        else:
            self.log.debug('Adding {} to pending keys'.format(keyUri))
            self.pendingKeys.append(keyUri)
            self.keyFace.expressInterest(i, onKeyDataReceived, onKeyTimeout)
开发者ID:thecodemaiden,项目名称:ndn-repo-3,代码行数:57,代码来源:bms_client.py

示例7: onSyncTimeout

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def onSyncTimeout(self, interest):
        newInterest = Interest(Name(self._syncPrefix).append(self._currentDigest))
        newInterest.setInterestLifetimeMilliseconds(self._syncInterestLifetime)
        newInterest.setMustBeFresh(True)
        self._numOutstandingInterest -= 1
        print "re-expressing: " + newInterest.getName().toUri()

        if self._numOutstandingInterest <= 0:
            self._face.expressInterest(newInterest, self.onSyncData, self.onSyncTimeout)
            self._numOutstandingInterest += 1
        return
开发者ID:remap,项目名称:ndn-flow,代码行数:13,代码来源:sync_based_discovery.py

示例8: _sendNextInterestWithSegment

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def _sendNextInterestWithSegment(self, name):
        interest = Interest(name)
        uri = name.toUri()

        interest.setInterestLifetimeMilliseconds(4000)
        interest.setMustBeFresh(True)

        if name.toUri() not in self.outstanding:
            self.outstanding[name.toUri()] = 1

        self.face.expressInterest(interest, self._onData, self._onTimeout)
        print "Sent Interest for %s" % uri
开发者ID:dibenede,项目名称:ndn-tutorial-gec21,代码行数:14,代码来源:consumer.py

示例9: start

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
 def start(self):
     """
     Starts the discovery
     """
     interest = Interest(Name(self._syncPrefix).append(self._initialDigest))
     interest.setMustBeFresh(True)
     interest.setInterestLifetimeMilliseconds(self._syncInterestLifetime)
     self._face.expressInterest(interest, self.onSyncData, self.onSyncTimeout)
     self._numOutstandingInterest += 1
     if __debug__:
         print("Express interest: " + interest.getName().toUri())
     return
开发者ID:remap,项目名称:ndn-flow,代码行数:14,代码来源:sync_based_discovery.py

示例10: _sendNextInterest

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def _sendNextInterest(self, name):
        interest = Interest(name)
        uri = name.toUri()

        interest.setInterestLifetimeMilliseconds(4000)
        interest.setMustBeFresh(True)

        if uri not in self.outstanding:
            self.outstanding[uri] = 1

        self.face.expressInterest(interest, self._onData, self._onTimeout)
        print "Sent Interest for %s" % uri
        global start_time
        start_time = time.time()
开发者ID:thiteixeira,项目名称:GENI,代码行数:16,代码来源:consumer.py

示例11: createFreshInterest

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
def createFreshInterest():
    freshInterest = Interest(Name("/ndn/abc"))
    freshInterest.setMustBeFresh(False)
    freshInterest.setMinSuffixComponents(4)
    freshInterest.setMaxSuffixComponents(6)
    freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
    freshInterest.getKeyLocator().setKeyData(bytearray(
      [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 
       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
    freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
    freshInterest.setInterestLifetimeMilliseconds(30000)
    freshInterest.setChildSelector(1)
    freshInterest.setMustBeFresh(True);
    freshInterest.setScope(2)

    return freshInterest
开发者ID:bboalimoe,项目名称:PyNDN2,代码行数:18,代码来源:test_interest_methods.py

示例12: run

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def run(self):
        try:
            interest = Interest(self.name)
            uri = self.name.toUri()

            interest.setInterestLifetimeMilliseconds(4000)
            interest.setMustBeFresh(True)

            self.face.expressInterest(interest, self._onData, self._onTimeout)

            while not self.isDone:
                self.face.processEvents()
                time.sleep(0.01)

            print "Sent Interest for %s" % uri

        except RuntimeError as e:
            print "ERROR: %s" % e
开发者ID:dibenede,项目名称:nfd-strategies,代码行数:20,代码来源:consumer.py

示例13: publishObject

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
    def publishObject(self, name, entityInfo):
        """
        Adds another object and registers prefix for that object's name

        :param name: the object's name string
        :type name: str
        :param entityInfo: the application given entity info to describe this object name with
        :type entityInfo: EntityInfo
        """
        # If this is the first object we host, we register for sync namespace: meaning a participant not hosting anything 
        #   is only "listening" for sync, and will not help in the sync process
        if len(self._hostedObjects.keys()) == 0:
            self._memoryContentCache.registerPrefix(self._syncPrefix, self.onRegisterFailed, self.onSyncInterest)
        if self.addObject(name, False):
            # Do not add itself to contentCache if its currentDigest is "00".
            if self._currentDigest != self._initialDigest:
                self.contentCacheAddSyncData(Name(self._syncPrefix).append(self._currentDigest))
            
            self.updateDigest()
            
            interest = Interest(Name(self._syncPrefix).append(self._currentDigest))
            interest.setInterestLifetimeMilliseconds(self._syncInterestLifetime)
            interest.setMustBeFresh(True)
            
            self._face.expressInterest(interest, self.onSyncData, self.onSyncTimeout)
            self._numOutstandingInterest += 1

            self._hostedObjects[name] = entityInfo
            self.contentCacheAddEntityData(name, entityInfo)
            self.notifyObserver(name, "ADD", "")
            # TODO: should the user configure this prefix as well?
            self._memoryContentCache.registerPrefix(Name(name), self.onRegisterFailed, self.onEntityDataNotFound)
        else:
            if __debug__:
                print("Item with this name already added")
        return
开发者ID:remap,项目名称:ndn-flow,代码行数:38,代码来源:sync_based_discovery.py

示例14: _expressCustomInterest

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
 def _expressCustomInterest(self, interestName):
     # TODO: make this a form, add timeout field
     try:
         handled = False
         (returnCode, returnStr) = self.ui.prompt(
             "Send interest",
             interestName,
             preExtra=["--extra-button", "--extra-label", "Signed", "--ok-label", "Unsigned"],
         )
         if returnCode == Dialog.DIALOG_ESC or returnCode == Dialog.DIALOG_CANCEL:
             self.loop.call_soon(self.expressInterest)
         else:
             interestName = Name(returnStr)
             doSigned = returnCode == Dialog.DIALOG_EXTRA
             interest = Interest(interestName)
             interest.setInterestLifetimeMilliseconds(5000)
             interest.setChildSelector(1)
             interest.setMustBeFresh(True)
             if doSigned:
                 self.face.makeCommandInterest(interest)
             self.ui.alert("Waiting for response to {}".format(interestName.toUri()), False)
             self.face.expressInterest(interest, self.onDataReceived, self.onInterestTimeout)
     except:
         self.loop.call_soon(self.expressInterest)
开发者ID:RayneHwang,项目名称:ndn-pi,代码行数:26,代码来源:iot_console.py

示例15: onReceivedSyncData

# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import setMustBeFresh [as 别名]
 def onReceivedSyncData(self, itemName):
     interest = Interest(Name(itemName))
     interest.setInterestLifetimeMilliseconds(4000)
     interest.setMustBeFresh(False)
     self._face.expressInterest(interest, self.onEntityData, self.onEntityTimeout) 
     return
开发者ID:remap,项目名称:ndn-flow,代码行数:8,代码来源:sync_based_discovery.py


注:本文中的pyndn.Interest.setMustBeFresh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。