예제 #1
0
def adminInterface(controller, hab, adminHttpPort=5623, adminTcpPort=5624):

    rotateHandler = agenting.RotateHandler(hab=hab)
    issueHandler = agenting.IssueCredentialHandler(hab=hab)
    handlers = [rotateHandler, issueHandler]

    exchanger = exchanging.Exchanger(hab=hab,
                                     controller=controller,
                                     handlers=handlers)

    server = tcpServing.Server(host="", port=adminTcpPort)
    tcpServerDoer = tcpServing.ServerDoer(server=server)
    directant = directing.Directant(hab=hab, server=server)

    app = falcon.App()
    exnServer = httping.AgentExnServer(exc=exchanger, app=app)
    httpKelServer = httping.AgentKelServer(hab=hab, app=app)

    server = http.Server(port=adminHttpPort, app=exnServer.app)
    httpServerDoer = http.ServerDoer(server=server)

    doers = [
        exnServer, exchanger, tcpServerDoer, directant, httpKelServer,
        httpServerDoer
    ]

    return doers
예제 #2
0
    def __init__(self, port, hab: habbing.Habitat, mbx: exchanging.Mailboxer,
                 **kwa):
        """

        :param port:
        :param hab:
        :param kwa:
        """
        self.hab = hab
        self.mbx = mbx
        self.port = port
        self.rxbs = bytearray()

        self.app = falcon.App()

        self.app.add_route("/mbx", self)

        self.server = http.Server(port=self.port, app=self.app)
        serdoer = http.ServerDoer(server=self.server)

        doers = [serdoer]

        super(MailboxServer, self).__init__(doers=doers, **kwa)
        if self.tymth:
            self.server.wind(self.tymth)
예제 #3
0
def runAgent(controller,
             name="agent",
             httpPort=5620,
             tcp=5621,
             adminHttpPort=5623,
             adminTcpPort=5624,
             expire=0.0):
    """
    Setup and run one agent
    """
    logger = help.ogler.getLogger()

    ks = keeping.Keeper(name=name,
                        temp=False)  # not opened by default, doer opens
    ksDoer = keeping.KeeperDoer(
        keeper=ks)  # doer do reopens if not opened and closes
    db = basing.Baser(name=name, temp=False,
                      reload=True)  # not opened by default, doer opens
    dbDoer = basing.BaserDoer(
        baser=db)  # doer do reopens if not opened and closes

    # setup habitat
    hab = habbing.Habitat(name=name, ks=ks, db=db, temp=False, create=False)
    habDoer = habbing.HabitatDoer(habitat=hab)  # setup doer

    # kvy = eventing.Kevery(db=hab.db, local=False)
    # setup doers
    server = tcpServing.Server(host="", port=tcp)
    tcpServerDoer = tcpServing.ServerDoer(server=server)
    directant = directing.Directant(hab=hab, server=server)

    wallet = walleting.Wallet(hab=hab, name=name)

    jsonSchema = scheming.JSONSchema(resolver=scheming.jsonSchemaCache)
    issueHandler = handling.IssueHandler(wallet=wallet, typ=jsonSchema)
    requestHandler = handling.RequestHandler(wallet=wallet, typ=jsonSchema)
    exchanger = exchanging.Exchanger(hab=hab,
                                     handlers=[issueHandler, requestHandler])

    app = falcon.App()
    exnServer = httping.AgentExnServer(exc=exchanger, app=app)
    httpKelServer = httping.AgentKelServer(hab=hab, app=app)

    server = http.Server(port=httpPort, app=exnServer.app)
    httpServerDoer = http.ServerDoer(server=server)

    doers = [
        ksDoer, dbDoer, habDoer, exchanger, directant, tcpServerDoer,
        exnServer, httpServerDoer, httpKelServer
    ]
    doers.extend(adminInterface(controller, hab, adminHttpPort, adminTcpPort))

    try:
        tock = 0.03125
        doist = doing.Doist(limit=expire, tock=tock, real=True)
        doist.do(doers=doers)
    except kering.ConfigurationError:
        print(f"prefix for {name} does not exist, incept must be run first", )
예제 #4
0
def launch(args):
    app = falcon.App()
    server = http.Server(port=args.http, app=app)
    httpServerDoer = http.ServerDoer(server=server)

    serving.loadEnds(app,
                     schemaDir=args.schemaDir,
                     credDir=args.credDir,
                     oobiDir=args.oobiDir)

    doers = [httpServerDoer]

    tock = 0.03125
    doist = doing.Doist(limit=0.0, tock=tock, real=True)
    doist.do(doers=doers)
예제 #5
0
def test_server_client_doers():
    """
    Test HTTP ServerDoer ClientDoer classes
    """
    tock = 0.03125
    ticks = 16
    limit = ticks * tock
    doist = doing.Doist(tock=tock, real=True, limit=limit)
    assert doist.tyme == 0.0  # on next cycle
    assert doist.tock == tock == 0.03125
    assert doist.real == True
    assert doist.limit == limit == 0.5
    assert doist.doers == []

    def wsgiApp(environ, start_response):
        start_response('200 OK', [('Content-type', 'text/plain'),
                                  ('Content-length', '12')])
        return [b"Hello World!"]

    port = 6101
    server = http.Server(port=port, app=wsgiApp, tymth=doist.tymen())
    assert server.servant.tyme == doist.tyme

    serdoer = http.ServerDoer(tymth=doist.tymen(), server=server)
    assert serdoer.server == server
    assert serdoer.tyme == serdoer.server.servant.tyme == doist.tyme

    path = "http://{0}:{1}/".format('localhost', port)
    client = http.Client(path=path, tymth=doist.tymen())
    assert client.connector.tyme == doist.tyme

    request = dict([
        ('method', u'GET'),
        ('path', u'/echo?name=fame'),
        ('qargs', dict()),
        ('fragment', u''),
        ('headers',
         dict([('Accept', 'application/json'), ('Content-Length', 0)])),
    ])

    client.requests.append(request)

    clidoer = http.ClientDoer(tymth=doist.tymen(), client=client)
    assert clidoer.client == client
    assert clidoer.tyme == clidoer.client.connector.tyme == doist.tyme

    assert serdoer.tock == 0.0  # ASAP
    assert clidoer.tock == 0.0  # ASAP

    doers = [serdoer, clidoer]

    doist.do(doers=doers, limit=limit)
    assert doist.tyme == limit
    assert server.servant.opened == False
    assert client.connector.opened == False

    assert len(client.responses) == 1
    response = client.responses.popleft()
    assert response['body'] == (b'Hello World!')
    assert response['status'] == 200
    """End Test """