Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connectd memleak fix #5312

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
connectd: use is_msg_gossip_broadcast into gossip_rcvd_filter.c
It was doing its own equivalent check anyway.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 16, 2022
commit 3caa39241dba162bbe8ab9374266d45d4622bdcd
60 changes: 55 additions & 5 deletions connectd/gossip_rcvd_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,63 @@ struct gossip_rcvd_filter *new_gossip_rcvd_filter(const tal_t *ctx)
return f;
}

static bool extract_msg_key(const u8 *msg, u64 *key)
static bool is_msg_gossip_broadcast(const u8 *cursor)
{
int type = fromwire_peektype(msg);
switch ((enum peer_wire)fromwire_peektype(cursor)) {
case WIRE_CHANNEL_ANNOUNCEMENT:
case WIRE_NODE_ANNOUNCEMENT:
case WIRE_CHANNEL_UPDATE:
return true;
case WIRE_QUERY_SHORT_CHANNEL_IDS:
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
case WIRE_QUERY_CHANNEL_RANGE:
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_ONION_MESSAGE:
case WIRE_OBS2_ONION_MESSAGE:
case WIRE_WARNING:
case WIRE_INIT:
case WIRE_PING:
case WIRE_PONG:
case WIRE_ERROR:
case WIRE_OPEN_CHANNEL:
case WIRE_ACCEPT_CHANNEL:
case WIRE_FUNDING_CREATED:
case WIRE_FUNDING_SIGNED:
case WIRE_FUNDING_LOCKED:
case WIRE_SHUTDOWN:
case WIRE_CLOSING_SIGNED:
case WIRE_UPDATE_ADD_HTLC:
case WIRE_UPDATE_FULFILL_HTLC:
case WIRE_UPDATE_FAIL_HTLC:
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
case WIRE_TX_ADD_INPUT:
case WIRE_TX_REMOVE_INPUT:
case WIRE_TX_ADD_OUTPUT:
case WIRE_TX_REMOVE_OUTPUT:
case WIRE_TX_COMPLETE:
case WIRE_TX_SIGNATURES:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
#if EXPERIMENTAL_FEATURES
case WIRE_STFU:
#endif
break;
}
return false;
}

if (type != WIRE_CHANNEL_ANNOUNCEMENT
&& type != WIRE_NODE_ANNOUNCEMENT
&& type != WIRE_CHANNEL_UPDATE)
static bool extract_msg_key(const u8 *msg, u64 *key)
{
if (!is_msg_gossip_broadcast(msg))
return false;

*key = msg_key(msg);
Expand Down
57 changes: 1 addition & 56 deletions connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,68 +640,13 @@ static bool handle_custommsg(struct daemon *daemon,
}
}

static bool is_msg_gossip_broadcast(const u8 *cursor)
{
switch ((enum peer_wire)fromwire_peektype(cursor)) {
case WIRE_CHANNEL_ANNOUNCEMENT:
case WIRE_NODE_ANNOUNCEMENT:
case WIRE_CHANNEL_UPDATE:
return true;
case WIRE_QUERY_SHORT_CHANNEL_IDS:
case WIRE_REPLY_SHORT_CHANNEL_IDS_END:
case WIRE_QUERY_CHANNEL_RANGE:
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_ONION_MESSAGE:
case WIRE_OBS2_ONION_MESSAGE:
case WIRE_WARNING:
case WIRE_INIT:
case WIRE_PING:
case WIRE_PONG:
case WIRE_ERROR:
case WIRE_OPEN_CHANNEL:
case WIRE_ACCEPT_CHANNEL:
case WIRE_FUNDING_CREATED:
case WIRE_FUNDING_SIGNED:
case WIRE_FUNDING_LOCKED:
case WIRE_SHUTDOWN:
case WIRE_CLOSING_SIGNED:
case WIRE_UPDATE_ADD_HTLC:
case WIRE_UPDATE_FULFILL_HTLC:
case WIRE_UPDATE_FAIL_HTLC:
case WIRE_UPDATE_FAIL_MALFORMED_HTLC:
case WIRE_COMMITMENT_SIGNED:
case WIRE_REVOKE_AND_ACK:
case WIRE_UPDATE_FEE:
case WIRE_UPDATE_BLOCKHEIGHT:
case WIRE_CHANNEL_REESTABLISH:
case WIRE_ANNOUNCEMENT_SIGNATURES:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
case WIRE_TX_ADD_INPUT:
case WIRE_TX_REMOVE_INPUT:
case WIRE_TX_ADD_OUTPUT:
case WIRE_TX_REMOVE_OUTPUT:
case WIRE_TX_COMPLETE:
case WIRE_TX_SIGNATURES:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
#if EXPERIMENTAL_FEATURES
case WIRE_STFU:
#endif
break;
}
return false;
}

/* We handle pings and gossip messages. */
static bool handle_message_locally(struct peer *peer, const u8 *msg)
{
enum peer_wire type = fromwire_peektype(msg);

/* We remember these so we don't rexmit them */
if (is_msg_gossip_broadcast(msg))
gossip_rcvd_filter_add(peer->gs.grf, msg);
gossip_rcvd_filter_add(peer->gs.grf, msg);

if (type == WIRE_GOSSIP_TIMESTAMP_FILTER) {
handle_gossip_timestamp_filter_in(peer, msg);
Expand Down