Skip to content

Commit

Permalink
gossipd: rename remote_addr to discovered_ip within gossipd
Browse files Browse the repository at this point in the history
This is cleaner because, the `remote_addr` and `discovered_ip` are
related but two different things.

Within connectd and lightningd we use the peers `remote_addr` feature
to validate (and guess a port) to be used for IP discovery.

Also when a peer reports us a `remote_addr`, this is given to the plugin API
via the `peer_connected` hook. The network port here is not modified for
godd reason! This can be used i.e. to detect if we are behind a NAT.

But once lightningd figures enough peers report the same `remote_addr`,
it sets the port to the selected network and tells gossipd to use that for
`node_announcement` updates.

Hence, within gossipd, there is no (should not be) `remote_addr`.

Changelog-None
  • Loading branch information
m-schmoock committed Sep 13, 2022
1 parent bcb6d32 commit b842571
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 53 deletions.
16 changes: 8 additions & 8 deletions gossipd/gossip_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
for (i = 0; i < count_announceable; i++)
tal_arr_expand(&was, daemon->announceable[i]);

/* Add IP discovery `remote_addr` v4 and v6 of our self. */
/* Add discovered IPs v4/v6 verified by peer `remote_addr` feature. */
/* Only do that if we don't have addresses announced. */
if (count_announceable == 0) {
if (daemon->remote_addr_v4 != NULL &&
!wireaddr_arr_contains(was, daemon->remote_addr_v4))
tal_arr_expand(&was, *daemon->remote_addr_v4);
if (daemon->remote_addr_v6 != NULL &&
!wireaddr_arr_contains(was, daemon->remote_addr_v6))
tal_arr_expand(&was, *daemon->remote_addr_v6);
if (daemon->discovered_ip_v4 != NULL &&
!wireaddr_arr_contains(was, daemon->discovered_ip_v4))
tal_arr_expand(&was, *daemon->discovered_ip_v4);
if (daemon->discovered_ip_v6 != NULL &&
!wireaddr_arr_contains(was, daemon->discovered_ip_v6))
tal_arr_expand(&was, *daemon->discovered_ip_v6);
}

/* Sort by address type again, as we added dynamic remote_addr v4/v6. */
/* Sort by address type again, as we added dynamic discovered_ip v4/v6. */
/* BOLT #7:
*
* The origin node:
Expand Down
46 changes: 23 additions & 23 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,33 +341,33 @@ static void handle_local_private_channel(struct daemon *daemon, const u8 *msg)
}
}

/* lightningd tells us it has dicovered and verified new `remote_addr`.
/* lightningd tells us it has discovered and verified new `remote_addr`.
* We can use this to update our node announcement. */
static void handle_remote_addr(struct daemon *daemon, const u8 *msg)
static void handle_discovered_ip(struct daemon *daemon, const u8 *msg)
{
struct wireaddr remote_addr;
struct wireaddr discovered_ip;

if (!fromwire_gossipd_remote_addr(msg, &remote_addr))
master_badmsg(WIRE_GOSSIPD_REMOTE_ADDR, msg);
if (!fromwire_gossipd_discovered_ip(msg, &discovered_ip))
master_badmsg(WIRE_GOSSIPD_DISCOVERED_IP, msg);

switch (remote_addr.type) {
switch (discovered_ip.type) {
case ADDR_TYPE_IPV4:
if (daemon->remote_addr_v4 != NULL &&
wireaddr_eq_without_port(daemon->remote_addr_v4,
&remote_addr))
if (daemon->discovered_ip_v4 != NULL &&
wireaddr_eq_without_port(daemon->discovered_ip_v4,
&discovered_ip))
break;
tal_free(daemon->remote_addr_v4);
daemon->remote_addr_v4 = tal_dup(daemon, struct wireaddr,
&remote_addr);
tal_free(daemon->discovered_ip_v4);
daemon->discovered_ip_v4 = tal_dup(daemon, struct wireaddr,
&discovered_ip);
goto update_node_annoucement;
case ADDR_TYPE_IPV6:
if (daemon->remote_addr_v6 != NULL &&
wireaddr_eq_without_port(daemon->remote_addr_v6,
&remote_addr))
if (daemon->discovered_ip_v6 != NULL &&
wireaddr_eq_without_port(daemon->discovered_ip_v6,
&discovered_ip))
break;
tal_free(daemon->remote_addr_v6);
daemon->remote_addr_v6 = tal_dup(daemon, struct wireaddr,
&remote_addr);
tal_free(daemon->discovered_ip_v6);
daemon->discovered_ip_v6 = tal_dup(daemon, struct wireaddr,
&discovered_ip);
goto update_node_annoucement;

/* ignore all other cases */
Expand All @@ -381,7 +381,7 @@ static void handle_remote_addr(struct daemon *daemon, const u8 *msg)

update_node_annoucement:
status_debug("Update our node_announcement for discovered address: %s",
fmt_wireaddr(tmpctx, &remote_addr));
fmt_wireaddr(tmpctx, &discovered_ip));
maybe_send_own_node_announce(daemon, false);
}

Expand Down Expand Up @@ -1038,8 +1038,8 @@ static struct io_plan *recv_req(struct io_conn *conn,
handle_local_private_channel(daemon, msg);
goto done;

case WIRE_GOSSIPD_REMOTE_ADDR:
handle_remote_addr(daemon, msg);
case WIRE_GOSSIPD_DISCOVERED_IP:
handle_discovered_ip(daemon, msg);
goto done;
#if DEVELOPER
case WIRE_GOSSIPD_DEV_SET_MAX_SCIDS_ENCODE_SIZE:
Expand Down Expand Up @@ -1097,8 +1097,8 @@ int main(int argc, char *argv[])
daemon->node_announce_regen_timer = NULL;
daemon->current_blockheight = 0; /* i.e. unknown */
daemon->rates = NULL;
daemon->remote_addr_v4 = NULL;
daemon->remote_addr_v6 = NULL;
daemon->discovered_ip_v4 = NULL;
daemon->discovered_ip_v6 = NULL;
list_head_init(&daemon->deferred_updates);

/* Tell the ecdh() function how to talk to hsmd */
Expand Down
4 changes: 2 additions & 2 deletions gossipd/gossipd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ struct daemon {
struct wireaddr *announceable;

/* verified remote_addr as reported by recent peers */
struct wireaddr *remote_addr_v4;
struct wireaddr *remote_addr_v6;
struct wireaddr *discovered_ip_v4;
struct wireaddr *discovered_ip_v6;

/* Timer until we can send an updated node_announcement */
struct oneshot *node_announce_timer;
Expand Down
6 changes: 3 additions & 3 deletions gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ msgdata,gossipd_local_private_channel,features,u8,len
msgtype,gossipd_used_local_channel_update,3052
msgdata,gossipd_used_local_channel_update,scid,short_channel_id,

# Tell gossipd we have discovered a new remote_addr
msgtype,gossipd_remote_addr,3009
msgdata,gossipd_remote_addr,remote_addr,wireaddr,
# Tell gossipd we have verified a new public IP by the remote_addr feature
msgtype,gossipd_discovered_ip,3009
msgdata,gossipd_discovered_ip,discovered_ip,wireaddr,
2 changes: 1 addition & 1 deletion lightningd/gossip_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
case WIRE_GOSSIPD_ADDGOSSIP_REPLY:
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
case WIRE_GOSSIPD_REMOTE_ADDR:
case WIRE_GOSSIPD_DISCOVERED_IP:
break;

case WIRE_GOSSIPD_GET_TXOUT:
Expand Down
4 changes: 2 additions & 2 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ static void update_remote_addr(struct lightningd *ld,
ld->discovered_ip_v4 = tal_dup(ld, struct wireaddr,
ld->remote_addr_v4);
ld->discovered_ip_v4->port = public_port;
subd_send_msg(ld->gossip, towire_gossipd_remote_addr(
subd_send_msg(ld->gossip, towire_gossipd_discovered_ip(
tmpctx,
ld->discovered_ip_v4));
}
Expand All @@ -1326,7 +1326,7 @@ static void update_remote_addr(struct lightningd *ld,
ld->discovered_ip_v6 = tal_dup(ld, struct wireaddr,
ld->remote_addr_v6);
ld->discovered_ip_v6->port = public_port;
subd_send_msg(ld->gossip, towire_gossipd_remote_addr(
subd_send_msg(ld->gossip, towire_gossipd_discovered_ip(
tmpctx,
ld->discovered_ip_v6));
}
Expand Down
9 changes: 3 additions & 6 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,6 @@ struct channel *find_channel_by_scid(const struct peer *peer UNNEEDED,
struct plugin *find_plugin_for_command(struct lightningd *ld UNNEEDED,
const char *cmd_name UNNEEDED)
{ fprintf(stderr, "find_plugin_for_command called!\n"); abort(); }
/* Generated stub for fixup_htlcs_out */
void fixup_htlcs_out(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "fixup_htlcs_out called!\n"); abort(); }
/* Generated stub for fromwire_bigsize */
bigsize_t fromwire_bigsize(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_bigsize called!\n"); abort(); }
Expand Down Expand Up @@ -733,9 +730,9 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
const struct channel_id *channel UNNEEDED,
const char *fmt UNNEEDED, ...)
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
/* Generated stub for towire_gossipd_remote_addr */
u8 *towire_gossipd_remote_addr(const tal_t *ctx UNNEEDED, const struct wireaddr *remote_addr UNNEEDED)
{ fprintf(stderr, "towire_gossipd_remote_addr called!\n"); abort(); }
/* Generated stub for towire_gossipd_discovered_ip */
u8 *towire_gossipd_discovered_ip(const tal_t *ctx UNNEEDED, const struct wireaddr *discovered_ip UNNEEDED)
{ fprintf(stderr, "towire_gossipd_discovered_ip called!\n"); abort(); }
/* Generated stub for towire_hsmd_sign_bolt12 */
u8 *towire_hsmd_sign_bolt12(const tal_t *ctx UNNEEDED, const wirestring *messagename UNNEEDED, const wirestring *fieldname UNNEEDED, const struct sha256 *merkleroot UNNEEDED, const u8 *publictweak UNNEEDED)
{ fprintf(stderr, "towire_hsmd_sign_bolt12 called!\n"); abort(); }
Expand Down
11 changes: 3 additions & 8 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,6 @@ struct command_result *param_short_channel_id(struct command *cmd UNNEEDED,
const jsmntok_t *tok UNNEEDED,
struct short_channel_id **scid UNNEEDED)
{ fprintf(stderr, "param_short_channel_id called!\n"); abort(); }
/* Generated stub for param_string */
struct command_result *param_string(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char * buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
const char **str UNNEEDED)
{ fprintf(stderr, "param_string called!\n"); abort(); }
/* Generated stub for parse_onionpacket */
struct onionpacket *parse_onionpacket(const tal_t *ctx UNNEEDED,
const u8 *src UNNEEDED,
Expand Down Expand Up @@ -774,9 +769,9 @@ u8 *towire_final_incorrect_cltv_expiry(const tal_t *ctx UNNEEDED, u32 cltv_expir
/* Generated stub for towire_final_incorrect_htlc_amount */
u8 *towire_final_incorrect_htlc_amount(const tal_t *ctx UNNEEDED, struct amount_msat incoming_htlc_amt UNNEEDED)
{ fprintf(stderr, "towire_final_incorrect_htlc_amount called!\n"); abort(); }
/* Generated stub for towire_gossipd_remote_addr */
u8 *towire_gossipd_remote_addr(const tal_t *ctx UNNEEDED, const struct wireaddr *remote_addr UNNEEDED)
{ fprintf(stderr, "towire_gossipd_remote_addr called!\n"); abort(); }
/* Generated stub for towire_gossipd_discovered_ip */
u8 *towire_gossipd_discovered_ip(const tal_t *ctx UNNEEDED, const struct wireaddr *discovered_ip UNNEEDED)
{ fprintf(stderr, "towire_gossipd_discovered_ip called!\n"); abort(); }
/* Generated stub for towire_hsmd_get_output_scriptpubkey */
u8 *towire_hsmd_get_output_scriptpubkey(const tal_t *ctx UNNEEDED, u64 channel_id UNNEEDED, const struct node_id *peer_id UNNEEDED, const struct pubkey *commitment_point UNNEEDED)
{ fprintf(stderr, "towire_hsmd_get_output_scriptpubkey called!\n"); abort(); }
Expand Down

0 comments on commit b842571

Please sign in to comment.