Exemplo n.º 1
0
    def test_connect_broken_transport(self):
        """
        Transport with 100% loss never connects.
        """
        client_transport, server_transport = dummy_dtls_transport_pair(
            loss=[True])
        client = RTCSctpTransport(client_transport)
        client._rto = 0.1
        self.assertFalse(client.is_server)
        server = RTCSctpTransport(server_transport)
        server._rto = 0.1
        self.assertTrue(server.is_server)

        # connect
        server.start(client.getCapabilities(), client.port)
        client.start(server.getCapabilities(), server.port)

        # check outcome
        run(wait_for_outcome(client, server))
        self.assertEqual(client.state, RTCSctpTransport.State.CLOSED)
        self.assertEqual(server.state, RTCSctpTransport.State.CLOSED)

        # shutdown
        run(client.stop())
        run(server.stop())
        self.assertEqual(client.state, RTCSctpTransport.State.CLOSED)
        self.assertEqual(server.state, RTCSctpTransport.State.CLOSED)
Exemplo n.º 2
0
    def test_connect_lossy_transport(self):
        """
        Transport with 25% loss eventually connects.
        """
        client_transport, server_transport = dummy_dtls_transport_pair(
            loss=[True, False, False, False])

        client = RTCSctpTransport(client_transport)
        client._rto = 0.1
        self.assertFalse(client.is_server)
        server = RTCSctpTransport(server_transport)
        server._rto = 0.1
        self.assertTrue(server.is_server)

        # connect
        server.start(client.getCapabilities(), client.port)
        client.start(server.getCapabilities(), server.port)

        # check outcome
        run(wait_for_outcome(client, server))
        self.assertEqual(client.state, RTCSctpTransport.State.ESTABLISHED)
        self.assertEqual(server.state, RTCSctpTransport.State.ESTABLISHED)

        # transmit data
        server_queue = asyncio.Queue()

        async def server_fake_receive(*args):
            await server_queue.put(args)

        server._receive = server_fake_receive

        for i in range(20):
            message = (123, i, b'ping')
            run(client._send(*message))
            received = run(server_queue.get())
            self.assertEqual(received, message)

        # shutdown
        run(client.stop())
        run(server.stop())
        self.assertEqual(client.state, RTCSctpTransport.State.CLOSED)
        self.assertEqual(server.state, RTCSctpTransport.State.CLOSED)