def test_send_receive (self):
        server = Server ()
        client = Client ()
    
        event_loop = ndn.EventLoop (server.face, client.face)
        client.setEventLoop (event_loop)
        event_loop.run ()

        self.assertTrue (client.dataReceived)
        self.assertFalse (client.timeoutReceived)
    def run (self):
        _LOG.info ('Daemon started')

        self._ndns = ndns.ndns_session (self.data_dir)
        self._face = ndn.Face ()

        self._startZoneServing ()

        self._eventLoop = ndn.EventLoop (self._face)
        self._eventLoop.run ()

        _LOG.info ('Daemon stopped')
Exemple #3
0
		# SignedInfo
		si = ndn.SignedInfo()
		si.type = ndn.CONTENT_DATA
		si.finalBlockID = ndn.Name.num2seg(0)
		si.publisherPublicKeyDigest = key.publicKeyID
		si.keyLocator = keylocator

		# ContentObject
		co = ndn.ContentObject()
		co.content = content
		co.name = co_name
		co.signedInfo = si

		co.sign(key)
		return co

	def callback(kind, info):
		print(info.ContentObject.content)

	fc = FlowController("/test", ndn.Face())
	fc.put(publish('/test/1', 'one'))
	fc.put(publish('/test/2', 'two'))
	fc.put(publish('/test/3', 'three'))
	vp = VersionedPull("/chat", callback)
	el = ndn.EventLoop(fc.handle, vp.handle)

	while True:
		vp.requestNext()
		el.run_once()
		time.sleep(1)
Exemple #4
0
def dig(args, out=None, cachingQuery=None, policy=None):
    if out is None:
        out = StringIO()

    if policy is None:
        policy = ndns.TrustPolicy

    if cachingQuery is None:
        cachingQuery = ndns.CachingQueryObj

    if not isinstance(args.zone, ndn.Name):
        zone = ndn.Name(args.zone)
    else:
        zone = args.zone

    if args.simple:
        if args.name:
            if not args.ndn:
                args.name = ndns.ndnify(args.name)
            name = ndn.Name(args.name)
        elif not args.raw:
            sys.stderr.write(
                "ERROR: For simple query, ``name'' (label) argument is mandatory\n"
            )
            exit(5)

    face = ndn.Face()
    loop = ndn.EventLoop(face)
    needrun = True

    def onResult(result, msg):
        if args.no_output:
            needrun = False
            loop.stop()
            return

        if not args.quiet:
            out.write(";; Got data packet [%s]\n" % result.name)
            out.write(";;       signed by [%s]\n" %
                      result.signedInfo.keyLocator.keyName)
            out.write("\n")
            out.write("%s\n" % msg.to_text())
        else:
            for rrset in msg.answer:
                out.write("%s\n" % rrset.to_text())

        needrun = False
        loop.stop()

    def onError(errmsg, *k, **kw):
        if args.no_output:
            needrun = False
            loop.stop()
            return

        out.write(";; %s\n" % errmsg)
        needrun = False
        loop.stop()

    def onPreResult(result, msg):
        def _onVerify(data, status):
            if status:
                onResult(result, msg)
            else:
                onError("Got answer, but it cannot be verified")

        if args.verify:
            onResult(result, msg)
        else:
            policy.verifyAsync(face, result, _onVerify)

    if args.simple:
        if not args.raw:
            cachingQuery.expressQueryFor(face,
                                         onPreResult,
                                         onError,
                                         zone,
                                         args.fh,
                                         name,
                                         args.rrtype,
                                         verify=args.verify)
        else:
            cachingQuery.expressQueryForRaw(face,
                                            onPreResult,
                                            onError,
                                            zone,
                                            hint=args.fh,
                                            verify=args.verify)
    elif args.zone_fh_query:
        cachingQuery.expressQueryForZoneFh(face, onPreResult, onError, zone,
                                           args.verify)
    else:
        args.rrtype = args.name
        cachingQuery.expressQuery(face, onPreResult, onError, zone,
                                  args.rrtype, args.verify)

    if needrun:
        loop.run()

    if isinstance(out, StringIO):
        return out.getvalue()