Esempio n. 1
0
def main():
    """Main."""
    args = config()
    _did, my_vk, my_sk, their_vk, endpoint = create_or_recall_keys(
        args.replace)

    conn = StaticConnection(my_vk, my_sk, their_vk, endpoint)

    print('Pinging connection...')
    reply = conn.send_and_await_reply(
        {
            "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
            "response_requested": True
        },
        return_route='all',
        timeout=5)
    print('Response:', reply.pretty_print())

    @conn.route('did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/basicmessage/1.0/message')
    async def basic_message_auto_responder(msg, conn):
        """Automatically respond to basicmessages."""
        await conn.send_async({
            "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/"
            "basicmessage/1.0/message",
            "~l10n": {
                "locale": "en"
            },
            "sent_time": utils.timestamp(),
            "content": "You said: {}".format(msg['content'])
        })

    async def handle(request):
        """aiohttp handle POST."""
        response = []
        with conn.reply_handler(response.append):
            await conn.handle(await request.read())

        if response:
            return web.Response(body=response.pop())

        raise web.HTTPAccepted()

    app = web.Application()
    app.add_routes([web.post('/', handle)])

    web.run_app(app, port=args.port)
Esempio n. 2
0
def main():
    """Main."""
    args = config()
    _did, my_vk, my_sk, their_vk, endpoint = create_or_recall_keys(
        args.replace)

    conn = StaticConnection(my_vk, my_sk, their_vk, endpoint)

    print('Pinging connection...')
    reply = conn.send_and_await_reply(
        {
            "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
            "response_requested": True
        },
        return_route='all',
        timeout=5)
    print('Response:', reply.pretty_print())
Esempio n. 3
0
def main():
    """Start a server with a static connection."""
    keys = crypto.create_keypair(
        seed=hashlib.sha256(b'client').digest()
    )
    their_vk, _ = crypto.create_keypair(
        seed=hashlib.sha256(b'server').digest()
    )
    conn = StaticConnection(
        keys, their_vk=their_vk, endpoint='http://*****:*****@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/"
                 "basicmessage/1.0/message",
        "~l10n": {"locale": "en"},
        "sent_time": utils.timestamp(),
        "content": "The Cron Script has been executed."
    }, return_route='all')
    print('Msg from conn:', reply and reply.pretty_print())