From 2d919d56cb6097c753b534a2baf711631e39a18a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Mar 2018 02:15:55 +1030 Subject: [PATCH] gossipd: make struct queued_message private. Callers don't need it, and when we add timestamps it just makes for more places to change. Signed-off-by: Rusty Russell --- gossipd/broadcast.c | 18 +++++++++++++++--- gossipd/broadcast.h | 11 +---------- gossipd/gossip.c | 16 ++++++++-------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/gossipd/broadcast.c b/gossipd/broadcast.c index fd6b9ab85..4d9bfaf43 100644 --- a/gossipd/broadcast.c +++ b/gossipd/broadcast.c @@ -1,6 +1,14 @@ #include #include +struct queued_message { + /* Broadcast index. */ + u64 index; + + /* Serialized payload */ + const u8 *payload; +}; + struct broadcast_state *new_broadcast_state(tal_t *ctx) { struct broadcast_state *bstate = tal(ctx, struct broadcast_state); @@ -49,10 +57,14 @@ bool replace_broadcast(const tal_t *ctx, return evicted; } -struct queued_message *next_broadcast_message(struct broadcast_state *bstate, - u64 *last_index) +const u8 *next_broadcast(struct broadcast_state *bstate, u64 *last_index) { - return uintmap_after(&bstate->broadcasts, last_index); + struct queued_message *m; + + m = uintmap_after(&bstate->broadcasts, last_index); + if (m) + return m->payload; + return NULL; } const u8 *get_broadcast(struct broadcast_state *bstate, u64 msgidx) diff --git a/gossipd/broadcast.h b/gossipd/broadcast.h index 5deb7c335..6f34b0ecd 100644 --- a/gossipd/broadcast.h +++ b/gossipd/broadcast.h @@ -9,14 +9,6 @@ /* Common functionality to implement staggered broadcasts with replacement. */ -struct queued_message { - /* Broadcast index. */ - u64 index; - - /* Serialized payload */ - const u8 *payload; -}; - struct broadcast_state { u64 next_index; UINTMAP(struct queued_message *) broadcasts; @@ -34,8 +26,7 @@ bool replace_broadcast(const tal_t *ctx, const u8 *payload TAKES); -struct queued_message *next_broadcast_message(struct broadcast_state *bstate, - u64 *last_index); +const u8 *next_broadcast(struct broadcast_state *bstate, u64 *last_index); const u8 *get_broadcast(struct broadcast_state *bstate, u64 msgidx); #endif /* LIGHTNING_LIGHTNINGD_GOSSIP_BROADCAST_H */ diff --git a/gossipd/gossip.c b/gossipd/gossip.c index 652415fd1..76aca5685 100644 --- a/gossipd/gossip.c +++ b/gossipd/gossip.c @@ -708,14 +708,14 @@ static struct io_plan *peer_pkt_out(struct io_conn *conn, struct peer *peer) return ready_for_master(conn, peer); } else if (peer->gossip_sync) { /* If we're supposed to be sending gossip, do so now. */ - struct queued_message *next; + const u8 *next; - next = next_broadcast_message(peer->daemon->rstate->broadcasts, - &peer->broadcast_index); + next = next_broadcast(peer->daemon->rstate->broadcasts, + &peer->broadcast_index); if (next) return peer_write_message(conn, &peer->local->pcs, - next->payload, + next, peer_pkt_out); /* Gossip is drained. Wait for next timer. */ @@ -915,7 +915,7 @@ static bool send_peer_with_fds(struct peer *peer, const u8 *msg) */ static bool nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc) { - struct queued_message *next; + const u8 *next; struct peer *peer = dc->ctx; @@ -926,8 +926,8 @@ static bool nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc) if (!peer->gossip_sync) return false; - next = next_broadcast_message(peer->daemon->rstate->broadcasts, - &peer->broadcast_index); + next = next_broadcast(peer->daemon->rstate->broadcasts, + &peer->broadcast_index); if (!next) { peer->gossip_sync = false; @@ -935,7 +935,7 @@ static bool nonlocal_dump_gossip(struct io_conn *conn, struct daemon_conn *dc) } else { u8 *msg = towire_gossip_send_gossip(conn, peer->broadcast_index, - next->payload); + next); daemon_conn_send(peer->remote, take(msg)); return true; }