Skip to content

Commit 7fc214a

Browse files
endothermicdevrustyrussell
authored andcommitted
gossipd: add request to connect to new gossip peer
Gossipd uses this to ask lightningd -> connectd to initiate a connection to a new gossip peer. This can be used when there are insufficient peers already connected to gossip with. Changelog-Changed: Gossipd can now request connections to additional nodes for improved gossip sync
1 parent 9cba417 commit 7fc214a

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

gossipd/gossipd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ static struct io_plan *recv_req(struct io_conn *conn,
636636
case WIRE_GOSSIPD_NEW_BLOCKHEIGHT_REPLY:
637637
case WIRE_GOSSIPD_GET_ADDRS_REPLY:
638638
case WIRE_GOSSIPD_REMOTE_CHANNEL_UPDATE:
639+
case WIRE_GOSSIPD_CONNECT_TO_PEER:
639640
break;
640641
}
641642

gossipd/gossipd_wire.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ subtypedata,peer_update,htlc_maximum_msat,amount_msat,
9090
msgtype,gossipd_remote_channel_update,3010
9191
msgdata,gossipd_remote_channel_update,source_node,?node_id,
9292
msgdata,gossipd_remote_channel_update,peer_update,peer_update,
93+
94+
# Ask lightningd to connect to a peer.
95+
msgtype,gossipd_connect_to_peer,3011
96+
msgdata,gossipd_connect_to_peer,id,node_id,
97+
msgdata,gossipd_connect_to_peer,num,u16,
98+
msgdata,gossipd_connect_to_peer,addrs,wireaddr,num,

gossipd/seeker.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,20 @@ static bool seek_any_unknown_nodes(struct seeker *seeker)
963963
return true;
964964
}
965965

966+
/* Ask lightningd for more peers if we're short on gossip streamers. */
967+
static void maybe_get_new_peer(struct seeker *seeker)
968+
{
969+
size_t connected_peers = peer_node_id_map_count(seeker->daemon->peers);
970+
if (connected_peers < tal_count(seeker->gossiper)) {
971+
status_debug("seeker: have only %zu connected peers."
972+
" Should connect to more.",
973+
connected_peers);
974+
975+
}
976+
/* TODO: find random node announcement, see if we can connect,
977+
* ask lightningd to connect via towire_gossipd_connect_to_peer. */
978+
}
979+
966980
/* Periodic timer to see how our gossip is going. */
967981
static void seeker_check(struct seeker *seeker)
968982
{
@@ -988,6 +1002,7 @@ static void seeker_check(struct seeker *seeker)
9881002
break;
9891003
case NORMAL:
9901004
/* FIXME: maybe_get_more_peers(seeker); */
1005+
maybe_get_new_peer(seeker);
9911006
maybe_rotate_gossipers(seeker);
9921007
if (!seek_any_unknown_scids(seeker)
9931008
&& !seek_any_stale_scids(seeker))

lightningd/gossip_control.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ static void handle_peer_update_data(struct lightningd *ld, const u8 *msg)
172172
channel_gossip_set_remote_update(ld, &update, source);
173173
}
174174

175+
/* gossipd would like a connection to this peer for more gossiping. */
176+
static void handle_connect_to_peer(struct subd *gossip, const u8 *msg)
177+
{
178+
struct node_id *id = tal(tmpctx, struct node_id);
179+
struct wireaddr *addrs;
180+
if (!fromwire_gossipd_connect_to_peer(tmpctx, msg, id, &addrs))
181+
log_broken(gossip->ld->log, "malformed peer connect request"
182+
" from gossipd %s", tal_hex(msg, msg));
183+
else
184+
log_debug(gossip->ld->log, "asked to connect to %s",
185+
fmt_node_id(msg, id));
186+
/* TODO: send node_id and address to connectd. */
187+
}
188+
175189
static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
176190
{
177191
enum gossipd_wire t = fromwire_peektype(msg);
@@ -208,6 +222,9 @@ static unsigned gossip_msg(struct subd *gossip, const u8 *msg, const int *fds)
208222
handle_peer_update_data(gossip->ld, msg);
209223
tal_free(msg);
210224
break;
225+
case WIRE_GOSSIPD_CONNECT_TO_PEER:
226+
/* Please try connecting to this peer for more gossip. */
227+
handle_connect_to_peer(gossip, msg);
211228
}
212229
return 0;
213230
}

0 commit comments

Comments
 (0)