Exemplo n.º 1
0
 def logfile_path(self) -> Path:
     """
     Return the path to the log file.
     """
     if self._logfile_path is not None:
         return self._logfile_path
     else:
         return get_logfile_path(self.data_dir)
Exemplo n.º 2
0
    def __init__(self,
                 network_id: int,
                 max_peers: int = DEFAULT_MAX_PEERS,
                 data_dir: str = None,
                 nodekey_path: str = None,
                 logfile_path: str = None,
                 nodekey: PrivateKey = None,
                 sync_mode: str = SYNC_FULL,
                 port: int = 30303,
                 preferred_nodes: Tuple[KademliaNode, ...] = None,
                 bootstrap_nodes: Tuple[KademliaNode, ...] = None) -> None:
        self.network_id = network_id
        self.max_peers = max_peers
        self.sync_mode = sync_mode
        self.port = port

        if not preferred_nodes and network_id in DEFAULT_PREFERRED_NODES:
            self.preferred_nodes = DEFAULT_PREFERRED_NODES[self.network_id]
        else:
            self.preferred_nodes = preferred_nodes

        if bootstrap_nodes is None:
            if self.network_id == MAINNET_NETWORK_ID:
                self.bootstrap_nodes = tuple(
                    KademliaNode.from_uri(enode)
                    for enode in MAINNET_BOOTNODES)
            elif self.network_id == ROPSTEN_NETWORK_ID:
                self.bootstrap_nodes = tuple(
                    KademliaNode.from_uri(enode)
                    for enode in ROPSTEN_BOOTNODES)
        else:
            self.bootstrap_nodes = bootstrap_nodes

        # validation
        if nodekey is not None and nodekey_path is not None:
            raise ValueError(
                "It is invalid to provide both a `nodekey` and a `nodekey_path`"
            )

        # set values
        if data_dir is not None:
            self.data_dir = data_dir
        else:
            self.data_dir = get_data_dir_for_network_id(self.network_id)

        if nodekey_path is not None:
            self.nodekey_path = nodekey_path
        elif nodekey is not None:
            self.nodekey = nodekey

        if logfile_path is not None:
            self.logfile_path = logfile_path
        else:
            self.logfile_path = get_logfile_path(self.data_dir)