Browse Source

gossip: Removing origin from staggered broadcast

Keeping a pointer to the peer that initially sent us a message
could (actually will!) result in dangling pointers. Removing this
results in some additional messages, which will be discarded by the
recipient, so that should not be a problem.
ppa-0.6.1
Christian Decker 8 years ago
committed by Rusty Russell
parent
commit
95bc8f6987
  1. 14
      daemon/p2p_announce.c

14
daemon/p2p_announce.c

@ -26,9 +26,6 @@ struct queued_message {
u8 *payload; u8 *payload;
struct list_node list; struct list_node list;
/* who told us about this message? */
struct peer *origin;
}; };
u8 ipv4prefix[] = { u8 ipv4prefix[] = {
@ -81,8 +78,7 @@ static void queue_broadcast(struct lightningd_state *dstate,
const int type, const int type,
const u32 timestamp, const u32 timestamp,
const u8 *tag, const u8 *tag,
const u8 *payload, const u8 *payload)
struct peer *origin)
{ {
struct queued_message *el, *msg; struct queued_message *el, *msg;
list_for_each(&dstate->broadcast_queue, el, list) { list_for_each(&dstate->broadcast_queue, el, list) {
@ -94,7 +90,6 @@ static void queue_broadcast(struct lightningd_state *dstate,
el->payload = tal_free(el->payload); el->payload = tal_free(el->payload);
el->payload = tal_dup_arr(el, u8, payload, tal_count(payload), 0); el->payload = tal_dup_arr(el, u8, payload, tal_count(payload), 0);
el->timestamp = timestamp; el->timestamp = timestamp;
el->origin = origin;
return; return;
} }
} }
@ -105,7 +100,6 @@ static void queue_broadcast(struct lightningd_state *dstate,
msg->timestamp = timestamp; msg->timestamp = timestamp;
msg->tag = tal_dup_arr(msg, u8, tag, tal_count(tag), 0); msg->tag = tal_dup_arr(msg, u8, tag, tal_count(tag), 0);
msg->payload = tal_dup_arr(msg, u8, payload, tal_count(payload), 0); msg->payload = tal_dup_arr(msg, u8, payload, tal_count(payload), 0);
msg->origin = origin;
list_add_tail(&dstate->broadcast_queue, &msg->list); list_add_tail(&dstate->broadcast_queue, &msg->list);
} }
@ -172,7 +166,7 @@ void handle_channel_announcement(
towire_channel_id(&tag, &msg->channel_id); towire_channel_id(&tag, &msg->channel_id);
queue_broadcast(peer->dstate, WIRE_CHANNEL_ANNOUNCEMENT, queue_broadcast(peer->dstate, WIRE_CHANNEL_ANNOUNCEMENT,
0, /* `channel_announcement`s do not have a timestamp */ 0, /* `channel_announcement`s do not have a timestamp */
tag, serialized, peer); tag, serialized);
tal_free(msg); tal_free(msg);
} }
@ -228,7 +222,7 @@ void handle_channel_update(struct peer *peer, const struct msg_channel_update *m
WIRE_CHANNEL_UPDATE, WIRE_CHANNEL_UPDATE,
msg->timestamp, msg->timestamp,
tag, tag,
serialized, peer); serialized);
tal_free(c->channel_update); tal_free(c->channel_update);
c->channel_update = tal_dup_arr(c, u8, serialized, tal_count(serialized), 0); c->channel_update = tal_dup_arr(c, u8, serialized, tal_count(serialized), 0);
@ -281,7 +275,7 @@ void handle_node_announcement(
WIRE_NODE_ANNOUNCEMENT, WIRE_NODE_ANNOUNCEMENT,
msg->timestamp, msg->timestamp,
tag, tag,
serialized, peer); serialized);
tal_free(node->node_announcement); tal_free(node->node_announcement);
node->node_announcement = tal_dup_arr(node, u8, serialized, tal_count(serialized), 0); node->node_announcement = tal_dup_arr(node, u8, serialized, tal_count(serialized), 0);
tal_free(msg); tal_free(msg);

Loading…
Cancel
Save