Browse Source

lightningd: support multiple addresses.

Currently only ipv4 and ipv6.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
329269d9d0
  1. 10
      lightningd/jsonrpc.c
  2. 1
      lightningd/lightningd.c
  3. 6
      lightningd/lightningd.h
  4. 25
      lightningd/options.c
  5. 2
      lightningd/options.h
  6. 9
      lightningd/peer_control.c

10
lightningd/jsonrpc.c

@ -248,11 +248,13 @@ static void json_getinfo(struct command *cmd,
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_pubkey(response, "id", &cmd->ld->id); 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_num(response, "port", cmd->ld->portnum);
json_add_string(response, "network", json_array_start(response, "address");
get_chainparams(cmd->ld)->network_name); 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_string(response, "version", version());
json_add_num(response, "blockheight", get_block_height(cmd->ld->topology)); json_add_num(response, "blockheight", get_block_height(cmd->ld->topology));
json_object_end(response); json_object_end(response);

1
lightningd/lightningd.c

@ -79,6 +79,7 @@ static struct lightningd *new_lightningd(const tal_t *ctx,
ld->rgb = NULL; ld->rgb = NULL;
list_head_init(&ld->pay_commands); list_head_init(&ld->pay_commands);
list_head_init(&ld->connects); list_head_init(&ld->connects);
ld->wireaddrs = tal_arr(ld, struct ipaddr, 0);
ld->portnum = DEFAULT_PORT; ld->portnum = DEFAULT_PORT;
timers_init(&ld->timers, time_mono()); timers_init(&ld->timers, time_mono());
ld->topology = new_topology(ld, ld->log); ld->topology = new_topology(ld, ld->log);

6
lightningd/lightningd.h

@ -62,9 +62,6 @@ struct config {
/* How long between changing commit and sending COMMIT message. */ /* How long between changing commit and sending COMMIT message. */
struct timerel commit_time; struct timerel commit_time;
/* IPv4 or IPv6 address to announce to the network */
struct ipaddr ipaddr;
/* Disable automatic reconnects */ /* Disable automatic reconnects */
bool no_reconnect; bool no_reconnect;
}; };
@ -97,6 +94,9 @@ struct lightningd {
/* Port we're listening on */ /* Port we're listening on */
u16 portnum; u16 portnum;
/* Addresses to announce to the network (tal_count()) */
struct ipaddr *wireaddrs;
/* Bearer of all my secrets. */ /* Bearer of all my secrets. */
int hsm_fd; int hsm_fd;

25
lightningd/options.c

@ -118,7 +118,7 @@ static char *opt_set_s32(const char *arg, s32 *u)
} }
/* FIXME: Rename ipaddr and hoist up */ /* 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 in6_addr v6;
struct in_addr v4; 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) { if (inet_pton(AF_INET, arg, &v4) == 1) {
addr->type = ADDR_TYPE_IPV4; addr->type = ADDR_TYPE_IPV4;
addr->addrlen = 4; addr->addrlen = 4;
addr->port = port;
memcpy(&addr->addr, &v4, addr->addrlen); memcpy(&addr->addr, &v4, addr->addrlen);
return true; return true;
} else if (inet_pton(AF_INET6, arg, &v6) == 1) { } else if (inet_pton(AF_INET6, arg, &v6) == 1) {
addr->type = ADDR_TYPE_IPV6; addr->type = ADDR_TYPE_IPV6;
addr->addrlen = 16; addr->addrlen = 16;
addr->port = port;
memcpy(&addr->addr, &v6, addr->addrlen); memcpy(&addr->addr, &v6, addr->addrlen);
return true; return true;
} }
return false; 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 NULL;
return tal_fmt(NULL, "Unable to parse IP address '%s'", arg); 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, opt_register_noarg("--no-reconnect", opt_set_bool,
&ld->config.no_reconnect, "Disable automatic reconnect attempts"); &ld->config.no_reconnect, "Disable automatic reconnect attempts");
opt_register_arg("--ipaddr", opt_set_ipaddr, NULL, opt_register_arg("--ipaddr", opt_add_ipaddr, NULL,
&ld->config.ipaddr, ld,
"Set the IP address (v4 or v6) to announce to the network for incoming connections"); "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, opt_register_early_arg("--network", opt_set_network, opt_show_network,
ld, ld,
@ -366,9 +372,6 @@ static const struct config testnet_config = {
/* Take 0.001% */ /* Take 0.001% */
.fee_per_satoshi = 10, .fee_per_satoshi = 10,
/* Do not advertise any IP */
.ipaddr.type = 0,
/* Automatically reconnect */ /* Automatically reconnect */
.no_reconnect = false, .no_reconnect = false,
}; };
@ -427,9 +430,6 @@ static const struct config mainnet_config = {
/* Take 0.001% */ /* Take 0.001% */
.fee_per_satoshi = 10, .fee_per_satoshi = 10,
/* Do not advertise any IP */
.ipaddr.type = 0,
/* Automatically reconnect */ /* Automatically reconnect */
.no_reconnect = false, .no_reconnect = false,
}; };
@ -631,7 +631,6 @@ bool handle_opts(struct lightningd *ld, int argc, char *argv[])
/* Now look for config file */ /* Now look for config file */
opt_parse_from_config(ld); opt_parse_from_config(ld);
ld->config.ipaddr.port = ld->portnum;
opt_parse(&argc, argv, opt_log_stderr_exit); opt_parse(&argc, argv, opt_log_stderr_exit);
if (argc != 1) if (argc != 1)
errx(1, "no arguments accepted"); errx(1, "no arguments accepted");

2
lightningd/options.h

@ -13,7 +13,7 @@ void register_opts(struct lightningd *ld);
*/ */
bool handle_opts(struct lightningd *ld, int argc, char *argv[]); 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. */ /* Derive default color and alias from the pubkey. */
void setup_color_and_alias(struct lightningd *ld); void setup_color_and_alias(struct lightningd *ld);

9
lightningd/peer_control.c

@ -741,7 +741,7 @@ static void json_connect(struct command *cmd,
port = tal_strdup(cmd, stringify(DEFAULT_PORT)); port = tal_strdup(cmd, stringify(DEFAULT_PORT));
} }
addr.port = atoi(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); command_fail(cmd, "host %s:%s not valid", name, port);
/* Tell it about the address. */ /* 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 *features = NULL;
u8 *addresses = tal_arr(ctx, u8, 0); u8 *addresses = tal_arr(ctx, u8, 0);
u8 *announcement; u8 *announcement;
size_t i;
if (!sig) { if (!sig) {
sig = tal(ctx, secp256k1_ecdsa_signature); sig = tal(ctx, secp256k1_ecdsa_signature);
memset(sig, 0, sizeof(*sig)); memset(sig, 0, sizeof(*sig));
} }
if (ld->config.ipaddr.type != ADDR_TYPE_PADDING) { for (i = 0; i < tal_count(ld->wireaddrs); i++)
towire_ipaddr(&addresses, &ld->config.ipaddr); towire_ipaddr(&addresses, ld->wireaddrs+i);
}
announcement = announcement =
towire_node_announcement(ctx, sig, features, timestamp, towire_node_announcement(ctx, sig, features, timestamp,
&ld->id, ld->rgb, (u8 *)ld->alias, &ld->id, ld->rgb, (u8 *)ld->alias,

Loading…
Cancel
Save