connectd: divert gossip messages directly to gossipd.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-01-25 06:38:52 +10:30
parent 9983c2fd8e
commit d7cf38a80a
2 changed files with 24 additions and 23 deletions

View File

@ -6,6 +6,7 @@
#include <bitcoin/chainparams.h>
#include <ccan/io/io.h>
#include <common/cryptomsg.h>
#include <common/daemon_conn.h>
#include <common/dev_disconnect.h>
#include <common/features.h>
#include <common/gossip_constants.h>
@ -18,6 +19,7 @@
#include <common/utils.h>
#include <common/wire_error.h>
#include <connectd/connectd.h>
#include <connectd/connectd_gossipd_wiregen.h>
#include <connectd/multiplex.h>
#include <errno.h>
#include <fcntl.h>
@ -29,6 +31,7 @@
#include <wire/peer_wire.h>
#include <wire/wire.h>
#include <wire/wire_io.h>
#include <wire/wire_sync.h>
void queue_peer_msg(struct peer *peer, const u8 *msg TAKES)
{
@ -334,7 +337,7 @@ again:
return NULL;
}
/* We only handle gossip_timestamp_filter for now */
/* We handle gossip_timestamp_filter, and divert other gossip msgs to gossipd */
static bool handle_message_locally(struct peer *peer, const u8 *msg)
{
struct bitcoin_blkid chain_hash;
@ -347,6 +350,18 @@ static bool handle_message_locally(struct peer *peer, const u8 *msg)
if (!fromwire_gossip_timestamp_filter(msg, &chain_hash,
&first_timestamp,
&timestamp_range)) {
/* Do we want to divert to gossipd? */
if (is_msg_for_gossipd(msg)) {
u8 *gmsg = towire_gossipd_recv_gossip(NULL,
&peer->id, msg);
/* gossipd doesn't log IO, so we log it here. */
status_peer_io(LOG_IO_IN, &peer->id, msg);
daemon_conn_send(peer->daemon->gossipd, take(gmsg));
return true;
}
return false;
}

View File

@ -682,27 +682,6 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
/* These are messages relayed from peer */
switch ((enum peer_wire)fromwire_peektype(msg)) {
case WIRE_CHANNEL_ANNOUNCEMENT:
err = handle_channel_announcement_msg(peer->daemon, peer, msg);
goto handled_relay;
case WIRE_CHANNEL_UPDATE:
err = handle_channel_update_msg(peer, msg);
goto handled_relay;
case WIRE_NODE_ANNOUNCEMENT:
err = handle_node_announce(peer, msg);
goto handled_relay;
case WIRE_QUERY_CHANNEL_RANGE:
err = handle_query_channel_range(peer, msg);
goto handled_relay;
case WIRE_REPLY_CHANNEL_RANGE:
err = handle_reply_channel_range(peer, msg);
goto handled_relay;
case WIRE_QUERY_SHORT_CHANNEL_IDS:
err = handle_query_short_channel_ids(peer, msg);
goto handled_relay;
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
err = handle_reply_short_channel_ids_end(peer, msg);
goto handled_relay;
case WIRE_OBS2_ONION_MESSAGE:
err = handle_obs2_onion_message(peer, msg);
goto handled_relay;
@ -710,7 +689,14 @@ static struct io_plan *peer_msg_in(struct io_conn *conn,
err = handle_onion_message(peer, msg);
goto handled_relay;
/* These are non-gossip messages (!is_msg_for_gossipd()) */
/* These are not sent by peer (connectd sends us gossip msgs) */
case WIRE_CHANNEL_ANNOUNCEMENT:
case WIRE_CHANNEL_UPDATE:
case WIRE_NODE_ANNOUNCEMENT:
case WIRE_QUERY_CHANNEL_RANGE:
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_QUERY_SHORT_CHANNEL_IDS:
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
case WIRE_WARNING:
case WIRE_INIT:
case WIRE_ERROR: