async def test_simple_messaging(backchannel):
    """Show simple messages being passed to and from the test subject."""

    expected_schema = MessageSchema({
        '@type': 'test/protocol/1.0/test',
        '@id': str,
        'msg': 'pong'
    })

    ping = Message({
        '@type': 'test/protocol/1.0/test',
        'msg': 'ping'
    })
    print('Sending message:', ping.pretty_print())
    pong = await backchannel.send_and_await_reply_async(
        ping,
        timeout=1
    )

    print('Received message:', pong.pretty_print())

    assert pong.mtc[
        CONFIDENTIALITY | INTEGRITY | AUTHENTICATED_ORIGIN | DESERIALIZE_OK
    ]
    assert not pong.mtc[NONREPUDIATION]
    assert pong.mtc.ad['sender_vk'] == crypto.bytes_to_b58(backchannel.their_vk)
    assert pong.mtc.ad['recip_vk'] == crypto.bytes_to_b58(backchannel.my_vk)

    assert expected_schema.validate(pong)
Пример #2
0
 def _send(self, message_body):
     message = Message(message_body)
     print('Sending message:', message.pretty_print())
     reply = self.connection.send_and_await_reply(message,
                                                  return_route='all',
                                                  timeout=5)
     print('Response:', reply.pretty_print())
     return reply
Пример #3
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)

    ping = Message({
        "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
        "response_requested": True
    })
    print('Pinging connection:', ping.pretty_print())
    reply = conn.send_and_await_reply(
        ping,
        return_route='all',
        timeout=5
    )
    print('Response:', reply.pretty_print())
Пример #4
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)

    ping = Message({
        "@type": "did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/trust_ping/1.0/ping",
        "response_requested": True
    })
    print('Pinging connection:', ping.pretty_print())
    reply = conn.send_and_await_reply(ping, 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)
async def test_simple_messaging(connection):
    """Show simple messages being passed to and from the test subject."""

    expected_schema = MessageSchema({
        '@type': 'test/protocol/1.0/test',
        '@id': str,
        'msg': 'pong'
    })

    ping = Message({'@type': 'test/protocol/1.0/test', 'msg': 'ping'})
    print('Sending message:', ping.pretty_print())
    pong = await connection.send_and_await_reply_async(ping, timeout=1)

    print('Received message:', pong.pretty_print())

    assert pong.mtc.is_authcrypted()
    assert pong.mtc.sender == crypto.bytes_to_b58(connection.recipients[0])
    assert pong.mtc.recipient == connection.verkey_b58

    assert expected_schema(pong)