options: Add --offline to disable listening and auto-reconnection

This commit is contained in:
Christian Decker 2018-02-22 10:42:58 +01:00 committed by Rusty Russell
parent 0a20bd44f0
commit 6f6176a91e
3 changed files with 17 additions and 5 deletions

View File

@ -1502,7 +1502,10 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
}
daemon->rstate = new_routing_state(daemon, &chain_hash, &daemon->id);
setup_listeners(daemon, port);
if (port)
setup_listeners(daemon, port);
else
status_trace("Not listeing for incoming connections due to --no-listen");
new_reltimer(&daemon->timers, daemon,
time_from_sec(daemon->update_channel_interval/2),

View File

@ -148,6 +148,9 @@ struct lightningd {
/* May be useful for non-developers debugging in the field */
char *debug_subdaemon_io;
/* Disable automatic reconnects */
bool no_reconnect;
#if DEVELOPER
/* If we want to debug a subdaemon. */
const char *dev_debug_subdaemon;
@ -163,9 +166,6 @@ struct lightningd {
/* Things we've marked as not leaking. */
const void **notleaks;
/* Disable automatic reconnects */
bool no_reconnect;
#endif /* DEVELOPER */
};

View File

@ -210,6 +210,13 @@ static char *opt_set_fee_rates(const char *arg, struct chain_topology *topo)
return NULL;
}
static char *opt_set_offline(struct lightningd *ld)
{
ld->portnum = 0;
ld->no_reconnect = true;
return NULL;
}
static void config_register_opts(struct lightningd *ld)
{
opt_register_noarg("--daemon", opt_set_bool, &ld->daemon,
@ -271,6 +278,8 @@ static void config_register_opts(struct lightningd *ld)
opt_register_arg("--ipaddr", opt_add_ipaddr, NULL,
ld,
"Set the IP address (v4 or v6) to announce to the network for incoming connections");
opt_register_noarg("--offline", opt_set_offline, ld,
"Start in offline-mode (do not automatically reconnect and do not accept incoming connections");
opt_register_early_arg("--network", opt_set_network, opt_show_network,
ld,
@ -719,6 +728,7 @@ static void add_config(struct lightningd *ld,
if (opt->type & OPT_NOARG) {
if (opt->cb == (void *)opt_usage_and_exit
|| opt->cb == (void *)version_and_exit
|| opt->cb == (void *)opt_set_offline /* will show up as port=0 and --no-reconnect */
|| opt->cb == (void *)test_daemons_and_exit) {
/* These are not important */
} else if (opt->cb == (void *)opt_set_bool) {
@ -855,4 +865,3 @@ static const struct json_command listconfigs_command = {
"With [config], object only has that field"
};
AUTODATA(json_command, &listconfigs_command);