本文整理汇总了Python中pyndn.Face.processEvents方法的典型用法代码示例。如果您正苦于以下问题:Python Face.processEvents方法的具体用法?Python Face.processEvents怎么用?Python Face.processEvents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Face
的用法示例。
在下文中一共展示了Face.processEvents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
# The default Face will connect using a Unix socket, or to "localhost".
face = Face()
identityStorage = MemoryIdentityStorage()
privateKeyStorage = MemoryPrivateKeyStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, privateKeyStorage), None)
keyChain.setFace(face)
# 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)
echo = Echo(keyChain, certificateName)
prefix = Name("/testecho")
dump("Register prefix", prefix.toUri())
face.registerPrefix(prefix, echo.onInterest, echo.onRegisterFailed)
while echo._responseCount < 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()
示例2: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
face = Face("localhost")
identityStorage = MemoryIdentityStorage()
privateKeyStorage = MemoryPrivateKeyStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, privateKeyStorage), None)
keyChain.setFace(face)
# Initialize the storage.
keyName = Name("/testname/DSK-reposerver")
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)
echo = RepoServer(keyChain, certificateName)
prefix = Name("/ndn/ucla.edu/bms")
dump("Register prefix", prefix.toUri())
face.registerPrefix(prefix, echo.onInterest, echo.onRegisterFailed)
while True:
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()
示例3: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
# The default Face will connect using a Unix socket, or to "localhost".
face = Face()
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
dataPrefix = "/home/test1/data"
repoDataPrefix = "/home/test1/data"
# Set up repo-ng, register prefix for repo-ng's fetch prefix
# Per configuration file in /usr/local/etc/ndn/repo-ng.conf
# memCache is not used for now; repo is hoping that the piece of data in question is still being held at nfd
#memCache = MemoryContentCache(face, 100000)
#memCache.registerPrefix(Name(repoDataPrefix), onRegisterFailed, onDataNotFound)
counter = Counter(face, repoDataPrefix)
interest = Interest(Name(dataPrefix))
interest.setChildSelector(1)
interest.setInterestLifetimeMilliseconds(defaultInterestLifetime)
face.expressInterest(interest, counter.onData, counter.onTimeout)
while True:
face.processEvents()
# We need to sleep for a few milliseconds so we don't use 100% of the CPU.
time.sleep(1)
face.shutdown()
示例4: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [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)
示例5: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [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)
示例6: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [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()
示例7: Consumer
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
class Consumer(object):
'''Hello World consumer'''
def __init__(self, prefix):
self.prefix = Name(prefix)
self.outstanding = dict()
self.isDone = False
self.face = Face("127.0.0.1")
def run(self):
try:
self._sendNextInterest(self.prefix)
while not self.isDone:
self.face.processEvents()
time.sleep(0.01)
except RuntimeError as e:
print "ERROR: %s" % e
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
def _onData(self, interest, data):
payload = data.getContent()
name = data.getName()
print "Received data: ", payload.toRawStr()
del self.outstanding[name.toUri()]
self.isDone = True
def _onTimeout(self, interest):
name = interest.getName()
uri = name.toUri()
print "TIMEOUT #%d: %s" % (self.outstanding[uri], uri)
self.outstanding[uri] += 1
if self.outstanding[uri] <= 3:
self._sendNextInterest(name)
else:
self.isDone = True
示例8: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
if len(sys.argv) < 2:
print("argv error: please input turnOn, turnOff or status")
exit(1)
else:
cmd = sys.argv[1]
loop = asyncio.get_event_loop()
#face = ThreadsafeFace(loop, "localhost")
face = Face("localhost")
# Counter will stop the ioService after callbacks for all expressInterest.
counter = Counter(loop, 3)
seed = HMACKey(0,0,"seed","seedName")
# Try to fetch anything.
name1 = Name("/home/sensor/LED/0/"+cmd+"/0/0")
commandTokenName = '/home/sensor/LED/0/'+cmd+'/token/0'
commandTokenKey = hmac.new(seed.getKey(), commandTokenName, sha256).digest()
accessTokenName = '/home/sensor/LED/0/'+cmd+'/token/0/user/Tom/token/0'
accessTokenKey = hmac.new(commandTokenKey, accessTokenName, sha256).digest()
accessToken = HMACKey(0,0,accessTokenKey,accessTokenName)
dump("seed.getKey() :",seed.getKey())
dump("commandTokenName :",commandTokenName)
dump("commandTokenKey :",base64.b64encode(commandTokenKey))
dump("accessTokenName :",accessTokenName)
dump("accessTokenKey :",base64.b64encode(accessTokenKey))
interest = Interest(name1)
interest.setInterestLifetimeMilliseconds(3000)
a = AccessControlManager()
a.signInterestWithHMACKey(interest,accessToken)
dump("Express name ", interest.toUri())
face.expressInterest(interest, counter.onData, counter.onTimeout)
"""
name2 = Name("/home/sensor/LED/T0829374723/turnOff")
dump("Express name ", name2.toUri())
face.expressInterest(name2, 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(2)
face.shutdown()
示例9: run
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def run(self):
face = Face()
# Use the system default key chain and certificate name to sign commands.
face.setCommandSigningInfo(self.keyChain, self.keyChain.getDefaultCertificateName())
# Also use the default certificate name to sign data packets.
face.registerPrefix(self.prefix, self.onInterest, self.onRegisterFailed)
print "Registering prefix %s" % self.prefix.toUri()
while not self.isDone:
face.processEvents()
time.sleep(0.01)
示例10: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
"""
Call requestInsert and register a prefix so that ProduceSegments will answer
interests from the repo to send the data packets. This assumes that repo-ng
is already running (e.g. `sudo ndn-repo-ng`).
"""
repoCommandPrefix = Name("/example/repo/1")
repoDataPrefix = Name("/example/data/1")
nowMilliseconds = int(time.time() * 1000.0)
fetchPrefix = Name(repoDataPrefix).append("testinsert").appendVersion(nowMilliseconds)
# The default Face will connect using a Unix socket, or to "localhost".
face = Face()
# Use the system default key chain and certificate name to sign commands.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Register the prefix and send the repo insert command at the same time.
startBlockId = 0
endBlockId = 1
enabled = [True]
def onFinished():
dump("All data was inserted.")
enabled[0] = False
produceSegments = ProduceSegments(
keyChain, keyChain.getDefaultCertificateName(), startBlockId, endBlockId,
onFinished)
dump("Register prefix", fetchPrefix.toUri())
def onRegisterFailed(prefix):
dump("Register failed for prefix", prefix.toUri())
enabled[0] = False
face.registerPrefix(
fetchPrefix, produceSegments.onInterest, onRegisterFailed)
def onInsertStarted():
dump("Insert started for", fetchPrefix.toUri())
def onFailed():
enabled[0] = False
requestInsert(
face, repoCommandPrefix, fetchPrefix, onInsertStarted, onFailed,
startBlockId, endBlockId)
# Run until all the data is sent.
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)
face.shutdown()
示例11: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
"""
Call startRepoWatch and register a prefix so that SendSegments will answer
interests from the repo to send data packets for the watched prefix. When
all the data is sent (or an error), call stopRepoWatch. This assumes that
repo-ng is already running (e.g. `sudo ndn-repo-ng`).
"""
repoCommandPrefix = Name("/example/repo/1")
repoDataPrefix = Name("/example/data/1")
nowMilliseconds = int(time.time() * 1000.0)
watchPrefix = Name(repoDataPrefix).append("testwatch").appendVersion(
nowMilliseconds)
# The default Face will connect using a Unix socket, or to "localhost".
face = Face()
# Use the system default key chain and certificate name to sign commands.
keyChain = KeyChain()
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
# Register the prefix and start the repo watch at the same time.
enabled = [True]
def onFinishedSending():
stopRepoWatchAndQuit(face, repoCommandPrefix, watchPrefix, enabled)
sendSegments = SendSegments(
keyChain, keyChain.getDefaultCertificateName(), onFinishedSending)
def onRegisterFailed(prefix):
dump("Register failed for prefix", prefix.toUri())
enabled[0] = False
dump("Register prefix", watchPrefix.toUri())
face.registerPrefix(watchPrefix, sendSegments.onInterest, onRegisterFailed)
def onRepoWatchStarted():
dump("Watch started for", watchPrefix.toUri())
def onStartFailed():
dump("startRepoWatch failed.")
stopRepoWatchAndQuit(face, repoCommandPrefix, watchPrefix, enabled)
startRepoWatch(
face, repoCommandPrefix, watchPrefix, onRepoWatchStarted, onStartFailed)
# Run until someone sets enabled[0] = False.
enabled[0] = True
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)
face.shutdown()
示例12: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
face = Face()
# Use the system default key chain and certificate name to sign commands.
keyChain = KeyChain()
certificateName = keyChain.getDefaultCertificateName()
face.setCommandSigningInfo(keyChain, certificateName)
test = DiscoveryTest(face, keyChain, certificateName)
test.start()
while True:
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()
示例13: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
seg = 0
if len(sys.argv) < 3:
print("argv error: please input capture or capture with #seg")
exit(1)
elif len(sys.argv) == 2:
cmd = sys.argv[1]
else:
cmd = sys.argv[1]
seg = sys.argv[2]
loop = asyncio.get_event_loop()
#face = ThreadsafeFace(loop, "localhost")
face = Face("localhost")
# Counter will stop the ioService after callbacks for all expressInterest.
counter = Counter(loop, 3)
seed = HMACKey(0,0,"seed","seedName")
# Try to fetch anything.
import time
r = time.time()
name1 = Name("/home/security/camera/0/"+cmd)
name1.appendTimestamp(int(r))
name1.appendSegment(int(seg))
interest = Interest(name1)
interest.setInterestLifetimeMilliseconds(3000)
dump("Express name ", interest.toUri())
face.expressInterest(interest, counter.onData, counter.onTimeout)
"""
name2 = Name("/home/sensor/LED/T0829374723/turnOff")
dump("Express name ", name2.toUri())
face.expressInterest(name2, 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(2)
face.shutdown()
示例14: run
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def run(self, namespace):
# The default Face will connect using a Unix socket
face = Face()
prefix = Name(namespace)
# Use the system default key chain and certificate name to sign commands.
face.setCommandSigningInfo(self.keyChain, self.keyChain.getDefaultCertificateName())
# Also use the default certificate name to sign data packets.
face.registerPrefix(prefix, self.onInterest, self.onRegisterFailed)
print "Registering prefix", prefix.toUri()
while True:
face.processEvents()
time.sleep(0.01)
示例15: main
# 需要导入模块: from pyndn import Face [as 别名]
# 或者: from pyndn.Face import processEvents [as 别名]
def main():
face = Face("localhost")
counter = Counter()
ignored, name = argv
name = "/ndn/ucla.edu/bms/" + name
name1 = Name(name)
dump("Express name ", name1.toUri())
face.expressInterest(name1, 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()