Clean up network options.

It's become clear that our network options are insufficient, with the coming
addition of Tor and unix domain support.

Currently:

1. We always bind to local IPv4 and IPv6 sockets, unless --port=0, --offline,
   or any address is specified explicitly.  If they're routable, we announce.
2. --addr is used to announce, but not to control binding.

After this change:

1. --port is deprecated.
2. --addr controls what we bind to and announce.
3. --bind-addr/--announce-addr can be used to control one and not the other.
4. Unless --autolisten=0, we add local IPv4 & IPv6 port 9735 (and announce if they are routable).
5. --offline still overrides listening (though announcing is still the same).

This means we can bind to as many ports/interfaces as we want, and for
special effects we can announce different things (eg. we're sitting
behind a port forward or a proxy).

What remains to implement is semi-automatic binding: we should be able
to say '--addr=0.0.0.0:9999' and have the address resolve at bind
time, or even '--addr=0.0.0.0:0' and have the port autoresolve too
(you could determine what it was from 'lightning-cli getinfo'.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-05-07 13:58:12 +09:30
committed by Christian Decker
parent 00537fde43
commit fe96fe10c7
13 changed files with 228 additions and 109 deletions

View File

@@ -149,12 +149,31 @@ static void json_getinfo(struct command *cmd,
json_object_start(response, NULL);
json_add_pubkey(response, "id", &cmd->ld->id);
if (cmd->ld->listen && cmd->ld->portnum) {
json_add_num(response, "port", cmd->ld->portnum);
if (cmd->ld->listen) {
bool have_listen_no_announce = false;
if (deprecated_apis)
json_add_num(response, "port", cmd->ld->portnum);
/* These are the addresses we're announcing */
json_array_start(response, "address");
for (size_t i = 0; i < tal_count(cmd->ld->wireaddrs); i++)
json_add_address(response, NULL, cmd->ld->wireaddrs+i);
for (size_t i = 0; i < tal_count(cmd->ld->wireaddrs); i++) {
if (cmd->ld->listen_announce[i] & ADDR_ANNOUNCE)
json_add_address(response, NULL,
cmd->ld->wireaddrs+i);
else
have_listen_no_announce = true;
}
json_array_end(response);
if (have_listen_no_announce) {
json_array_start(response, "listen-only");
for (size_t i = 0; i < tal_count(cmd->ld->wireaddrs); i++) {
if (cmd->ld->listen_announce[i] == ADDR_LISTEN)
json_add_address(response, NULL,
cmd->ld->wireaddrs+i);
}
json_array_end(response);
}
}
json_add_string(response, "version", version());
json_add_num(response, "blockheight", get_block_height(cmd->ld->topology));