Exemple #1
0
 def _setup_server(self, key, ksize, storage, max_messages,
                   refresh_neighbours_interval, bootstrap_nodes):
     self.server = StorjServer(
         key, ksize=ksize, storage=storage, max_messages=max_messages,
         refresh_neighbours_interval=refresh_neighbours_interval
     )
     self.server.listen(self.port)
     self.server.bootstrap(bootstrap_nodes)
Exemple #2
0
    def __init__(self,
                 key,
                 port=DEFAULT_PORT,
                 start_reactor=True,
                 bootstrap_nodes=None):
        """Create a node instance, DHT functions like a dict.
        All calls are blocking for ease of use.
        """

        # validate port
        assert (isinstance(port, int))
        assert (port >= 0 and port <= 2**16)

        # validate bootstrap_nodes
        if bootstrap_nodes is None:
            bootstrap_nodes = DEFAULT_BOOTSTRAP_NODES
        for address in bootstrap_nodes:
            assert (isinstance(address, tuple) or isinstance(address, list))
            assert (len(address) == 2)
            other_ip, other_port = address
            assert (valid_ip(other_ip))
            assert (isinstance(other_port, int))
            assert (other_port >= 0 and other_port <= 2**16)

        # start dht node
        self._server = StorjServer(key)
        self._server.listen(port)
        if len(bootstrap_nodes) > 0:
            self._server.bootstrap(bootstrap_nodes)

        # start twisted reactor
        if start_reactor:
            self._reactor_thread = threading.Thread(
                target=reactor.run, kwargs={"installSignalHandlers": False})
            self._reactor_thread.start()
        else:
            self._reactor_thread = None