示例#1
0
文件: test_dtls.py 项目: pslq/aiortc
    def test_srtp_unprotect_error(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])
        receiver1 = DummyRtpReceiver()
        session1._register_rtp_receiver(
            receiver1,
            RTCRtpParameters(rtcp=RTCRtcpParameters(ssrc=1831097322)))

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])
        receiver2 = DummyRtpReceiver()
        session2._register_rtp_receiver(
            receiver2,
            RTCRtpParameters(rtcp=RTCRtcpParameters(ssrc=4028317929)))

        run(
            asyncio.gather(session1.start(session2.getLocalParameters()),
                           session2.start(session1.getLocalParameters())))

        # send same RTP twice, to trigger error on the receiver side:
        # "replay check failed (bad index)"
        run(session1._send_rtp(RTP))
        run(session1._send_rtp(RTP))
        run(asyncio.sleep(0.5))
        self.assertEqual(len(receiver2.rtcp_packets), 0)
        self.assertEqual(len(receiver2.rtp_packets), 1)

        # shutdown
        run(session1.stop())
        run(session2.stop())
示例#2
0
    def test_rtp(self):
        transport1, transport2 = dummy_ice_transport_pair()

        certificate1 = RTCCertificate.generateCertificate()
        session1 = RTCDtlsTransport(transport1, [certificate1])
        receiver1 = DummyRtpReceiver()
        session1._register_rtp_receiver(
            receiver1,
            RTCRtpParameters(rtcp=RTCRtcpParameters(ssrc=1831097322)))

        certificate2 = RTCCertificate.generateCertificate()
        session2 = RTCDtlsTransport(transport2, [certificate2])
        receiver2 = DummyRtpReceiver()
        session2._register_rtp_receiver(
            receiver2,
            RTCRtpParameters(rtcp=RTCRtcpParameters(ssrc=4028317929)))

        run(
            asyncio.gather(session1.start(session2.getLocalParameters()),
                           session2.start(session1.getLocalParameters())))
        self.assertCounters(session1, session2, 2, 2)

        # send RTP
        run(session1._send_rtp(RTP))
        run(asyncio.sleep(0.1))
        self.assertCounters(session1, session2, 3, 2)
        self.assertEqual(len(receiver2.rtcp_packets), 0)
        self.assertEqual(len(receiver2.rtp_packets), 1)

        # send RTCP
        run(session2._send_rtp(RTCP))
        run(asyncio.sleep(0.1))
        self.assertCounters(session1, session2, 3, 3)
        self.assertEqual(len(receiver1.rtcp_packets), 1)
        self.assertEqual(len(receiver1.rtp_packets), 0)

        # shutdown
        run(session1.stop())
        run(asyncio.sleep(0.5))
        self.assertCounters(session1, session2, 4, 3)
        self.assertEqual(session1.state, 'closed')
        self.assertEqual(session2.state, 'closed')

        # try closing again
        run(session1.stop())
        run(session2.stop())

        # try sending after close
        with self.assertRaises(ConnectionError):
            run(session1._send_rtp(RTP))