Skip to content

Commit

Permalink
gossip: pass ip_discovery as enum
Browse files Browse the repository at this point in the history
  • Loading branch information
m-schmoock committed Dec 21, 2022
1 parent 701a201 commit 7a7adaf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion gossipd/gossip_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "config.h"
#include <ccan/asort/asort.h>
#include <ccan/cast/cast.h>
#include <ccan/ccan/opt/opt.h>
#include <ccan/mem/mem.h>
#include <common/daemon_conn.h>
#include <common/features.h>
Expand Down Expand Up @@ -46,7 +47,8 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
/* Add discovered IPs v4/v6 verified by peer `remote_addr` feature. */
/* Only do that if we don't have any addresses announced or
* `config.ip_discovery` is explicitly enabled. */
if (count_announceable == 0 || daemon->ip_discovery) {
if ((daemon->ip_discovery == OPT_AUTOBOOL_AUTO && count_announceable == 0) ||
daemon->ip_discovery == OPT_AUTOBOOL_TRUE) {
if (daemon->discovered_ip_v4 != NULL &&
!wireaddr_arr_contains(was, daemon->discovered_ip_v4))
tal_arr_expand(&was, *daemon->discovered_ip_v4);
Expand Down
4 changes: 2 additions & 2 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ static void handle_discovered_ip(struct daemon *daemon, const u8 *msg)
return;

update_node_annoucement:
if (daemon->ip_discovery)
if (daemon->ip_discovery == OPT_AUTOBOOL_TRUE)
status_debug("Update our node_announcement for discovered address: %s",
fmt_wireaddr(tmpctx, &discovered_ip));
maybe_send_own_node_announce(daemon, false);
Expand Down Expand Up @@ -1098,7 +1098,7 @@ int main(int argc, char *argv[])
daemon->rates = NULL;
daemon->discovered_ip_v4 = NULL;
daemon->discovered_ip_v6 = NULL;
daemon->ip_discovery = false;
daemon->ip_discovery = OPT_AUTOBOOL_AUTO;
list_head_init(&daemon->deferred_updates);

/* Tell the ecdh() function how to talk to hsmd */
Expand Down
3 changes: 2 additions & 1 deletion gossipd/gossipd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LIGHTNING_GOSSIPD_GOSSIPD_H
#define LIGHTNING_GOSSIPD_GOSSIPD_H
#include "config.h"
#include <ccan/ccan/opt/opt.h>
#include <ccan/timer/timer.h>
#include <common/node_id.h>
#include <wire/peer_wire.h>
Expand Down Expand Up @@ -51,7 +52,7 @@ struct daemon {
/* verified remote_addr as reported by recent peers */
struct wireaddr *discovered_ip_v4;
struct wireaddr *discovered_ip_v6;
bool ip_discovery;
enum opt_autobool ip_discovery;

/* Timer until we can send an updated node_announcement */
struct oneshot *node_announce_timer;
Expand Down
2 changes: 1 addition & 1 deletion gossipd/gossipd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ msgdata,gossipd_init,announceable,wireaddr,num_announceable
msgdata,gossipd_init,dev_gossip_time,?u32,
msgdata,gossipd_init,dev_fast_gossip,bool,
msgdata,gossipd_init,dev_fast_gossip_prune,bool,
msgdata,gossipd_init,ip_discovery,bool,
msgdata,gossipd_init,ip_discovery,u32,

msgtype,gossipd_init_reply,3100

Expand Down
3 changes: 2 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def test_remote_addr(node_factory, bitcoind):
# don't announce anything per se
opts = {'may_reconnect': True,
'dev-allow-localhost': None,
'dev-no-reconnect': None}
'dev-no-reconnect': None,
'ip-discovery': True}
l1, l2, l3 = node_factory.get_nodes(3, opts)

# Disable announcing local autobind addresses with dev-allow-localhost.
Expand Down

0 comments on commit 7a7adaf

Please sign in to comment.