Beispiel #1
0
    def test_eq(self):
        self.assertEqual(self.pc1, self._mk_default_CPC())

        other_addresses = ((self.hostname, self.port),
                           ("openbazaar.org", self.port), (self.hostname,
                                                           8080))
        for address in other_addresses:
            self.assertEqual(
                self.pc1,
                connection.CryptoPeerConnection(self.transport,
                                                address[0],
                                                address[1],
                                                peer_socket=self.socket))

        self.assertNotEqual(self.pc1, None)

        self.assertEqual(self.pc2, self._mk_complete_CPC())
        self.assertEqual(self.pc2, self.guid)

        another_guid = "43"
        self.assertNotEqual(
            self.pc2,
            connection.CryptoPeerConnection(self.transport,
                                            self.hostname,
                                            self.port,
                                            self.pub,
                                            another_guid,
                                            self.nickname,
                                            self.sin,
                                            peer_socket=self.socket))
        self.assertNotEqual(self.pc1, int(self.guid))
    def test_eq(self):
        self.assertEqual(self.pc1, self._mk_default_CPC())

        other_addresses = (self._mk_address("http", self.hostname, self.port),
                           self._mk_address(self.protocol, "openbazaar.org",
                                            self.port),
                           self._mk_address(self.protocol, self.hostname,
                                            8080))
        for address in other_addresses:
            self.assertEqual(
                self.pc1,
                connection.CryptoPeerConnection(self.transport, address))

        self.assertNotEqual(self.pc1, None)

        self.assertEqual(self.pc2, self._mk_complete_CPC())
        self.assertEqual(self.pc2, self.guid)

        another_guid = "43"
        self.assertNotEqual(
            self.pc2,
            connection.CryptoPeerConnection(self.transport, self.address,
                                            self.pub, another_guid,
                                            self.nickname, self.sin))
        self.assertNotEqual(self.pc1, int(self.guid))
 def _mk_complete_CPC(cls):
     return connection.CryptoPeerConnection(
         cls.transport,
         cls.address,
         cls.pub,
         cls.guid,
         cls.nickname,
         cls.sin,
     )
Beispiel #4
0
 def _mk_complete_CPC(cls):
     return connection.CryptoPeerConnection(cls.transport,
                                            cls.hostname,
                                            cls.port,
                                            cls.pub,
                                            cls.guid,
                                            cls.nickname,
                                            cls.sin,
                                            peer_socket=cls.socket)
Beispiel #5
0
    def get_crypto_peer(self,
                        guid=None,
                        hostname=None,
                        port=None,
                        pubkey=None,
                        nickname=None,
                        nat_type=None,
                        avatar_url=None):
        if guid == self.guid:
            self.log.error('Cannot get CryptoPeerConnection for your own node')
            return

        if not guid:
            guid = 'seed%d' % len(self.peers)

        if guid not in self.peers:
            self.peers[guid] = connection.CryptoPeerConnection(
                self,
                hostname,
                port,
                pubkey,
                guid=guid,
                nickname=nickname,
                peer_socket=self.listener.socket,
                nat_type=nat_type,
                avatar_url=avatar_url)
        else:
            # FIXME this is wrong to do here, but it keeps this as close as
            # possible to the original pre-connection-reuse behavior
            if hostname:
                self.peers[guid].hostname = hostname
            if port:
                self.peers[guid].port = port
            if pubkey:
                self.peers[guid].pub = pubkey
            if nickname:
                self.peers[guid].nickname = nickname
            if nat_type:
                self.peers[guid].nat_type = nat_type
            if avatar_url:
                self.peers[guid].avatar_url = avatar_url

        return self.peers[guid]
 def _mk_default_CPC(cls):
     return connection.CryptoPeerConnection(
         cls.transport,
         cls.address,
     )
Beispiel #7
0
 def _mk_default_CPC(cls):
     return connection.CryptoPeerConnection(cls.transport,
                                            cls.hostname,
                                            cls.port,
                                            peer_socket=cls.socket)