From 8912272983e02182efd00f1c60172de785d3c192 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 8 Feb 2017 14:05:21 +0100 Subject: [PATCH] gossip: Prevent normal messages to trigger the staggered broadcast Only call `peer_dump_gossip` if the broadcast timer actually expired. previously it could get triggered by any normal message. --- lightningd/gossip/gossip.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lightningd/gossip/gossip.c b/lightningd/gossip/gossip.c index 97f1965fa..318c4d97e 100644 --- a/lightningd/gossip/gossip.c +++ b/lightningd/gossip/gossip.c @@ -60,6 +60,8 @@ struct peer { /* High water mark for the staggered broadcast */ u64 broadcast_index; u8 **msg_out; + /* Is it time to continue the staggered broadcast? */ + bool gossip_sync; }; static void destroy_peer(struct peer *peer) @@ -158,11 +160,12 @@ static struct io_plan *pkt_out(struct io_conn *conn, struct peer *peer); /* Wake up the outgoing direction of the connection and write any * queued messages. Needed since the `io_wake` method signature does - * not allow us to specify it as the callback for `new_reltimer`. + * not allow us to specify it as the callback for `new_reltimer`, but + * it allows us to set an additional flag for the routing dump.. */ static void wake_pkt_out(struct peer *peer) { - /* */ + peer->gossip_sync = true; io_wake(peer); } @@ -196,8 +199,13 @@ static struct io_plan *pkt_out(struct io_conn *conn, struct peer *peer) return peer_write_message(conn, peer->cs, out, pkt_out); } - /* Send any queued up broadcast messages */ - return peer_dump_gossip(conn, peer); + if (peer->gossip_sync){ + /* Send any queued up broadcast messages */ + peer->gossip_sync = false; + return peer_dump_gossip(conn, peer); + } else { + return io_out_wait(conn, peer, pkt_out, peer); + } } static bool has_even_bit(const u8 *bitmap)