Example #1
0
    def test_get_socket_addresses(self):
        server = PendingConnectionsServer(None, Network())

        node = Node()
        port = 100
        res = server.get_socket_addresses(node, port, None)
        self.assertEqual(res, [])
        node.pub_addr = "10.10.10.10"
        res = server.get_socket_addresses(node, port, None)
        self.assertEqual(len(res), 1)
        self.assertEqual(res[0].address, node.pub_addr)
        self.assertEqual(res[0].port, port)
        node.pub_port = 1023
        res = server.get_socket_addresses(node, port, None)
        self.assertEqual(len(res), 1)
        self.assertEqual(res[0].address, node.pub_addr)
        self.assertEqual(res[0].port, 1023)
        node.prv_addresses = [
            "10.10.10.1", "10.10.10.2", "10.10.10.3", "10.10.10.4"
        ]
        res = server.get_socket_addresses(node, port, None)
        self.assertEqual(len(res), 5)
        self.assertEqual(res[4].address, node.pub_addr)
        self.assertEqual(res[4].port, 1023)
        for i in range(4):
            self.assertEqual(res[i].address, node.prv_addresses[i])
            self.assertEqual(res[i].port, port)
        node.pub_addr = None
        res = server.get_socket_addresses(node, port, None)
        self.assertEqual(len(res), 4)
        for i in range(4):
            self.assertEqual(res[i].address, node.prv_addresses[i])
            self.assertEqual(res[i].port, port)
Example #2
0
    def test_get_socket_addresses(self):
        server = PendingConnectionsServer(None, Network())

        node = self.node_info
        res = server.get_socket_addresses(node,
                                          prv_port=node.prv_port,
                                          pub_port=node.pub_port)
        self.assertEqual(res, [
            SocketAddress(self.node_info.pub_addr, self.node_info.pub_port),
            SocketAddress(self.node_info.prv_addresses[0],
                          self.node_info.prv_port)
        ])
        node.pub_addr = "10.10.10.10"
        res = server.get_socket_addresses(node,
                                          prv_port=node.prv_port,
                                          pub_port=node.pub_port)
        self.assertEqual(len(res), 2)
        self.assertEqual(res[0].address, node.pub_addr)
        self.assertEqual(res[0].port, node.pub_port)
        node.pub_port = 1023
        res = server.get_socket_addresses(node,
                                          prv_port=node.prv_port,
                                          pub_port=node.pub_port)
        self.assertEqual(len(res), 2)
        self.assertEqual(res[0].address, node.pub_addr)
        self.assertEqual(res[0].port, 1023)

        node.prv_addresses = [
            "10.10.10.1", "10.10.10.2", "10.10.10.3", "10.10.10.4"
        ]

        res = server.get_socket_addresses(node,
                                          prv_port=node.prv_port,
                                          pub_port=node.pub_port)
        self.assertEqual(len(res), 5)
        self.assertEqual(res[4].address, node.prv_addresses[-1])
        self.assertEqual(res[4].port, 1233)
        for i in range(4):
            self.assertEqual(res[i + 1].address, node.prv_addresses[i])
            self.assertEqual(res[i + 1].port, node.prv_port)
        node.pub_addr = None
        res = server.get_socket_addresses(node,
                                          prv_port=node.prv_port,
                                          pub_port=node.pub_port)
        self.assertEqual(len(res), 4)
        for i in range(4):
            self.assertEqual(res[i].address, node.prv_addresses[i])
            self.assertEqual(res[i].port, node.prv_port)
Example #3
0
 def get_socket_addresses(self, node_info, port, key_id):
     if self.client.get_suggested_conn_reverse(key_id):
         return []
     socket_addresses = PendingConnectionsServer.get_socket_addresses(
         self, node_info, port, key_id)
     addr = self.client.get_suggested_addr(key_id)
     if addr:
         socket_addresses = [SocketAddress(addr, port)] + socket_addresses
     return socket_addresses