Example #1
0
def main():
    # The default Face will connect using a Unix socket, or to "localhost".
    face = Face()

    groupName = Name("/Prefix/READ")
    userName = Name("/U")
    userKeyName = Name("/U/Key")
    contentPrefix = Name("/Prefix/SAMPLE")
    contentName = Name(contentPrefix).append("Content")

    keyChain = createVerifyKeyChain()

    # Imitate test_consumer from the PyNDN integration tests.
    databaseFilePath = "test.db"
    try:
        os.remove(databaseFilePath)
    except OSError:
        pass

    namespace = Namespace(contentName)
    namespace.setFace(face)
    handler = NacConsumerHandler(
      namespace, keyChain, groupName, userName, Sqlite3ConsumerDb(databaseFilePath))
    fixtureUserDKeyBlob = Blob(FIXTURE_USER_D_KEY)
    handler.addDecryptionKey(userKeyName, fixtureUserDKeyBlob)

    enabled = [True]
    def onContentSet(namespace, contentNamespace, callbackId):
        if contentNamespace == namespace:
            dump("Got segmented content", contentNamespace.content.toRawStr())
            enabled[0] = False
    namespace.addOnContentSet(onContentSet)

    segmentStream = SegmentStream(namespace)
    SegmentedContent(segmentStream)
    segmentStream.start()

    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)
Example #2
0
def main():
    face = Face("memoria.ndn.ucla.edu")
    page = Namespace("/ndn/edu/ucla/remap/demo/ndn-js-test/named-data.net/project/ndn-ar2011.html/%FDT%F7n%9E")
    page.setFace(face)

    enabled = [True]
    def onContentSet(namespace, contentNamespace, callbackId):
        if contentNamespace == namespace:
            dump("Got segmented content size", contentNamespace.content.size())
            enabled[0] = False
    page.addOnContentSet(onContentSet)

    segmentStream = SegmentStream(page)
    SegmentedContent(segmentStream)
    segmentStream.start()

    # 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)