本文整理汇总了Python中pyndn.Name.append方法的典型用法代码示例。如果您正苦于以下问题:Python Name.append方法的具体用法?Python Name.append怎么用?Python Name.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Name
的用法示例。
在下文中一共展示了Name.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addCertificate
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def addCertificate(self, key, issuerId):
"""
Add a self-signed certificate made from the key and issuer ID.
:param PibKey key: The key for the certificate.
:param str issuerId: The issuer ID name component for the certificate
name.
:return: The new certificate.
:rtype: CertificateV2
"""
certificateName = Name(key.getName())
certificateName.append(issuerId).appendVersion(3)
certificate = CertificateV2()
certificate.setName(certificateName)
# Set the MetaInfo.
certificate.getMetaInfo().setType(ContentType.KEY)
# One hour.
certificate.getMetaInfo().setFreshnessPeriod(3600 * 1000.0)
# Set the content.
certificate.setContent(key.getPublicKey())
params = SigningInfo(key)
# Validity period of 10 days.
now = Common.getNowMilliseconds()
params.setValidityPeriod(
ValidityPeriod(now, now + 10 * 24 * 3600 * 1000.0))
self._keyChain.sign(certificate, params)
return certificate
示例2: _updateCapabilities
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def _updateCapabilities(self):
"""
Send the controller a list of our commands.
"""
fullCommandName = Name(self._policyManager.getTrustRootIdentity()
).append('updateCapabilities')
capabilitiesMessage = UpdateCapabilitiesCommandMessage()
for command in self._commands:
commandName = Name(self.prefix).append(Name(command.suffix))
capability = capabilitiesMessage.capabilities.add()
for i in range(commandName.size()):
capability.commandPrefix.components.append(
str(commandName.get(i).getValue()))
for kw in command.keywords:
capability.keywords.append(kw)
capability.needsSignature = command.isSigned
encodedCapabilities = ProtobufTlv.encode(capabilitiesMessage)
fullCommandName.append(encodedCapabilities)
interest = Interest(fullCommandName)
interest.setInterestLifetimeMilliseconds(5000)
self.face.makeCommandInterest(interest)
signature = self._policyManager._extractSignature(interest)
self.log.info("Sending capabilities to controller")
self.face.expressInterest(interest, self._onCapabilitiesAck, self._onCapabilitiesTimeout)
# update twice a minute
self.loop.call_later(30, self._updateCapabilities)
示例3: processInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def processInterest(interest, onData, onTimeout, onNetworkNack):
try:
# Create another key for the same identity and sign it properly.
parentKey = self._fixture._keyChain.createKey(
self._fixture._subIdentity)
requestedKey = self._fixture._subIdentity.getKey(interest.getName())
# Copy the Name.
certificateName = Name(requestedKey.getName())
certificateName.append("looper").appendVersion(1)
certificate = CertificateV2()
certificate.setName(certificateName)
# Set the MetaInfo.
certificate.getMetaInfo().setType(ContentType.KEY)
# Set the freshness period to one hour.
certificate.getMetaInfo().setFreshnessPeriod(3600 * 1000.0)
# Set the content.
certificate.setContent(requestedKey.getPublicKey())
# Set SigningInfo.
params = SigningInfo(parentKey)
# Validity period from 10 days before to 10 days after now.
now = Common.getNowMilliseconds()
params.setValidityPeriod(ValidityPeriod(
now - 10 * 24 * 3600 * 1000.0, now + 10 * 24 * 3600 * 1000.0))
self._fixture._keyChain.sign(certificate, params)
onData(interest, certificate)
except Exception as ex:
self.fail("Error in InfiniteCertificateChain: " + repr(ex))
示例4: main
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def main():
# Silence the warning from Interest wire encode.
Interest.setDefaultCanBePrefix(True)
# The default Face will connect using a Unix socket, or to "localhost".
face = Face()
counter = Counter()
if sys.version_info[0] <= 2:
word = raw_input("Enter a word to echo: ")
else:
word = input("Enter a word to echo: ")
name = Name("/testecho")
name.append(word)
dump("Express name ", name.toUri())
face.expressInterest(name, counter.onData, counter.onTimeout)
while counter._callbackCount < 1:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(0.01)
face.shutdown()
示例5: handleExpressInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def handleExpressInterest(interest, onData, onTimeout):
expressInterestCallCount[0] += 1
interestName = Name(interest.getName())
interestName.append(timeMarker)
self.assertTrue(interestName in self.encryptionKeys)
onData(interest, self.encryptionKeys[interestName])
return 0
示例6: createEncryptionKey
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def createEncryptionKey(self, eKeyName, timeMarker):
params = RsaKeyParams()
eKeyName = Name(eKeyName)
eKeyName.append(timeMarker)
dKeyBlob = RsaAlgorithm.generateKey(params).getKeyBits()
eKeyBlob = RsaAlgorithm.deriveEncryptKey(dKeyBlob).getKeyBits()
self.decryptionKeys[eKeyName] = dKeyBlob
keyData = Data(eKeyName)
keyData.setContent(eKeyBlob)
self.keyChain.sign(keyData, self.certificateName)
self.encryptionKeys[eKeyName] = keyData
示例7: test_typed_name_component
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def test_typed_name_component(self):
otherTypeCode = 99
uri = "/ndn/" + str(otherTypeCode) + "=value"
name = Name()
name.append("ndn").append("value", ComponentType.OTHER_CODE, otherTypeCode)
self.assertEqual(uri, name.toUri())
nameFromUri = Name(uri)
self.assertEqual("value", str(nameFromUri.get(1).getValue()))
self.assertEqual(otherTypeCode, nameFromUri.get(1).getOtherTypeCode())
decodedName = Name()
decodedName.wireDecode(name.wireEncode())
self.assertEqual("value", str(decodedName.get(1).getValue()))
self.assertEqual(otherTypeCode, decodedName.get(1).getOtherTypeCode())
示例8: test_published_kdks
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def test_published_kdks(self):
for user in self._fixture._userIdentities:
kdkName = Name("/access/policy/identity/NAC/dataset/KDK")
kdkName.append(
self._fixture._nacIdentity.getDefaultKey().getName().get(-1)).append(
"ENCRYPTED-BY").append(
user.getDefaultKey().getName())
self._fixture._face.receive(
Interest(kdkName).setCanBePrefix(True).setMustBeFresh(True))
self.assertTrue(
self._fixture._face._sentData[0].getName().equals(kdkName),
"Sent Data does not have the KDK name " + kdkName.toUri())
self._fixture._face._sentData = []
示例9: sendRepoInsertCommand
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def sendRepoInsertCommand(self, dataName):
self.log.debug('Sending insert command for {}'.format(dataName))
commandMessage = RepoCommandParameterMessage()
command = commandMessage.command
for component in dataName:
command.name.components.append(str(component.getValue()))
command.start_block_id = command.end_block_id = 0
commandComponent = ProtobufTlv.encode(commandMessage)
interestName = Name(self.repoPrefix).append('insert')
interestName.append(commandComponent)
interest = Interest(interestName)
interest.setInterestLifetimeMilliseconds(4000)
self.face.makeCommandInterest(interest)
self.face.expressInterest(interest, self.onDataReceived, self.onTimeout)
示例10: expressBootstrapInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def expressBootstrapInterest(self):
#generate bootstrap name /home/controller/bootstrap/<device-parameters>
bootstrapName = Name(self._bootstrapPrefix)
deviceParameters = {}
deviceParameters["category"] = self._deviceProfile.getCategory()
deviceParameters["serialNumber"] = self. _deviceProfile.getSerialNumber()
deviceParameters["type"] = self._deviceProfile.getType()
bootstrapName.append(json.dumps(deviceParameters))
bootstrapInterest = Interest(bootstrapName)
bootstrapInterest.setInterestLifetimeMilliseconds(3000)
self._accessControlManager.signInterestWithHMACKey(bootstrapInterest,self._bootstrapKey)
dump("Express bootstrap interest : ",bootstrapInterest.toUri())
self.face.expressInterest(bootstrapInterest, self.onBootstrapData, self.onBootstrapTimeout)
示例11: test_operate_rsa_decryption_key
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def test_operate_rsa_decryption_key(self):
# Test construction.
database = Sqlite3ConsumerDb(self.databaseFilePath)
# Generate key blobs.
(encryptionKeyBlob, decryptionKeyBlob) = generateRsaKeys()
keyName = Name(
"/alice/health/samples/activity/steps/D-KEY/20150928080000/20150928090000!")
keyName.append(Name("FOR/test/member/KEY/123!"))
database.addKey(keyName, decryptionKeyBlob)
resultBlob = database.getKey(keyName)
self.assertTrue(decryptionKeyBlob.equals(resultBlob))
database.deleteKey(keyName)
resultBlob = database.getKey(keyName)
self.assertEqual(0, resultBlob.size())
示例12: handleCommandInterests
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def handleCommandInterests(self, prefix, interest, transport, prefixId):
# TODO: verification
interestName = interest.getName()
if len(interestName) <= len(prefix)+4:
self.log.info("Bad command interest")
commandName = str(interestName[len(prefix)].getValue())
responseMessage = RepoCommandResponseMessage()
if commandName == 'insert':
commandParams = interestName[len(prefix)+1].getValue()
commandMessage = RepoCommandParameterMessage()
ProtobufTlv.decode(commandMessage, commandParams)
dataName = Name()
fullSchemaName = Name()
for component in commandMessage.command.name.components:
fullSchemaName.append(component)
if component == '_':
continue
dataName.append(component)
self.log.info("Insert request for {}".format(dataName))
responseMessage.response.status_code = 100
processId = self.currentProcessId
self.currentProcessId += 1
responseMessage.response.process_id = processId
else:
responseMessage.response.status_code = 403
responseData = Data(interestName)
responseData.setContent(ProtobufTlv.encode(responseMessage))
transport.send(responseData.wireEncode().buf())
# now send the interest out to the publisher
# TODO: pendingProcesses becomes list of all processes as objects
i = Interest(dataName)
i.setChildSelector(1)
i.setInterestLifetimeMilliseconds(4000)
try:
self.pendingProcesses[processId] = (dataName, 100)
except NameError:
pass # wasn't valid insert request
else:
self._insertFace.expressInterest(i,
self._onInsertionDataReceived,
self._onInsertionDataTimeout)
示例13: _addDeviceToNetwork
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def _addDeviceToNetwork(self, deviceSerial, newDeviceSuffix, pin):
h = HmacHelper(pin)
self._hmacDevices[deviceSerial] = h
d = DeviceConfigurationMessage()
for source, dest in [(self.networkPrefix, d.configuration.networkPrefix),
(self.deviceSuffix, d.configuration.controllerName),
(newDeviceSuffix, d.configuration.deviceSuffix)]:
for i in range(source.size()):
component = source.get(i)
dest.components.append(component.getValue().toRawStr())
interestName = Name('/localhop/configure').append(Name(deviceSerial))
encodedParams = ProtobufTlv.encode(d)
interestName.append(encodedParams)
interest = Interest(interestName)
h.signInterest(interest)
self.face.expressInterest(interest, self._deviceAdditionResponse,
self._deviceAdditionTimedOut)
示例14: test_content_key_timeout
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def test_content_key_timeout(self):
prefix = Name("/prefix")
suffix = Name("/suffix")
expectedInterest = Name(prefix)
expectedInterest.append(Encryptor.NAME_COMPONENT_READ)
expectedInterest.append(suffix)
expectedInterest.append(Encryptor.NAME_COMPONENT_E_KEY)
testTime = Schedule.fromIsoString("20150101T100001")
timeoutCount = [0]
# Prepare a TestFace to instantly answer calls to expressInterest.
class TestFace(object):
def __init__(self, handleExpressInterest):
self.handleExpressInterest = handleExpressInterest
def expressInterest(self, interest, onData, onTimeout):
return self.handleExpressInterest(interest, onData, onTimeout)
def handleExpressInterest(interest, onData, onTimeout):
self.assertEqual(expectedInterest, interest.getName())
timeoutCount[0] += 1
onTimeout(interest)
return 0
face = TestFace(handleExpressInterest)
# Verify that if no response is received, the producer appropriately times
# out. The result vector should not contain elements that have timed out.
testDb = Sqlite3ProducerDb(self.databaseFilePath)
producer = Producer(prefix, suffix, face, self.keyChain, testDb)
def onEncryptedKeys(result):
self.assertEqual(4, timeoutCount[0])
self.assertEqual(0, len(result))
producer.createContentKey(testTime, onEncryptedKeys)
示例15: createCheckInterest
# 需要导入模块: from pyndn import Name [as 别名]
# 或者: from pyndn.Name import append [as 别名]
def createCheckInterest(fullName, checkNum):
insertionName = Name("/repotest/repo/insert check")
commandParams = RepoCommandParameterMessage()
interestName = Name(fullName)
commandParams.repo_command_parameter.process_id = checkNum
for i in range(interestName.size()):
commandParams.repo_command_parameter.name.component.append(interestName.get(i).toEscapedString())
commandName = insertionName.append(ProtobufTlv.encode(commandParams))
interest = Interest(commandName)
return interest