Browse Source

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 <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
2d919d56cb
  1. 18
      gossipd/broadcast.c
  2. 11
      gossipd/broadcast.h
  3. 16
      gossipd/gossip.c

18
gossipd/broadcast.c

@ -1,6 +1,14 @@
#include <ccan/mem/mem.h>
#include <gossipd/broadcast.h>
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)

11
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 */

16
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;
}

Loading…
Cancel
Save