Normalize start_*.py.

This commit is contained in:
Richard Kiss 2020-10-12 11:53:05 -07:00
parent 7bbf64fa18
commit a7991fe2f1
6 changed files with 42 additions and 38 deletions

View File

@ -17,12 +17,12 @@ from src.server.start_service import run_service
# See: https://bugs.python.org/issue29288
u"".encode("idna")
SERVICE_NAME = "farmer"
def service_kwargs_for_farmer(
root_path: pathlib.Path, consensus_constants: ConsensusConstants
root_path: pathlib.Path, config: Dict, consensus_constants: ConsensusConstants
) -> Dict:
service_name = "farmer"
config = load_config_cli(root_path, "config.yaml", service_name)
keychain = Keychain()
connect_peers = [
@ -38,7 +38,7 @@ def service_kwargs_for_farmer(
api=api,
node_type=NodeType.FARMER,
advertised_port=config["port"],
service_name=service_name,
service_name=SERVICE_NAME,
server_listen_ports=[config["port"]],
connect_peers=connect_peers,
auth_connect_peers=False,
@ -50,7 +50,8 @@ def service_kwargs_for_farmer(
def main():
kwargs = service_kwargs_for_farmer(DEFAULT_ROOT_PATH, DEFAULT_CONSTANTS)
config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
kwargs = service_kwargs_for_farmer(DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS)
return run_service(**kwargs)

View File

@ -16,12 +16,12 @@ from src.util.default_root import DEFAULT_ROOT_PATH
# See: https://bugs.python.org/issue29288
u"".encode("idna")
SERVICE_NAME = "full_node"
def service_kwargs_for_full_node(
root_path: pathlib.Path, consensus_constants: ConsensusConstants
root_path: pathlib.Path, config: Dict, consensus_constants: ConsensusConstants
) -> Dict:
service_name = "full_node"
config = load_config_cli(root_path, "config.yaml", service_name)
api = FullNode(config, root_path=root_path, consensus_constants=consensus_constants)
@ -30,7 +30,7 @@ def service_kwargs_for_full_node(
api=api,
node_type=NodeType.FULL_NODE,
advertised_port=config["port"],
service_name=service_name,
service_name=SERVICE_NAME,
upnp_ports=[config["port"]],
server_listen_ports=[config["port"]],
on_connect_callback=api._on_connect,
@ -41,7 +41,8 @@ def service_kwargs_for_full_node(
def main():
kwargs = service_kwargs_for_full_node(DEFAULT_ROOT_PATH, DEFAULT_CONSTANTS)
config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
kwargs = service_kwargs_for_full_node(DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS)
return run_service(**kwargs)

View File

@ -16,13 +16,14 @@ from src.server.start_service import run_service
# See: https://bugs.python.org/issue29288
u"".encode("idna")
SERVICE_NAME = "harvester"
def service_kwargs_for_harvester(
root_path: pathlib.Path, consensus_constants: ConsensusConstants
root_path: pathlib.Path,
config: Dict,
consensus_constants: ConsensusConstants,
) -> Dict:
service_name = "harvester"
config = load_config_cli(root_path, "config.yaml", service_name)
connect_peers = [
PeerInfo(config["farmer_peer"]["host"], config["farmer_peer"]["port"])
]
@ -34,7 +35,7 @@ def service_kwargs_for_harvester(
api=api,
node_type=NodeType.HARVESTER,
advertised_port=config["port"],
service_name=service_name,
service_name=SERVICE_NAME,
server_listen_ports=[config["port"]],
connect_peers=connect_peers,
auth_connect_peers=True,
@ -45,7 +46,8 @@ def service_kwargs_for_harvester(
def main():
kwargs = service_kwargs_for_harvester(DEFAULT_ROOT_PATH, DEFAULT_CONSTANTS)
config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
kwargs = service_kwargs_for_harvester(DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS)
return run_service(**kwargs)

View File

@ -14,29 +14,28 @@ from src.server.start_service import run_service
# See: https://bugs.python.org/issue29288
u"".encode("idna")
SERVICE_NAME = "introducer"
def service_kwargs_for_introducer(
root_path: pathlib.Path, constants: ConsensusConstants
root_path: pathlib.Path, config: Dict, constants: ConsensusConstants
) -> Dict:
service_name = "introducer"
config = load_config_cli(root_path, "config.yaml", service_name)
introducer = Introducer(
config["max_peers_to_send"], config["recent_peer_threshold"]
)
api = Introducer(config["max_peers_to_send"], config["recent_peer_threshold"])
kwargs = dict(
root_path=root_path,
api=introducer,
api=api,
node_type=NodeType.INTRODUCER,
advertised_port=config["port"],
service_name=service_name,
service_name=SERVICE_NAME,
server_listen_ports=[config["port"]],
)
return kwargs
def main():
kwargs = service_kwargs_for_introducer(DEFAULT_ROOT_PATH, DEFAULT_CONSTANTS)
config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
kwargs = service_kwargs_for_introducer(DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS)
return run_service(**kwargs)

View File

@ -41,11 +41,11 @@ class Service:
rpc_info: Optional[Tuple[type, int]] = None,
parse_cli_args=True,
):
net_config = load_config(root_path, "config.yaml")
ping_interval = net_config.get("ping_interval")
network_id = net_config.get("network_id")
self.self_hostname = net_config.get("self_hostname")
self.daemon_port = net_config.get("daemon_port")
config = load_config(root_path, "config.yaml")
ping_interval = config.get("ping_interval")
network_id = config.get("network_id")
self.self_hostname = config.get("self_hostname")
self.daemon_port = config.get("daemon_port")
assert ping_interval is not None
assert network_id is not None
@ -56,14 +56,14 @@ class Service:
setproctitle(proctitle_name)
self._log = logging.getLogger(service_name)
if parse_cli_args:
config = load_config_cli(root_path, "config.yaml", service_name)
service_config = load_config_cli(root_path, "config.yaml", service_name)
else:
config = load_config(root_path, "config.yaml", service_name)
service_config = load_config(root_path, "config.yaml", service_name)
initialize_logging(service_name, config["logging"], root_path)
self._rpc_info = rpc_info
ssl_cert_path, ssl_key_path = load_ssl_paths(root_path, config)
ssl_cert_path, ssl_key_path = load_ssl_paths(root_path, service_config)
self._server = ChiaServer(
advertised_port,

View File

@ -14,12 +14,12 @@ from src.server.start_service import run_service
# See: https://bugs.python.org/issue29288
u"".encode("idna")
SERVICE_NAME = "timelord"
def service_kwargs_for_timelord(
root_path: pathlib.Path, discriminant_size_bits: int
root_path: pathlib.Path, config: Dict, discriminant_size_bits: int
) -> Dict:
service_name = "timelord"
config = load_config_cli(root_path, "config.yaml", service_name)
connect_peers = [
PeerInfo(config["full_node_peer"]["host"], config["full_node_peer"]["port"])
@ -32,7 +32,7 @@ def service_kwargs_for_timelord(
api=api,
node_type=NodeType.TIMELORD,
advertised_port=config["port"],
service_name=service_name,
service_name=SERVICE_NAME,
server_listen_ports=[config["port"]],
connect_peers=connect_peers,
auth_connect_peers=False,
@ -41,8 +41,9 @@ def service_kwargs_for_timelord(
def main():
config = load_config_cli(DEFAULT_ROOT_PATH, "config.yaml", SERVICE_NAME)
kwargs = service_kwargs_for_timelord(
DEFAULT_ROOT_PATH, DEFAULT_CONSTANTS.DISCRIMINANT_SIZE_BITS
DEFAULT_ROOT_PATH, config, DEFAULT_CONSTANTS.DISCRIMINANT_SIZE_BITS
)
return run_service(**kwargs)