本文整理汇总了Python中pyndn.Interest.getName方法的典型用法代码示例。如果您正苦于以下问题:Python Interest.getName方法的具体用法?Python Interest.getName怎么用?Python Interest.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Interest
的用法示例。
在下文中一共展示了Interest.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startPublishingAggregation
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [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
示例2: test_find_by_interest
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def test_find_by_interest(self):
self.anchorContainer.insert("group1", self.certificatePath1, 400.0)
interest = Interest(self.identity1.getName())
self.assertTrue(self.anchorContainer.find(interest) != None)
interest1 = Interest(self.identity1.getName().getPrefix(-1))
self.assertTrue(self.anchorContainer.find(interest1) != None)
interest2 = Interest(Name(self.identity1.getName()).appendVersion(1))
self.assertTrue(self.anchorContainer.find(interest2) == None)
certificate3 = self.fixture.addCertificate(
self.identity1.getDefaultKey(), "3")
certificate4 = self.fixture.addCertificate(
self.identity1.getDefaultKey(), "4")
certificate5 = self.fixture.addCertificate(
self.identity1.getDefaultKey(), "5")
certificate3Copy = CertificateV2(certificate3)
self.anchorContainer.insert("group2", certificate3Copy)
self.anchorContainer.insert("group3", certificate4)
self.anchorContainer.insert("group4", certificate5)
interest3 = Interest(certificate3.getKeyName())
foundCertificate = self.anchorContainer.find(interest3)
self.assertTrue(foundCertificate != None)
self.assertTrue(interest3.getName().isPrefixOf(foundCertificate.getName()))
self.assertTrue(certificate3.getName().equals(foundCertificate.getName()))
interest3.getExclude().appendComponent(
certificate3.getName().get(CertificateV2.ISSUER_ID_OFFSET))
foundCertificate = self.anchorContainer.find(interest3)
self.assertTrue(foundCertificate != None)
self.assertTrue(interest3.getName().isPrefixOf(foundCertificate.getName()))
self.assertTrue(not foundCertificate.getName().equals(certificate3.getName()))
示例3: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def main():
# The default Face connects to the local NFD.
face = Face()
interest = Interest(Name("/localhost/nfd/rib/list"))
interest.setInterestLifetimeMilliseconds(4000)
dump("Express interest", interest.getName().toUri())
enabled = [True]
def onComplete(content):
enabled[0] = False
printRibEntries(content)
def onError(errorCode, message):
enabled[0] = False
dump(message)
SegmentFetcher.fetch(
face, interest, SegmentFetcher.DontVerifySegment, onComplete, onError)
# Loop calling processEvents until a callback sets enabled[0] = False.
while enabled[0]:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(0.01)
示例4: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [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")
示例5: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def main():
# Silence the warning from Interest wire encode.
Interest.setDefaultCanBePrefix(True)
# The default Face connects to the local NFD.
face = Face()
interest = Interest(Name("/localhost/nfd/faces/list"))
interest.setInterestLifetimeMilliseconds(4000)
dump("Express interest", interest.getName().toUri())
enabled = [True]
def onComplete(content):
enabled[0] = False
printFaceStatuses(content)
def onError(errorCode, message):
enabled[0] = False
dump(message)
SegmentFetcher.fetch(face, interest, None, onComplete, onError)
# Loop calling processEvents until a callback sets enabled[0] = False.
while enabled[0]:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(0.01)
示例6: _sendCertificateRequest
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def _sendCertificateRequest(self, keyIdentity):
"""
We compose a command interest with our public key info so the controller
can sign us a certificate that can be used with other nodes in the network.
"""
try:
defaultKey = self._identityStorage.getDefaultKeyNameForIdentity(keyIdentity)
except SecurityException:
defaultKey = self._identityManager.generateRSAKeyPairAsDefault(keyIdentity)
self.log.debug("Key name: " + defaultKey.toUri())
message = CertificateRequestMessage()
publicKey = self._identityManager.getPublicKey(defaultKey)
message.command.keyType = publicKey.getKeyType()
message.command.keyBits = publicKey.getKeyDer().toRawStr()
for component in range(defaultKey.size()):
message.command.keyName.components.append(defaultKey.get(component).toEscapedString())
paramComponent = ProtobufTlv.encode(message)
interestName = Name(self._policyManager.getTrustRootIdentity()).append("certificateRequest").append(paramComponent)
interest = Interest(interestName)
interest.setInterestLifetimeMilliseconds(10000) # takes a tick to verify and sign
self._hmacHandler.signInterest(interest, keyName=self.prefix)
self.log.info("Sending certificate request to controller")
self.log.debug("Certificate request: "+interest.getName().toUri())
self.face.expressInterest(interest, self._onCertificateReceived, self._onCertificateTimeout)
示例7: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [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"))
示例8: processFaceStatus
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def processFaceStatus(encodedFaceStatus, prefix, uri, face, enabled):
"""
This is called when all the segments are received to decode the
encodedFaceStatus as a TLV FaceStatus message. If the face ID exists for the
face URL, use it to call registerRoute(), otherwise send a
/localhost/nfd/faces/create command to create the face.
:param Blob encodedFaceStatus: The TLV-encoded FaceStatus.
:param Name prefix: The prefix name to register.
:param str uri: The remote URI in case we need to tell NFD to create a face.
:param Face face: The Face which is used to sign the command interest and
call expressInterest.
:param enabled: On success or error, set enabled[0] = False.
:type enabled: An array with one bool element
"""
if encodedFaceStatus.size() == 0:
# No result, so we need to tell NFD to create the face.
# Encode the ControlParameters.
message = \
control_parameters_pb2.ControlParametersTypes.ControlParametersMessage()
message.control_parameters.uri = uri
encodedControlParameters = ProtobufTlv.encode(message)
interest = Interest(Name("/localhost/nfd/faces/create"))
interest.getName().append(encodedControlParameters)
interest.setInterestLifetimeMilliseconds(10000)
def onData(localInterest, data):
processCreateFaceResponse(data.getContent(), prefix, face, enabled)
def onTimeout(localInterest):
enabled[0] = False
dump("Face create command timed out.")
# Sign and express the interest.
face.makeCommandInterest(interest)
face.expressInterest(interest, onData, onTimeout)
else:
decodedFaceStatus = face_status_pb2.FaceStatusMessage()
ProtobufTlv.decode(decodedFaceStatus, encodedFaceStatus)
faceId = decodedFaceStatus.face_status[0].face_id
dump("Found face ID ", faceId)
registerRoute(prefix, faceId, face, enabled)
示例9: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def main():
# Silence the warning from Interest wire encode.
Interest.setDefaultCanBePrefix(True)
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"))
.setMustBeFresh(False)
.setMinSuffixComponents(4)
.setMaxSuffixComponents(6)
.setInterestLifetimeMilliseconds(30000)
.setChildSelector(1)
.setMustBeFresh(True))
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.getForwardingHint().add(1, Name("/A"))
dump(freshInterest.toUri())
# Set up the KeyChain.
keyChain = KeyChain("pib-memory:", "tpm-memory:")
keyChain.importSafeBag(SafeBag
(Name("/testname/KEY/123"),
Blob(DEFAULT_RSA_PRIVATE_KEY_DER, False),
Blob(DEFAULT_RSA_PUBLIC_KEY_DER, False)))
validator = Validator(ValidationPolicyFromPib(keyChain.getPib()))
# Make a Face just so that we can sign the interest.
face = Face("localhost")
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
face.makeCommandInterest(freshInterest)
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
dump("")
dump("Re-decoded fresh Interest:")
dumpInterest(reDecodedFreshInterest)
validator.validate(
reDecodedFreshInterest, makeSuccessCallback("Freshly-signed Interest"),
makeFailureCallback("Freshly-signed Interest"))
示例10: test_max_ndn_packet_size
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def test_max_ndn_packet_size(self):
# Construct an interest whose encoding is one byte larger than getMaxNdnPacketSize.
targetSize = Face.getMaxNdnPacketSize() + 1
# Start with an interest which is almost the right size.
interest = Interest()
interest.getName().append(bytearray(targetSize))
initialSize = interest.wireEncode().size()
# Now replace the component with the desired size which trims off the extra encoding.
interest.setName(
(Name().append(bytearray(targetSize - (initialSize - targetSize)))))
interestSize = interest.wireEncode().size()
self.assertEqual(targetSize, interestSize,
"Wrong interest size for MaxNdnPacketSize")
with self.assertRaises(RuntimeError):
# If no error is raised, then expressInterest didn't throw an
# exception when the interest size exceeds getMaxNdnPacketSize()
self.face.expressInterest(interest, Mock(), Mock())
示例11: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def main():
prefix = Name("/nfd/edu/ucla/remap/test")
# Route to aleph.ndn.ucla.edu. Have to use the canonical name with an IP
# address and port.
uri = "udp4://128.97.98.7:6363"
# The default Face connects to the local NFD.
face = Face()
# Use the system default key chain and certificate name to sign commands.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Create the /localhost/nfd/faces/query command interest, including the
# FaceQueryFilter. Construct the FaceQueryFilter using the structure in
# face_query_filter_pb2 which was produced by protoc.
message = face_query_filter_pb2.FaceQueryFilterMessage()
filter = message.face_query_filter.add()
filter.uri = uri
encodedFilter = ProtobufTlv.encode(message)
interest = Interest(Name("/localhost/nfd/faces/query"))
interest.getName().append(encodedFilter)
enabled = [True]
def onComplete(content):
processFaceStatus(content, prefix, uri, face, enabled)
def onError(errorCode, message):
enabled[0] = False
dump(message)
SegmentFetcher.fetch(
face, interest, SegmentFetcher.DontVerifySegment, onComplete, onError)
# Loop calling processEvents until a callback sets enabled[0] = False.
while enabled[0]:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(0.01)
示例12: _sendCertificateRequest
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def _sendCertificateRequest(self, keyIdentity):
"""
We compose a command interest with our public key info so the controller
can sign us a certificate that can be used with other nodes in the network.
"""
#TODO: GENERATE A NEW PUBLIC/PRIVATE PAIR INSTEAD OF COPYING
makeKey = False
try:
defaultKey = self._identityStorage.getDefaultKeyNameForIdentity(keyIdentity)
newKeyName = defaultKey
except SecurityException:
defaultIdentity = self._keyChain.getDefaultIdentity()
defaultKey = self._identityStorage.getDefaultKeyNameForIdentity(defaultIdentity)
newKeyName = self._identityStorage.getNewKeyName(keyIdentity, True)
makeKey = True
self.log.debug("Found key: " + defaultKey.toUri()+ " renaming as: " + newKeyName.toUri())
keyType = self._identityStorage.getKeyType(defaultKey)
keyDer = self._identityStorage.getKey(defaultKey)
if makeKey:
try:
privateDer = self._identityManager.getPrivateKey(defaultKey)
except SecurityException:
# XXX: is recovery impossible?
pass
else:
try:
self._identityStorage.addKey(newKeyName, keyType, keyDer)
self._identityManager.addPublicKey(newKeyName, keyDer)
self._identityManager.addPrivateKey(newKeyName, privateDer)
except SecurityException:
# TODO: key shouldn't exist...
pass
message = CertificateRequestMessage()
message.command.keyType = keyType
message.command.keyBits = keyDer.toRawStr()
for component in range(newKeyName.size()):
message.command.keyName.components.append(newKeyName.get(component).toEscapedString())
paramComponent = ProtobufTlv.encode(message)
interestName = Name(self._policyManager.getTrustRootIdentity()).append("certificateRequest").append(paramComponent)
interest = Interest(interestName)
interest.setInterestLifetimeMilliseconds(10000) # takes a tick to verify and sign
self._hmacHandler.signInterest(interest, keyName=self.prefix)
self.log.info("Sending certificate request to controller")
self.log.debug("Certificate request: "+interest.getName().toUri())
self.face.expressInterest(interest, self._onCertificateReceived, self._onCertificateTimeout)
示例13: onSyncTimeout
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [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
示例14: registerRoute
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [as 别名]
def registerRoute(prefix, faceId, face, enabled):
"""
Use /localhost/nfd/rib/register to register the prefix to the faceId.
:param Name prefix: The prefix name to register.
:param int faceId: The face ID.
:param Face face: The Face which is used to sign the command interest and
call expressInterest.
:param enabled: On success or error, set enabled[0] = False.
:type enabled: An array with one bool element
"""
# Use default values
origin = 255
cost = 0
CHILD_INHERIT = 1
flags = CHILD_INHERIT
message = control_parameters_pb2.ControlParametersTypes.ControlParametersMessage()
for i in range(prefix.size()):
message.control_parameters.name.component.append(prefix[i].getValue().toBytes())
message.control_parameters.face_id = faceId
message.control_parameters.origin = origin
message.control_parameters.cost = cost
message.control_parameters.flags = flags
encodedControlParameters = ProtobufTlv.encode(message)
interest = Interest(Name("/localhost/nfd/rib/register"))
interest.getName().append(encodedControlParameters)
interest.setInterestLifetimeMilliseconds(10000)
# Sign and express the interest.
face.makeCommandInterest(interest)
def onData(localInterest, data):
enabled[0] = False
processRegisterResponse(data.getContent())
def onTimeout(localInterest):
enabled[0] = False
dump("Register route command timed out.")
face.expressInterest(interest, onData, onTimeout)
示例15: start
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import getName [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