diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index ef7c718d2..10396c5d4 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -248,11 +248,13 @@ static void json_getinfo(struct command *cmd, json_object_start(response, NULL); json_add_pubkey(response, "id", &cmd->ld->id); - /* FIXME: Keep ipaddr and list them all. */ - if (cmd->ld->portnum) + if (cmd->ld->portnum) { json_add_num(response, "port", cmd->ld->portnum); - json_add_string(response, "network", - get_chainparams(cmd->ld)->network_name); + 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); + json_array_end(response); + } json_add_string(response, "version", version()); json_add_num(response, "blockheight", get_block_height(cmd->ld->topology)); json_object_end(response); diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 42305dd8d..8cb5af3e3 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -79,6 +79,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx, ld->rgb = NULL; list_head_init(&ld->pay_commands); list_head_init(&ld->connects); + ld->wireaddrs = tal_arr(ld, struct ipaddr, 0); ld->portnum = DEFAULT_PORT; timers_init(&ld->timers, time_mono()); ld->topology = new_topology(ld, ld->log); diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index 4bd37cd4b..89c4b5408 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -62,9 +62,6 @@ struct config { /* How long between changing commit and sending COMMIT message. */ struct timerel commit_time; - /* IPv4 or IPv6 address to announce to the network */ - struct ipaddr ipaddr; - /* Disable automatic reconnects */ bool no_reconnect; }; @@ -97,6 +94,9 @@ struct lightningd { /* Port we're listening on */ u16 portnum; + /* Addresses to announce to the network (tal_count()) */ + struct ipaddr *wireaddrs; + /* Bearer of all my secrets. */ int hsm_fd; diff --git a/lightningd/options.c b/lightningd/options.c index 92d44b17c..bc726d687 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -118,7 +118,7 @@ static char *opt_set_s32(const char *arg, s32 *u) } /* FIXME: Rename ipaddr and hoist up */ -bool parse_ipaddr(const char *arg, struct ipaddr *addr) +bool parse_ipaddr(const char *arg, struct ipaddr *addr, u16 port) { struct in6_addr v6; struct in_addr v4; @@ -133,20 +133,26 @@ bool parse_ipaddr(const char *arg, struct ipaddr *addr) if (inet_pton(AF_INET, arg, &v4) == 1) { addr->type = ADDR_TYPE_IPV4; addr->addrlen = 4; + addr->port = port; memcpy(&addr->addr, &v4, addr->addrlen); return true; } else if (inet_pton(AF_INET6, arg, &v6) == 1) { addr->type = ADDR_TYPE_IPV6; addr->addrlen = 16; + addr->port = port; memcpy(&addr->addr, &v6, addr->addrlen); return true; } return false; } -static char *opt_set_ipaddr(const char *arg, struct ipaddr *addr) +static char *opt_add_ipaddr(const char *arg, struct lightningd *ld) { - if (parse_ipaddr(arg, addr)) + size_t n = tal_count(ld->wireaddrs); + + tal_resize(&ld->wireaddrs, n+1); + + if (parse_ipaddr(arg, &ld->wireaddrs[n], ld->portnum)) return NULL; return tal_fmt(NULL, "Unable to parse IP address '%s'", arg); @@ -275,9 +281,9 @@ static void config_register_opts(struct lightningd *ld) opt_register_noarg("--no-reconnect", opt_set_bool, &ld->config.no_reconnect, "Disable automatic reconnect attempts"); - opt_register_arg("--ipaddr", opt_set_ipaddr, NULL, - &ld->config.ipaddr, - "Set the IP address (v4 or v6) to announce to the network for incoming connections"); + 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_early_arg("--network", opt_set_network, opt_show_network, ld, @@ -366,9 +372,6 @@ static const struct config testnet_config = { /* Take 0.001% */ .fee_per_satoshi = 10, - /* Do not advertise any IP */ - .ipaddr.type = 0, - /* Automatically reconnect */ .no_reconnect = false, }; @@ -427,9 +430,6 @@ static const struct config mainnet_config = { /* Take 0.001% */ .fee_per_satoshi = 10, - /* Do not advertise any IP */ - .ipaddr.type = 0, - /* Automatically reconnect */ .no_reconnect = false, }; @@ -631,7 +631,6 @@ bool handle_opts(struct lightningd *ld, int argc, char *argv[]) /* Now look for config file */ opt_parse_from_config(ld); - ld->config.ipaddr.port = ld->portnum; opt_parse(&argc, argv, opt_log_stderr_exit); if (argc != 1) errx(1, "no arguments accepted"); diff --git a/lightningd/options.h b/lightningd/options.h index dab0e3818..2519a8c53 100644 --- a/lightningd/options.h +++ b/lightningd/options.h @@ -13,7 +13,7 @@ void register_opts(struct lightningd *ld); */ bool handle_opts(struct lightningd *ld, int argc, char *argv[]); -bool parse_ipaddr(const char *arg, struct ipaddr *addr); +bool parse_ipaddr(const char *arg, struct ipaddr *addr, u16 port); /* Derive default color and alias from the pubkey. */ void setup_color_and_alias(struct lightningd *ld); diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 566b26444..2d0458c31 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -741,7 +741,7 @@ static void json_connect(struct command *cmd, port = tal_strdup(cmd, stringify(DEFAULT_PORT)); } addr.port = atoi(port); - if (!parse_ipaddr(name, &addr) || !addr.port) + if (!parse_ipaddr(name, &addr, addr.port) || !addr.port) command_fail(cmd, "host %s:%s not valid", name, port); /* Tell it about the address. */ @@ -1472,13 +1472,14 @@ static u8 *create_node_announcement(const tal_t *ctx, struct lightningd *ld, u8 *features = NULL; u8 *addresses = tal_arr(ctx, u8, 0); u8 *announcement; + size_t i; if (!sig) { sig = tal(ctx, secp256k1_ecdsa_signature); memset(sig, 0, sizeof(*sig)); } - if (ld->config.ipaddr.type != ADDR_TYPE_PADDING) { - towire_ipaddr(&addresses, &ld->config.ipaddr); - } + for (i = 0; i < tal_count(ld->wireaddrs); i++) + towire_ipaddr(&addresses, ld->wireaddrs+i); + announcement = towire_node_announcement(ctx, sig, features, timestamp, &ld->id, ld->rgb, (u8 *)ld->alias,