diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 22fed49d7..548bcc1e6 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -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), diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 960d6247c..9b6b6fa52 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -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 */ }; diff --git a/lightningd/options.c b/lightningd/options.c index ff9a1e269..6f13d66f6 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -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); -