Exemplo n.º 1
0
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()

    prefix = Namespace("/ndn/test/status")
    prefix.setFace(face)

    enabled = [True]

    # This is called to print the content after it is re-assembled from segments.
    def onGeneralizedObject(contentMetaInfo, objectNamespace):
        dump("Got generalized object", objectNamespace.name, ", content-type",
             contentMetaInfo.contentType, ":", str(objectNamespace.obj))
        enabled[0] = False

    handler = GeneralizedObjectHandler(prefix, onGeneralizedObject)
    # Allow one component after the prefix for the <version>.
    handler.setNComponentsAfterObjectNamespace(1)
    # In objectNeeded, set mustBeFresh == true so we avoid expired cached data.
    prefix.objectNeeded(True)

    # 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)
def main():
    # 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.
    keyChain = KeyChain()
    face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())

    objectPrefix = Namespace("/ndn/eb/run/28/description", keyChain)

    dump("Register prefix", objectPrefix.name)
    # Set the face and register to receive Interests.
    objectPrefix.setFace(
        face,
        lambda prefixName: dump("Register failed for prefix", prefixName))

    dump("Preparing data for", objectPrefix.name)
    GeneralizedObjectHandler().setObject(objectPrefix,
                                         Blob("EB run #28. Ham and oats"),
                                         "text/html")

    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)
Exemplo n.º 3
0
def main():
    # The default Face will connect using a Unix socket, or to "localhost".
    face = Face()

    prefix = Name("/icear-server/result/example-data/2/deeplab")
    prefixNamespace = Namespace(prefix)
    prefixNamespace.setFace(face)

    enabled = [True]
    img = [None]

    def onGeneralizedObject(contentMetaInfo, obj):
        data = obj.toBytes()
        dump("Got generalized object, content-type",
             contentMetaInfo.getContentType(), ":", repr(data))
        print(len(data))
        enabled[0] = False
        img[0] = data

    goh = GeneralizedObjectHandler(onGeneralizedObject)
    prefixNamespace.setHandler(goh).objectNeeded()

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

    image = Image.open(io.BytesIO(img[0]))
    image.show()
Exemplo n.º 4
0
def main(args):
    face = Face()

    prefix = Namespace(args['<prefix>'])
    prefix.setFace(face)

    enabled = [True]

    # This is called to print the content after it is re-assembled from segments.
    def onGeneralizedObject(contentMetaInfo, objectNamespace):
        if args['--verbose']:
            print(objectNamespace.getName())
        print(str(objectNamespace.obj))
        enabled[0] = False

    handler = GeneralizedObjectHandler(onGeneralizedObject)
    handler.setNComponentsAfterObjectNamespace(1)
    prefix.setHandler(handler).objectNeeded(True)

    # 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)
Exemplo n.º 5
0
    def fetch_data(self, prefix, start_frame, end_frame):
        # type: (Name, int, int) -> None
        for frame_id in range(start_frame, end_frame + 1):
            name = Name(prefix).append(str(frame_id))

            # Feed server with existing data
            if self.storage.exists(name):
                self.on_payload(name)

            # Fetching new data
            logging.info("Fetching: %s", name.toUri())
            # TODO: Namespace will put everything into memory
            frame_namespace = Namespace(name)
            frame_namespace.setFace(self.face)
            frame_namespace.setHandler(
                GeneralizedObjectHandler(partial(self.on_generalized_obj,
                                                 name))).objectNeeded()
Exemplo n.º 6
0
def main():
    # 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.
    keyChain = KeyChain()
    face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())

    prefix = Namespace("/ndn/test/status", keyChain)

    dump("Register prefix", prefix.name)
    # Set the face and register to receive Interests.
    prefix.setFace(face,
      lambda prefixName: dump("Register failed for prefix", prefixName))

    handler = GeneralizedObjectHandler()
    # Each generalized object will have a 1000 millisecond freshness period.
    metaInfo = MetaInfo()
    metaInfo.setFreshnessPeriod(1000.0)

    # This is called when the library receives an Interest which is not
    # satisfied by Data already in the Namespace tree.
    def onObjectNeeded(namespace, neededNamespace, callbackId):
        if not (neededNamespace is prefix):
            # This is not the expected Namespace.
            return False

        # Make a version from the current time.
        versionNamespace = prefix[
          Name.Component.fromVersion(Common.getNowMilliseconds())]
        # The metaInfo has the freshness period.
        versionNamespace.setNewDataMetaInfo(metaInfo)
        dump("Producing the generalized object for", versionNamespace.name)
        handler.setObject(
          versionNamespace, Blob("Status as of " + str(datetime.datetime.now())),
          "text/html")
        return True

    prefix.addOnObjectNeeded(onObjectNeeded)

    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)
Exemplo n.º 7
0
def main(args):
    face = Face()

    keyChain = KeyChain()
    face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())

    gobj = Namespace(args['<prefix>'], keyChain)

    gobj.setFace(
        face,
        lambda prefixName: dump("Register failed for prefix", prefixName))

    handler = GeneralizedObjectHandler()

    metaInfo = MetaInfo()
    if args['--freshness']:
        metaInfo.setFreshnessPeriod(float(args['--freshness']))
    else:
        metaInfo.setFreshnessPeriod(1000.0)

    def onObjectNeeded(namespace, neededNamespace, callbackId):
        if not (neededNamespace is gobj):
            # This is not the expected Namespace.
            return False

        # Make a version from the current time.
        versionNamespace = gobj[Name.Component.fromVersion(
            Common.getNowMilliseconds())]
        # The metaInfo has the freshness period.
        versionNamespace.setNewDataMetaInfo(metaInfo)

        with open(args['<file>'], 'r') as f:
            handler.setObject(versionNamespace, Blob(f.read()), "text/html")
        return True

    gobj.addOnObjectNeeded(onObjectNeeded)
    while True:
        face.processEvents()
        time.sleep(0.01)
Exemplo n.º 8
0
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()

    objectPrefix = Namespace("/ndn/eb/run/28/description")
    objectPrefix.setFace(face)

    enabled = [True]

    def onGeneralizedObject(contentMetaInfo, objectNamespace):
        dump("Got generalized object, content-type",
             contentMetaInfo.contentType, ":", str(objectNamespace.obj))
        enabled[0] = False

    GeneralizedObjectHandler(objectPrefix, onGeneralizedObject).objectNeeded()

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