define start-like options just once
This commit is contained in:
parent
9413edac47
commit
ec2e305b84
|
@ -22,122 +22,88 @@ def server(ctx): # this is the setuptools entrypoint for bin/wormhole-server
|
||||||
ctx.obj = Config()
|
ctx.obj = Config()
|
||||||
|
|
||||||
|
|
||||||
_relay_database_path = click.option(
|
_click_decorators = [
|
||||||
"--relay-database-path", default="relay.sqlite", metavar="PATH",
|
server.command(),
|
||||||
help="location for the relay server state database",
|
click.option(
|
||||||
)
|
|
||||||
_stats_json_path = click.option(
|
|
||||||
"--stats-json-path", default="stats.json", metavar="PATH",
|
|
||||||
help="location to write the relay stats file",
|
|
||||||
)
|
|
||||||
|
|
||||||
@server.command()
|
|
||||||
@click.option(
|
|
||||||
"--rendezvous", default="tcp:4000", metavar="tcp:PORT",
|
"--rendezvous", default="tcp:4000", metavar="tcp:PORT",
|
||||||
help="endpoint specification for the rendezvous port",
|
help="endpoint specification for the rendezvous port",
|
||||||
)
|
),
|
||||||
@click.option(
|
click.option(
|
||||||
"--transit", default="tcp:4001", metavar="tcp:PORT",
|
"--transit", default="tcp:4001", metavar="tcp:PORT",
|
||||||
help="endpoint specification for the transit-relay port",
|
help="endpoint specification for the transit-relay port",
|
||||||
)
|
),
|
||||||
@click.option(
|
click.option(
|
||||||
"--advertise-version", metavar="VERSION",
|
"--advertise-version", metavar="VERSION",
|
||||||
help="version to recommend to clients",
|
help="version to recommend to clients",
|
||||||
)
|
),
|
||||||
@click.option(
|
click.option(
|
||||||
"--blur-usage", default=None, type=int,
|
"--blur-usage", default=None, type=int,
|
||||||
metavar="SECONDS",
|
metavar="SECONDS",
|
||||||
help="round logged access times to improve privacy",
|
help="round logged access times to improve privacy",
|
||||||
)
|
),
|
||||||
@click.option(
|
click.option(
|
||||||
"--no-daemon", "-n", is_flag=True,
|
"--no-daemon", "-n", is_flag=True,
|
||||||
help="Run in the foreground",
|
help="Run in the foreground",
|
||||||
)
|
),
|
||||||
@click.option(
|
click.option(
|
||||||
"--signal-error", is_flag=True,
|
"--signal-error", is_flag=True,
|
||||||
help="force all clients to fail with a message",
|
help="force all clients to fail with a message",
|
||||||
)
|
),
|
||||||
@click.option(
|
click.option(
|
||||||
"--disallow-list", is_flag=True,
|
"--disallow-list", is_flag=True,
|
||||||
help="never send list of allocated nameplates",
|
help="never send list of allocated nameplates",
|
||||||
)
|
),
|
||||||
@_relay_database_path
|
click.option(
|
||||||
@_stats_json_path
|
"--relay-database-path", default="relay.sqlite", metavar="PATH",
|
||||||
@click.pass_obj
|
help="location for the relay server state database",
|
||||||
def start(cfg, signal_error, no_daemon, blur_usage, advertise_version,
|
),
|
||||||
|
click.option(
|
||||||
|
"--stats-json-path", default="stats.json", metavar="PATH",
|
||||||
|
help="location to write the relay stats file",
|
||||||
|
),
|
||||||
|
click.pass_obj,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _start_command(f):
|
||||||
|
for dec in _click_decorators[::-1]:
|
||||||
|
f = dec(f)
|
||||||
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
def arguments_to_config(
|
||||||
|
cfg, signal_error, no_daemon, blur_usage, advertise_version,
|
||||||
transit, rendezvous, disallow_list, relay_database_path,
|
transit, rendezvous, disallow_list, relay_database_path,
|
||||||
stats_json_path,
|
stats_json_path,
|
||||||
):
|
):
|
||||||
|
cfg.no_daemon = no_daemon
|
||||||
|
cfg.blur_usage = blur_usage
|
||||||
|
cfg.advertise_version = advertise_version
|
||||||
|
cfg.transit = str(transit)
|
||||||
|
cfg.rendezvous = str(rendezvous)
|
||||||
|
cfg.signal_error = signal_error
|
||||||
|
cfg.allow_list = not disallow_list
|
||||||
|
cfg.relay_database_path = relay_database_path
|
||||||
|
cfg.stats_json_path = stats_json_path
|
||||||
|
|
||||||
|
|
||||||
|
@_start_command
|
||||||
|
def start(cfg, **arguments):
|
||||||
"""
|
"""
|
||||||
Start a relay server
|
Start a relay server
|
||||||
"""
|
"""
|
||||||
from wormhole.server.cmd_server import start_server
|
from wormhole.server.cmd_server import start_server
|
||||||
cfg.no_daemon = no_daemon
|
arguments_to_config(cfg, **arguments)
|
||||||
cfg.blur_usage = blur_usage
|
|
||||||
cfg.advertise_version = advertise_version
|
|
||||||
cfg.transit = str(transit)
|
|
||||||
cfg.rendezvous = str(rendezvous)
|
|
||||||
cfg.signal_error = signal_error
|
|
||||||
cfg.allow_list = not disallow_list
|
|
||||||
cfg.relay_database_path = relay_database_path
|
|
||||||
cfg.stats_json_path = stats_json_path
|
|
||||||
|
|
||||||
start_server(cfg)
|
start_server(cfg)
|
||||||
|
|
||||||
|
|
||||||
# XXX it would be nice to reduce the duplication between 'restart' and
|
@_start_command
|
||||||
# 'start' options...
|
def restart(cfg, **arguments):
|
||||||
@server.command()
|
|
||||||
@click.option(
|
|
||||||
"--rendezvous", default="tcp:4000", metavar="tcp:PORT",
|
|
||||||
help="endpoint specification for the rendezvous port",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--transit", default="tcp:4001", metavar="tcp:PORT",
|
|
||||||
help="endpoint specification for the transit-relay port",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--advertise-version", metavar="VERSION",
|
|
||||||
help="version to recommend to clients",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--blur-usage", default=None, type=int,
|
|
||||||
metavar="SECONDS",
|
|
||||||
help="round logged access times to improve privacy",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--no-daemon", "-n", is_flag=True,
|
|
||||||
help="Run in the foreground",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--signal-error", is_flag=True,
|
|
||||||
help="force all clients to fail with a message",
|
|
||||||
)
|
|
||||||
@click.option(
|
|
||||||
"--disallow-list", is_flag=True,
|
|
||||||
help="never send list of allocated nameplates",
|
|
||||||
)
|
|
||||||
@_relay_database_path
|
|
||||||
@_stats_json_path
|
|
||||||
@click.pass_obj
|
|
||||||
def restart(cfg, signal_error, no_daemon, blur_usage, advertise_version,
|
|
||||||
transit, rendezvous, disallow_list, relay_database_path,
|
|
||||||
stats_json_path,
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Re-start a relay server
|
Re-start a relay server
|
||||||
"""
|
"""
|
||||||
from wormhole.server.cmd_server import restart_server
|
from wormhole.server.cmd_server import restart_server
|
||||||
cfg.no_daemon = no_daemon
|
arguments_to_config(cfg, **arguments)
|
||||||
cfg.blur_usage = blur_usage
|
|
||||||
cfg.advertise_version = advertise_version
|
|
||||||
cfg.transit = str(transit)
|
|
||||||
cfg.rendezvous = str(rendezvous)
|
|
||||||
cfg.signal_error = signal_error
|
|
||||||
cfg.allow_list = not disallow_list
|
|
||||||
cfg.relay_database_path = relay_database_path
|
|
||||||
cfg.stats_json_path = stats_json_path
|
|
||||||
|
|
||||||
restart_server(cfg)
|
restart_server(cfg)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user