mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-07 14:29:33 +01:00
c71e16f784
Make the update/announce messages own the element in the broadcast map not the other way around. Then we keep a pointer to the message, and when we free it (eg. channel closed, update replaces it), it gets freed from the broadcast map automatically. The result is much nicer! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
26 lines
839 B
C
26 lines
839 B
C
#ifndef LIGHTNING_GOSSIPD_BROADCAST_H
|
|
#define LIGHTNING_GOSSIPD_BROADCAST_H
|
|
#include "config.h"
|
|
|
|
#include <ccan/intmap/intmap.h>
|
|
#include <ccan/list/list.h>
|
|
#include <ccan/short_types/short_types.h>
|
|
#include <ccan/tal/tal.h>
|
|
|
|
/* Common functionality to implement staggered broadcasts with replacement. */
|
|
|
|
struct broadcast_state {
|
|
u64 next_index;
|
|
UINTMAP(struct queued_message *) broadcasts;
|
|
};
|
|
|
|
struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
|
|
|
/* Append a queued message for broadcast. Freeing the msg will remove it. */
|
|
void insert_broadcast(struct broadcast_state *bstate, const u8 *msg);
|
|
|
|
/* Return the broadcast with index >= *last_index, and update *last_index.
|
|
* There's no broadcast with index 0. */
|
|
const u8 *next_broadcast(struct broadcast_state *bstate, u64 *last_index);
|
|
#endif /* LIGHTNING_GOSSIPD_BROADCAST_H */
|