def _validate_network(network): if not isinstance(network, list): return False if len(network) != 2: return False transport, is_public = network if not isinstance(is_public, bool): return False if not isinstance(transport, list): return False if len(transport) != 2: return False ip, port = transport if not valid_ip(ip): return False if not valid_port(port): return False return True
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
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
def _validate_network(network): if not isinstance(network, list): return False if len(network) != 3: return False transport, unl, is_public = network if not isinstance(is_public, bool): return False if not isinstance(unl, six.string_types): return False # check transport if not isinstance(transport, list): return False if len(transport) != 2: return False ip, port = transport if not valid_ip(ip): return False if not valid_port(port): return False return True
def __init__(self, # kademlia DHT args key, ksize=20, port=None, bootstrap_nodes=None, dht_storage=None, max_messages=1024, refresh_neighbours_interval=WALK_TIMEOUT, # data transfer args disable_data_transfer=True, store_config=None, passive_port=None, passive_bind=None, # FIXME use utils.get_inet_facing_ip ? node_type="unknown", # FIMME what is this ? nat_type="unknown", # FIXME what is this ? wan_ip=None): # FIXME replace with sync_get_wan_ip calls """Create a blocking storjnode instance. Args: key (str): Bitcoin wif/hwif for auth, encryption and node id. ksize (int): The k parameter from the kademlia paper. port (port): Port to for incoming packages, randomly by default. bootstrap_nodes [(ip, port), ...]: Known network node addresses as. dht_storage: implements :interface:`~kademlia.storage.IStorage` max_messages (int): Max unprecessed messages, additional dropped. refresh_neighbours_interval (float): Auto refresh neighbours. disable_data_transfer: Disable data transfer for this node. store_config: Dict of storage paths to optional attributes. limit: The dir size limit in bytes, 0 for no limit. use_folder_tree: Files organized in a folder tree (always on for fat partitions). passive_port (int): Port to receive inbound TCP connections on. passive_bind (ip): LAN IP to receive inbound TCP connections on. node_type: TODO doc string nat_type: TODO doc string wan_ip: TODO doc string """ self.disable_data_transfer = bool(disable_data_transfer) self._transfer_request_handlers = set() self._transfer_complete_handlers = set() # set default store config if None given if store_config is None: store_config = storjnode.storage.manager.DEFAULT_STORE_CONFIG # validate port (randomish user port by default) port = port or random.choice(range(1024, 49151)) assert(0 <= port < 2 ** 16) self.port = port # passive port (randomish user port by default) passive_port = passive_port or random.choice(range(1024, 49151)) assert(0 <= port < 2 ** 16) # FIXME chance of same port and passive_port being the same # FIXME exclude ports already being used on the machine # passive bind # FIXME just use storjnode.util.get_inet_facing_ip ? passive_bind = passive_bind or "0.0.0.0" assert(valid_ip(passive_bind)) # validate bootstrap_nodes if bootstrap_nodes is None: bootstrap_nodes = DEFAULT_BOOTSTRAP_NODES # pragma: no cover 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(0 <= other_port < 2 ** 16) # start services self._setup_server(key, ksize, dht_storage, max_messages, refresh_neighbours_interval, bootstrap_nodes) if not self.disable_data_transfer: self._setup_data_transfer_client( store_config, passive_port, passive_bind, node_type, nat_type, wan_ip ) self._setup_message_dispatcher()