Exemplo n.º 1
0
 def test_cannot_pair_different_transports(self):
     candidate_a = Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')
     candidate_b = Candidate.from_sdp(
         '6815297761 1 tcp 659136 1.2.3.4 12345 typ host generation 0 tcptype active'
     )
     self.assertFalse(candidate_a.can_pair_with(candidate_b))
Exemplo n.º 2
0
 def test_cannot_pair_ipv4_ipv6(self):
     candidate_a = Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')
     candidate_b = Candidate.from_sdp(
         '6815297761 1 udp 659136 2a02:0db8:85a3:0000:0000:8a2e:0370:7334 12345'
         ' typ host generation 0')
     self.assertFalse(candidate_a.can_pair_with(candidate_b))
Exemplo n.º 3
0
 def test_can_pair_ipv4(self):
     candidate_a = Candidate.from_sdp(
         "6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0"
     )
     candidate_b = Candidate.from_sdp(
         "6815297761 1 udp 659136 1.2.3.4 12345 typ host generation 0"
     )
     self.assertTrue(candidate_a.can_pair_with(candidate_b))
Exemplo n.º 4
0
 def test_cannot_pair_different_components(self):
     candidate_a = Candidate.from_sdp(
         "6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0"
     )
     candidate_b = Candidate.from_sdp(
         "6815297761 2 udp 659136 1.2.3.4 12345 typ host generation 0"
     )
     self.assertFalse(candidate_a.can_pair_with(candidate_b))
Exemplo n.º 5
0
 def test_can_pair_ipv6(self):
     candidate_a = Candidate.from_sdp(
         "6815297761 1 udp 659136 2a02:0db8:85a3:0000:0000:8a2e:0370:7334 31102"
         " typ host generation 0"
     )
     candidate_b = Candidate.from_sdp(
         "6815297761 1 udp 659136 2a02:0db8:85a3:0000:0000:8a2e:0370:7334 12345"
         " typ host generation 0"
     )
     self.assertTrue(candidate_a.can_pair_with(candidate_b))
Exemplo n.º 6
0
 async def _handle_ice_candidates(self):
     """
     (*Coroutine*) Coroutine that handle the ICE candidates negotiation.
     """
     while self.readyState == PeerState.CONNECTING or self.readyState == PeerState.CONNECTED:
         signal = await self._get_signal()
         if 'type' in signal:
             if signal['type'] == 'status' and signal[
                     'status'] == 'unpaired':
                 if self.readyState == PeerState.CONNECTED:
                     logging.info('unpaired received, disconnecting...')
                     self.disconnection_event.set()
         elif 'candidate' in signal:
             logging.info('Got ice candidate:')
             candi = Candidate.from_sdp(signal['candidate']['candidate'])
             candidate = RTCIceCandidate(
                 component=candi.component,
                 foundation=candi.foundation,
                 ip=candi.host,
                 port=candi.port,
                 priority=candi.priority,
                 protocol=candi.transport,
                 relatedAddress=candi.related_address,
                 relatedPort=candi.related_port,
                 tcpType=candi.tcptype,
                 type=candi.type,
                 sdpMLineIndex=signal['candidate']['sdpMLineIndex'],
                 sdpMid=signal['candidate']['sdpMid'])
             logging.debug(candidate)
             self._pc.addIceCandidate(candidate)
         else:
             raise Exception('Received an unexpected signal: ', signal)
Exemplo n.º 7
0
 def test_repr(self):
     candidate = Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')
     self.assertEqual(
         repr(candidate),
         'Candidate(6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0)'
     )
    async def add_candidate_to_pc(self, pc_id, candidate=RTCIceCandidate):
        logger.info("add_candidate_to_pc {}".format(candidate))
        if candidate:
            this_candidate = candidate.get("candidate")
            if this_candidate:
                logger.info("---------- {}".format(candidate["candidate"]))
                candidate_inst = Candidate.from_sdp(candidate["candidate"])

                rTCIceCandidate = candidate_from_aioice(candidate_inst)
                rTCIceCandidate.sdp = candidate["sdpMid"]
                rTCIceCandidate.sdpMLineIndex = candidate["sdpMLineIndex"]
Exemplo n.º 9
0
 def test_connect_no_local_candidates(self):
     """
     If local candidates have not been gathered, connect fails.
     """
     conn = ice.Connection(ice_controlling=True)
     conn.remote_candidates = [Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')]
     conn.remote_username = '******'
     conn.remote_password = '******'
     with self.assertRaises(ConnectionError):
         run(conn.connect())
     run(conn.close())
Exemplo n.º 10
0
 def test_connect_no_remote_credentials(self):
     """
     If remote credentials have not been provided, connect fails.
     """
     conn = ice.Connection(ice_controlling=True)
     run(conn.gather_candidates())
     conn.remote_candidates = [Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')]
     with self.assertRaises(ConnectionError) as cm:
         run(conn.connect())
     self.assertEqual(str(cm.exception), 'Remote username or password is missing')
     run(conn.close())
Exemplo n.º 11
0
 def test_connect_no_gather(self):
     """
     If local candidates gathering was not performed, connect fails.
     """
     conn = ice.Connection(ice_controlling=True)
     conn.remote_candidates = [Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')]
     conn.remote_username = '******'
     conn.remote_password = '******'
     with self.assertRaises(ConnectionError) as cm:
         run(conn.connect())
     self.assertEqual(str(cm.exception), 'Local candidates gathering was not performed')
     run(conn.close())
Exemplo n.º 12
0
    def test_connect_timeout(self):
        # lower STUN retries
        stun.RETRY_MAX = 2

        conn = ice.Connection(ice_controlling=True)
        run(conn.gather_candidates())
        conn.remote_candidates = [Candidate.from_sdp(
            '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')]
        conn.remote_username = '******'
        conn.remote_password = '******'
        with self.assertRaises(ConnectionError):
            run(conn.connect())
        run(conn.close())
Exemplo n.º 13
0
    def test_from_sdp_no_generation(self):
        candidate = Candidate.from_sdp(
            '6815297761 1 udp 659136 1.2.3.4 31102 typ host')

        self.assertEqual(candidate.foundation, '6815297761')
        self.assertEqual(candidate.component, 1)
        self.assertEqual(candidate.transport, 'udp')
        self.assertEqual(candidate.priority, 659136)
        self.assertEqual(candidate.host, '1.2.3.4')
        self.assertEqual(candidate.port, 31102)
        self.assertEqual(candidate.type, 'host')
        self.assertEqual(candidate.generation, None)

        self.assertEqual(candidate.to_sdp(),
                         '6815297761 1 udp 659136 1.2.3.4 31102 typ host')
Exemplo n.º 14
0
    def test_from_sdp_no_generation(self):
        candidate = Candidate.from_sdp("6815297761 1 udp 659136 1.2.3.4 31102 typ host")

        self.assertEqual(candidate.foundation, "6815297761")
        self.assertEqual(candidate.component, 1)
        self.assertEqual(candidate.transport, "udp")
        self.assertEqual(candidate.priority, 659136)
        self.assertEqual(candidate.host, "1.2.3.4")
        self.assertEqual(candidate.port, 31102)
        self.assertEqual(candidate.type, "host")
        self.assertEqual(candidate.generation, None)

        self.assertEqual(
            candidate.to_sdp(), "6815297761 1 udp 659136 1.2.3.4 31102 typ host"
        )
Exemplo n.º 15
0
 async def test_connect_no_remote_credentials(self):
     """
     If remote credentials have not been provided, connect fails.
     """
     conn = ice.Connection(ice_controlling=True)
     await conn.gather_candidates()
     await conn.add_remote_candidate(
         Candidate.from_sdp(
             "6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0"))
     await conn.add_remote_candidate(None)
     with self.assertRaises(ConnectionError) as cm:
         await conn.connect()
     self.assertEqual(str(cm.exception),
                      "Remote username or password is missing")
     await conn.close()
Exemplo n.º 16
0
 def test_connect_no_local_candidates(self):
     """
     If local candidates gathering yielded no candidates, connect fails.
     """
     conn = ice.Connection(ice_controlling=True)
     conn._local_candidates_end = True
     conn.add_remote_candidate(
         Candidate.from_sdp(
             "6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0"))
     conn.add_remote_candidate(None)
     conn.remote_username = "******"
     conn.remote_password = "******"
     with self.assertRaises(ConnectionError) as cm:
         run(conn.connect())
     self.assertEqual(str(cm.exception), "ICE negotiation failed")
     run(conn.close())
Exemplo n.º 17
0
 async def test_connect_no_gather(self):
     """
     If local candidates gathering was not performed, connect fails.
     """
     conn = ice.Connection(ice_controlling=True)
     await conn.add_remote_candidate(
         Candidate.from_sdp(
             "6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0"))
     await conn.add_remote_candidate(None)
     conn.remote_username = "******"
     conn.remote_password = "******"
     with self.assertRaises(ConnectionError) as cm:
         await conn.connect()
     self.assertEqual(str(cm.exception),
                      "Local candidates gathering was not performed")
     await conn.close()
Exemplo n.º 18
0
    def test_connect_timeout(self):
        # lower STUN retries
        stun.RETRY_MAX = 1

        conn = ice.Connection(ice_controlling=True)
        run(conn.gather_candidates())
        conn.add_remote_candidate(
            Candidate.from_sdp(
                "6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0"))
        conn.add_remote_candidate(None)
        conn.remote_username = "******"
        conn.remote_password = "******"
        with self.assertRaises(ConnectionError) as cm:
            run(conn.connect())
        self.assertEqual(str(cm.exception), "ICE negotiation failed")
        run(conn.close())
Exemplo n.º 19
0
    def test_from_sdp_tcp(self):
        candidate = Candidate.from_sdp(
            '1936595596 1 tcp 1518214911 1.2.3.4 9 typ host '
            'tcptype active generation 0 network-id 1 network-cost 10')
        self.assertEqual(candidate.foundation, '1936595596')
        self.assertEqual(candidate.component, 1)
        self.assertEqual(candidate.transport, 'tcp')
        self.assertEqual(candidate.priority, 1518214911)
        self.assertEqual(candidate.host, '1.2.3.4')
        self.assertEqual(candidate.port, 9)
        self.assertEqual(candidate.type, 'host')
        self.assertEqual(candidate.tcptype, 'active')
        self.assertEqual(candidate.generation, 0)

        self.assertEqual(
            candidate.to_sdp(),
            '1936595596 1 tcp 1518214911 1.2.3.4 9 typ host tcptype active generation 0')
Exemplo n.º 20
0
    def test_from_sdp_udp_srflx(self):
        candidate = Candidate.from_sdp(
            '1 1 UDP 1686052863 1.2.3.4 42705 typ srflx raddr 192.168.1.101 rport 42705'
        )
        self.assertEqual(candidate.foundation, '1')
        self.assertEqual(candidate.component, 1)
        self.assertEqual(candidate.transport, 'UDP')
        self.assertEqual(candidate.priority, 1686052863)
        self.assertEqual(candidate.host, '1.2.3.4')
        self.assertEqual(candidate.port, 42705)
        self.assertEqual(candidate.type, 'srflx')
        self.assertEqual(candidate.related_address, '192.168.1.101')
        self.assertEqual(candidate.related_port, 42705)
        self.assertEqual(candidate.generation, None)

        self.assertEqual(
            candidate.to_sdp(),
            '1 1 UDP 1686052863 1.2.3.4 42705 typ srflx raddr 192.168.1.101 rport 42705'
        )
Exemplo n.º 21
0
    def test_from_sdp_tcp(self):
        candidate = Candidate.from_sdp(
            "1936595596 1 tcp 1518214911 1.2.3.4 9 typ host "
            "tcptype active generation 0 network-id 1 network-cost 10"
        )
        self.assertEqual(candidate.foundation, "1936595596")
        self.assertEqual(candidate.component, 1)
        self.assertEqual(candidate.transport, "tcp")
        self.assertEqual(candidate.priority, 1518214911)
        self.assertEqual(candidate.host, "1.2.3.4")
        self.assertEqual(candidate.port, 9)
        self.assertEqual(candidate.type, "host")
        self.assertEqual(candidate.tcptype, "active")
        self.assertEqual(candidate.generation, 0)

        self.assertEqual(
            candidate.to_sdp(),
            "1936595596 1 tcp 1518214911 1.2.3.4 9 typ host tcptype active generation 0",
        )
Exemplo n.º 22
0
    def test_from_sdp_udp_srflx(self):
        candidate = Candidate.from_sdp(
            "1 1 UDP 1686052863 1.2.3.4 42705 typ srflx raddr 192.168.1.101 rport 42705"
        )
        self.assertEqual(candidate.foundation, "1")
        self.assertEqual(candidate.component, 1)
        self.assertEqual(candidate.transport, "UDP")
        self.assertEqual(candidate.priority, 1686052863)
        self.assertEqual(candidate.host, "1.2.3.4")
        self.assertEqual(candidate.port, 42705)
        self.assertEqual(candidate.type, "srflx")
        self.assertEqual(candidate.related_address, "192.168.1.101")
        self.assertEqual(candidate.related_port, 42705)
        self.assertEqual(candidate.generation, None)

        self.assertEqual(
            candidate.to_sdp(),
            "1 1 UDP 1686052863 1.2.3.4 42705 typ srflx raddr 192.168.1.101 rport 42705",
        )
Exemplo n.º 23
0
 def test_from_sdp_truncated(self):
     with self.assertRaises(ValueError):
         Candidate.from_sdp('6815297761 1 udp 659136 1.2.3.4 31102 typ')
Exemplo n.º 24
0
 def test_can_pair_ipv4_case_insensitive(self):
     candidate_a = Candidate.from_sdp(
         '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0')
     candidate_b = Candidate.from_sdp(
         '6815297761 1 UDP 659136 1.2.3.4 12345 typ host generation 0')
     self.assertTrue(candidate_a.can_pair_with(candidate_b))