Esempio n. 1
0
    def find_peer(self, target_host, min_port, port_range):
        # the concept is to start at a random port, loop around until we get to a host that will respond
        max_port = min_port + port_range      # find the max range
        random_offset = 0 # = random.randint(min_port, self.port) # choose a random port in range
        # create a client for this operation
        client = Simple_Client(self.host, self.port)

        # instruct the client to 'broadcast' and loop through all peer addresses
        response = client.iterative_broadcast(target_host, min_port, random_offset, port_range, "FIND_PEER")
        if response == "":
            return (NetNode("None",0))
        # the response should be a tuple, separated by ':', but there is no type checking, sorry
        r_host, r_port = response.split(':')
        # we create a remote node for this
        r_node = NetNode(r_host, (int(r_port)))
        # then we stop and return the remote node
        return r_node
Esempio n. 2
0
    def find_peer(self, target_host, min_port, port_range):
        # the concept is to start at a random port, loop around until we get to a host that will respond
        max_port = min_port + port_range  # find the max range
        random_offset = 0  # = random.randint(min_port, self.port) # choose a random port in range
        # create a client for this operation
        client = Simple_Client(self.host, self.port)

        # instruct the client to 'broadcast' and loop through all peer addresses
        response = client.iterative_broadcast(target_host, min_port,
                                              random_offset, port_range,
                                              "FIND_PEER")
        if response == "":
            return (NetNode("None", 0))
        # the response should be a tuple, separated by ':', but there is no type checking, sorry
        r_host, r_port = response.split(':')
        # we create a remote node for this
        r_node = NetNode(r_host, (int(r_port)))
        # then we stop and return the remote node
        return r_node