本文整理汇总了Python中pyndn.Data.getMetaInfo方法的典型用法代码示例。如果您正苦于以下问题:Python Data.getMetaInfo方法的具体用法?Python Data.getMetaInfo怎么用?Python Data.getMetaInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Data
的用法示例。
在下文中一共展示了Data.getMetaInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generateData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def generateData(baseName):
'''
This appends the segment number to the data name
'''
# just make up some data and return it
ts = (time.time())
segmentId = 0 # compatible with repo-ng test: may change to test segmented data
versionComponent = baseName.get(-1) # should have a ts
dataName = Name(baseName)
dataName.appendSegment(segmentId)
d = Data(dataName)
content = "(" + str(ts) + ") Data named " + dataName.toUri()
d.setContent(content)
d.getMetaInfo().setFinalBlockID(segmentId)
d.getMetaInfo().setFreshnessPeriod(-1)
if shouldSign:
keychain.sign(d, certName)
else:
d.setSignature(fakeSignature)
if shouldCollectStats:
info = getInfoForVersion(versionComponent.toEscapedString())
if info is not None:
info['publish_time'] = ts
return d
示例2: publishData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def publishData(self):
timestamp = time.time()
info = {''}
if self._pir == None:
cpu_use = ps.cpu_percent()
users = [u.name for u in ps.users()]
nProcesses = len(ps.pids())
memUse = ps.virtual_memory().percent
swapUse = ps.swap_memory().percent
info = {'count': self._count, 'cpu_usage':cpu_use, 'users':users, 'processes':nProcesses,
'memory_usage':memUse, 'swap_usage':swapUse}
else:
info = {'count': self._count, 'pir_bool': self._pir.read()}
self._count += 1
dataOut = Data(Name(self._dataPrefix).appendVersion(int(timestamp)))
dataOut.setContent(json.dumps(info))
dataOut.getMetaInfo().setFreshnessPeriod(10000)
self.signData(dataOut)
#self._dataCache.add(dataOut)
# instead of adding data to content cache, we put data to nfd anyway
self.send(dataOut.wireEncode().buf())
print('data name: ' + dataOut.getName().toUri() + '; content: ' + str(info))
# repeat every 1 seconds
self.loop.call_later(1, self.publishData)
示例3: onPublishInterest
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def onPublishInterest(self, prefix, interest, transport, pxID):
'''
For publishing face
'''
# just make up some data and return it
interestName = interest.getName()
logger.info("Interest for " + interestName.toUri())
## CURRENTLY ASSUMES THERE'S A VERSION+SEGMENT SUFFIX!
dataName = Name(interestName)
ts = (time.time())
segmentId = 0
#try:
# segmentId = interestName.get(-1).toSegment()
#except:
#logger.debug("Could not find segment id!")
#dataName.appendSegment(segmentId)
versionStr = str(interestName.get(-2).getValue())
logger.debug('Publishing ' + versionStr + ' @ ' + str(ts))
d = Data(dataName)
content = "(" + str(ts) + ") Data named " + dataName.toUri()
d.setContent(content)
d.getMetaInfo().setFinalBlockID(segmentId)
d.getMetaInfo().setFreshnessPeriod(1000)
self.keychain.sign(d, self.certificateName)
encodedData = d.wireEncode()
stats.insertDataForVersion(versionStr, {'publish_time': time.time()})
transport.send(encodedData.toBuffer())
示例4: generateData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def generateData(self, baseName):
'''
This appends the segment number to the data name, since repo-ng tends to expect it
'''
# just make up some data and return it
ts = (time.time())
segmentId = 0 # compatible with repo-ng test: may change to test segmented data
versionStr = baseName.get(-1).toEscapedString()
dataName = Name(baseName)
dataName.appendSegment(segmentId)
d = Data(dataName)
content = "(" + str(ts) + ") Data named " + dataName.toUri()
d.setContent(content)
d.getMetaInfo().setFinalBlockID(segmentId)
d.getMetaInfo().setFreshnessPeriod(-1)
if shouldSign:
self.keychain.sign(d, self.certificateName)
else:
d.setSignature(self.fakeSignature)
stats.insertDataForVersion(versionStr, {'publish_time':time.time()})
logger.debug('Publishing: '+d.getName().toUri())
return d
示例5: onDataInterest
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def onDataInterest(prefix, interest, transport, pxID):
'''
For publishing face
'''
# just make up some data and return it
interestName = interest.getName()
logger.info("Interest for " + interestName.toUri())
## CURRENTLY ASSUMES THERE'S A VERSION/SEGMENT SUFFIX!
dataName = Name(interestName.getPrefix(-1))
ts = (time.time())
segmentId = 0
try:
segmentId = interestName().get(-1).toSegment()
except:
logger.debug("Could not find segment id!")
dataName.appendSegment(segmentId)
versionStr = interestName.get(-2).getValue().toRawStr()
logger.debug('publishing ' + versionStr)
info = getInfoForVersion(versionStr)
d = Data(dataName)
content = "(" + str(ts) + ") Data named " + dataName.toUri()
d.setContent(content)
d.getMetaInfo().setFinalBlockID(segmentId)
keychain.sign(d, certName)
encodedData = d.wireEncode()
now = time.time()
if info is not None:
info['publish_time'] = now
transport.send(encodedData.toBuffer())
示例6: wrap_content
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def wrap_content(self, name, content, key=None, key_locator=None):
"""
@param name - name of the data
@param content - data to be wrapped
@param key - key used to sign the data
@return the content object created
wraps the given name and content into a content object
"""
co = Data(Name(name))
co.setContent(content)
co.getMetaInfo().setFreshnessPeriod(5000)
co.getMetaInfo().setFinalBlockID(Name("/%00%09")[0])
identityStorage = MemoryIdentityStorage()
privateKeyStorage = MemoryPrivateKeyStorage()
identityManager = IdentityManager(identityStorage, privateKeyStorage)
keyChain = KeyChain(identityManager, None)
# Initialize the storage.
keyName = Name("/ndn/bms/DSK-default")
certificateName = keyName.getSubName(0, keyName.size() - 1).append(
"KEY").append(keyName[-1]).append("ID-CERT").append("0")
identityStorage.addKey(keyName, KeyType.RSA, Blob(DEFAULT_PUBLIC_KEY_DER))
privateKeyStorage.setKeyPairForKeyName(keyName, DEFAULT_PUBLIC_KEY_DER,
DEFAULT_PRIVATE_KEY_DER)
keyChain.sign(co, certificateName)
_data = co.wireEncode()
return _data.toRawStr()
示例7: test_malformed_certificate
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def test_malformed_certificate(self):
# Copy the default certificate.
malformedCertificate = Data(
self._fixture._subIdentity.getDefaultKey().getDefaultCertificate())
malformedCertificate.getMetaInfo().setType(ContentType.BLOB)
self._fixture._keyChain.sign(
malformedCertificate, SigningInfo(self._fixture._identity))
# It has the wrong content type and a missing ValidityPeriod.
try:
CertificateV2(malformedCertificate).wireEncode()
self.fail("Did not throw the expected exception")
except CertificateV2.Error:
pass
else:
self.fail("Did not throw the expected exception")
originalProcessInterest = self._fixture._face._processInterest
def processInterest(interest, onData, onTimeout, onNetworkNack):
if interest.getName().isPrefixOf(malformedCertificate.getName()):
onData(interest, malformedCertificate)
else:
originalProcessInterest.processInterest(
interest, onData, onTimeout, onNetworkNack)
self._fixture._face._processInterest = processInterest
data = Data(Name("/Security/V2/ValidatorFixture/Sub1/Sub2/Data"))
self._fixture._keyChain.sign(data, SigningInfo(self._fixture._subIdentity))
self.validateExpectFailure(data, "Signed by a malformed certificate")
self.assertEqual(1, len(self._fixture._face._sentInterests))
示例8: onLightingCommand
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def onLightingCommand(self, prefix, interest, transport, prefixId):
interestName = Name(interest.getName())
#d = Data(interest.getName().getPrefix(prefix.size()+1))
d = Data(interest.getName())
# get the command parameters from the name
try:
commandComponent = interest.getName().get(prefix.size())
commandParams = interest.getName().get(prefix.size()+1)
lightingCommand = LightCommandMessage()
ProtobufTlv.decode(lightingCommand, commandParams.getValue())
self.log.info("Command: " + commandComponent.toEscapedString())
requestedColor = lightingCommand.command.pattern.colors[0]
colorStr = str((requestedColor.r, requestedColor.g, requestedColor.b))
self.log.info("Requested color: " + colorStr)
self.setPayloadColor(0, requestedColor)
self.sendLightPayload(1)
d.setContent("Gotcha: " + colorStr+ "\n")
except Exception as e:
print e
d.setContent("Bad command\n")
finally:
d.getMetaInfo().setFinalBlockID(0)
self.signData(d)
encodedData = d.wireEncode()
transport.send(encodedData.toBuffer())
示例9: __init__
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def __init__(self, prefix, maxCount=1):
self.keyChain = KeyChain()
self.prefix = Name(prefix)
self.isDone = False
# Initialize list for Data packet storage.
# We'll treat the indices as equivalent to the sequence
# number requested by Interests.
self.data = []
finalBlock = Name.Component.fromNumberWithMarker(maxCount - 1, 0x00)
hourMilliseconds = 3600 * 1000
# Pre-generate and sign all of Data we can serve.
# We can also set the FinalBlockID in each packet
# ahead of time because we know the entire sequence.
for i in range(maxCount):
dataName = Name(prefix).appendSegment(i)
data = Data(dataName)
data.setContent("Hello, " + dataName.toUri())
data.getMetaInfo().setFinalBlockID(finalBlock)
data.getMetaInfo().setFreshnessPeriod(hourMilliseconds)
self.keyChain.sign(data, self.keyChain.getDefaultCertificateName())
self.data.append(data)
示例10: createFreshData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def createFreshData(self):
freshData = Data(Name("/ndn/abc"))
freshData.setContent("SUCCESS!")
freshData.getMetaInfo().setFreshnessPeriod(5000.0)
freshData.getMetaInfo().setFinalBlockID(Name("/%00%09")[0])
# Initialize the storage.
return freshData
示例11: publishData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def publishData(self, key, key_ts, payload, timestamp):
data = Data(Name(self.prefix).append(bytearray(timestamp)))
iv = Random.new().read(AES.block_size)
encryptor = AES.new(key, AES.MODE_CBC, iv)
data.setContent(bytearray(key_ts + iv + encryptor.encrypt(pad(json.dumps(payload)))))
data.getMetaInfo().setFreshnessPeriod(5000)
self.keychain.sign(data, self.cert_name)
self.publisher.put(data)
示例12: createData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def createData(self, namePrefix, timestamp, payload, certName):
data = Data(Name(self._namespace).append(namePrefix).append(str(int(float(timestamp)))))
data.setContent(payload)
self._keyChain.sign(data, certName)
data.getMetaInfo().setFreshnessPeriod(self.DEFAULT_DATA_LIFETIME)
if __debug__:
print(data.getName().toUri())
return data
示例13: sendData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def sendData(self, prefix, interest, face, registeredPrefixId, content): #onInterest
#transport.send(encodedData.toBuffer())
#print(prefix)
# Publish segments
dataSize = len(content)
print("Dat size: ",dataSize)
segmentBegin = 0
segmentNo = 0
print "Start"
while segmentBegin < dataSize:
segmentEnd = segmentBegin + 2000 #Common.MAX_NDN_PACKET_SIZE
if segmentEnd > dataSize:
segmentEnd = dataSize
# Make and sign a Data packet.
print("Prefix: ")
print(prefix)
if not "%" in str(prefix)[-7:]:
segmentName = prefix
#print("NO % in name: ", segmentName)
segmentName.appendSegment(segmentNo)
else:
segmentName = str(prefix)[:-1]
#print("% in name: ",segmentName)
segmentName += str(segmentNo)
segmentName = Name(segmentName)
print("Segment Name: ")
print(segmentName)
print("Segment Name appended: ", segmentName)
print "Segmenting data from %d to %d" % (segmentBegin, segmentEnd)
print("COntent: ")
print(content[segmentBegin:segmentEnd])
data = Data(segmentName)
data.setContent(content[segmentBegin:segmentEnd])
data.getMetaInfo().setFreshnessPeriod(2000)
self._keyChain.sign(data, self._certificateName)
if segmentEnd >= dataSize:
print("yes")
data.getMetaInfo().setFinalBlockId(segmentName[-1])
#encodedData = data.wireEncode()
segmentBegin = segmentEnd
print "Sending data " + segmentName.toUri()
#transport.send(encodedData.toBuffer())
face.putData(data)
segmentNo += 1
time.sleep(0.5)
print "Finish"
示例14: contentCacheAddEntityData
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def contentCacheAddEntityData(self, name, entityInfo):
content = self._serializer.serialize(entityInfo)
data = Data(Name(name))
data.setContent(content)
data.getMetaInfo().setFreshnessPeriod(self._entityDataFreshnessPeriod)
self._keyChain.sign(data, self._certificateName)
self._memoryContentCache.add(data)
print "added entity to cache: " + data.getName().toUri() + "; " + data.getContent().toRawStr()
示例15: onEntityDataNotFound
# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import getMetaInfo [as 别名]
def onEntityDataNotFound(self, prefix, interest, face, interestFilterId, filter):
name = interest.getName().toUri()
if name in self._hostedObjects:
content = self._serializer.serialize(self._hostedObjects[name])
data = Data(Name(name))
data.setContent(content)
data.getMetaInfo().setFreshnessPeriod(self._entityDataFreshnessPeriod)
self._keyChain.sign(data, self._certificateName)
self._face.putData(data)
return