Browse Source

lightningd: make explicit listen and reconnect flags.

We set no_reconnect with --offline, but that doesn't work if !DEVELOPER.
Make the flag positive, and non-DEVELOPER mode for gossipd.

We also don't override portnum with --offline, but have an explicit
'listen' flag.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
ed466a8523
  1. 13
      gossipd/gossip.c
  2. 3
      gossipd/gossip_wire.csv
  3. 10
      lightningd/gossip_control.c
  4. 2
      lightningd/jsonrpc.c
  5. 3
      lightningd/lightningd.c
  6. 9
      lightningd/lightningd.h
  7. 7
      lightningd/opening_control.c
  8. 21
      lightningd/options.c

13
gossipd/gossip.c

@ -132,8 +132,8 @@ struct daemon {
/* To make sure our node_announcement timestamps increase */
u32 last_announce_timestamp;
/* Only matters if DEVELOPER defined */
bool no_reconnect;
/* Automatically reconnect. */
bool reconnect;
};
/* Peers we're trying to reach. */
@ -1631,7 +1631,7 @@ static struct io_plan *gossip_init(struct daemon_conn *master,
daemon, msg, &daemon->broadcast_interval, &chain_hash,
&daemon->id, &daemon->globalfeatures,
&daemon->localfeatures, &daemon->wireaddrs, daemon->rgb,
daemon->alias, &update_channel_interval, &daemon->no_reconnect)) {
daemon->alias, &update_channel_interval, &daemon->reconnect)) {
master_badmsg(WIRE_GOSSIPCTL_INIT, msg);
}
/* Prune time is twice update time */
@ -1955,12 +1955,11 @@ static void retry_important(struct important_peerid *imp)
/* In case we've come off a timer, don't leave dangling pointer */
imp->reconnect_timer = NULL;
#if DEVELOPER
/* With --dev-no-reconnect, we only want explicit
/* With --dev-no-reconnect or --offline, we only want explicit
* connects */
if (imp->daemon->no_reconnect)
if (!imp->daemon->reconnect)
return;
#endif
try_reach_peer(imp->daemon, &imp->id, false);
}

3
gossipd/gossip_wire.csv

@ -16,8 +16,7 @@ gossipctl_init,,wireaddrs,num_wireaddrs*struct wireaddr
gossipctl_init,,rgb,3*u8
gossipctl_init,,alias,32*u8
gossipctl_init,,update_channel_interval,u32
# DEVELOPER only
gossipctl_init,,no_reconnect,bool
gossipctl_init,,reconnect,bool
# Activate the gossip daemon, so others can connect.
gossipctl_activate,3025

Can't render this file because it has a wrong number of fields in line 6.

10
lightningd/gossip_control.c

@ -183,11 +183,6 @@ void gossip_init(struct lightningd *ld)
u8 *msg;
int hsmfd;
u64 capabilities = HSM_CAP_ECDH | HSM_CAP_SIGN_GOSSIP;
#if DEVELOPER
bool no_reconnect = ld->no_reconnect;
#else
bool no_reconnect = false;
#endif
msg = towire_hsm_client_hsmfd(tmpctx, &ld->id, capabilities);
if (!wire_sync_write(ld->hsm_fd, msg))
@ -212,7 +207,7 @@ void gossip_init(struct lightningd *ld)
&get_chainparams(ld)->genesis_blockhash, &ld->id,
get_offered_global_features(tmpctx),
get_offered_local_features(tmpctx), ld->wireaddrs, ld->rgb,
ld->alias, ld->config.channel_update_interval, no_reconnect);
ld->alias, ld->config.channel_update_interval, ld->reconnect);
subd_send_msg(ld->gossip, msg);
}
@ -227,7 +222,8 @@ static void gossip_activate_done(struct subd *gossip UNUSED,
void gossip_activate(struct lightningd *ld)
{
const u8 *msg = towire_gossipctl_activate(NULL, ld->portnum);
const u8 *msg = towire_gossipctl_activate(NULL,
ld->listen ? ld->portnum : 0);
subd_req(ld->gossip, ld->gossip, take(msg), -1, 0,
gossip_activate_done, NULL);

2
lightningd/jsonrpc.c

@ -149,7 +149,7 @@ static void json_getinfo(struct command *cmd,
json_object_start(response, NULL);
json_add_pubkey(response, "id", &cmd->ld->id);
if (cmd->ld->portnum) {
if (cmd->ld->listen && cmd->ld->portnum) {
json_add_num(response, "port", cmd->ld->portnum);
json_array_start(response, "address");
for (size_t i = 0; i < tal_count(cmd->ld->wireaddrs); i++)

3
lightningd/lightningd.c

@ -51,7 +51,6 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dev_debug_subdaemon = NULL;
ld->dev_disconnect_fd = -1;
ld->dev_subdaemon_fail = false;
ld->no_reconnect = false;
if (getenv("LIGHTNINGD_DEV_MEMLEAK"))
memleak_init(ld, backtrace_state);
@ -72,6 +71,8 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
list_head_init(&ld->close_commands);
ld->wireaddrs = tal_arr(ld, struct wireaddr, 0);
ld->portnum = DEFAULT_PORT;
ld->listen = true;
ld->reconnect = true;
timers_init(&ld->timers, time_mono());
ld->topology = new_topology(ld, ld->log);
ld->debug_subdaemon_io = NULL;

9
lightningd/lightningd.h

@ -111,6 +111,12 @@ struct lightningd {
/* Port we're listening on */
u16 portnum;
/* Do we want to reconnect to other peers? */
bool reconnect;
/* Do we want to listen for other peers? */
bool listen;
/* Addresses to announce to the network (tal_count()) */
struct wireaddr *wireaddrs;
@ -160,9 +166,6 @@ struct lightningd {
/* May be useful for non-developers debugging in the field */
char *debug_subdaemon_io;
/* Disable automatic reconnects */
bool no_reconnect;
/* Initial autocleaninvoice settings. */
u64 ini_autocleaninvoice_cycle;
u64 ini_autocleaninvoice_expiredby;

7
lightningd/opening_control.c

@ -257,13 +257,6 @@ void tell_gossipd_peer_is_important(struct lightningd *ld,
{
u8 *msg;
#if DEVELOPER
/* Don't schedule an attempt if we disabled reconnections with
* the `--dev-no-reconnect` flag */
if (ld->no_reconnect)
return;
#endif /* DEVELOPER */
/* Tell gossipd we need to keep connection to this peer */
msg = towire_gossipctl_peer_important(NULL, &channel->peer->id, true);
subd_send_msg(ld->gossip, take(msg));

21
lightningd/options.c

@ -259,8 +259,9 @@ static char *opt_set_fee_rates(const char *arg, struct chain_topology *topo)
static char *opt_set_offline(struct lightningd *ld)
{
ld->portnum = 0;
ld->no_reconnect = true;
ld->reconnect = false;
ld->listen = false;
return NULL;
}
@ -360,8 +361,8 @@ static void config_register_opts(struct lightningd *ld)
#if DEVELOPER
static void dev_register_opts(struct lightningd *ld)
{
opt_register_noarg("--dev-no-reconnect", opt_set_bool,
&ld->no_reconnect,
opt_register_noarg("--dev-no-reconnect", opt_set_invbool,
&ld->reconnect,
"Disable automatic reconnect attempts");
opt_register_noarg("--dev-fail-on-subdaemon-fail", opt_set_bool,
&ld->dev_subdaemon_fail, opt_hidden);
@ -767,11 +768,11 @@ void handle_opts(struct lightningd *ld, int argc, char *argv[])
check_config(ld);
if (ld->portnum && tal_count(ld->wireaddrs) == 0)
if (ld->portnum && ld->listen && tal_count(ld->wireaddrs) == 0)
guess_addresses(ld);
else
log_debug(ld->log, "Not guessing addresses: %s",
ld->portnum ? "manually set" : "port set to zero");
(ld->portnum && ld->listen) ? "manually set" : "port set to zero");
}
/* FIXME: This is a hack! Expose somehow in ccan/opt.*/
@ -804,12 +805,18 @@ static void add_config(struct lightningd *ld,
/* These two show up as --network= */
|| opt->cb == (void *)opt_set_testnet
|| opt->cb == (void *)opt_set_mainnet
|| 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) {
const bool *b = opt->u.carg;
answer = tal_fmt(name0, "%s", *b ? "true" : "false");
} else if (opt->cb == (void *)opt_set_invbool) {
const bool *b = opt->u.carg;
answer = tal_fmt(name0, "%s", !*b ? "true" : "false");
} else if (opt->cb == (void *)opt_set_offline) {
answer = tal_fmt(name0, "%s",
(!ld->reconnect && !ld->listen)
? "true" : "false");
} else {
/* Insert more decodes here! */
abort();

Loading…
Cancel
Save