2018-03-22 11:36:25 +01:00
|
|
|
#ifndef LIGHTNING_GOSSIPD_BROADCAST_H
|
|
|
|
#define LIGHTNING_GOSSIPD_BROADCAST_H
|
2017-01-26 22:47:52 +01:00
|
|
|
#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 {
|
2018-03-13 16:35:55 +01:00
|
|
|
u64 next_index;
|
2018-01-31 17:52:12 +01:00
|
|
|
UINTMAP(struct queued_message *) broadcasts;
|
2018-05-30 18:13:22 +02:00
|
|
|
size_t count;
|
2017-01-26 22:47:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
|
|
|
|
2018-05-10 14:22:37 +02:00
|
|
|
/* Append a queued message for broadcast. Freeing the msg will remove it. */
|
2018-06-08 08:31:49 +02:00
|
|
|
u64 insert_broadcast(struct broadcast_state *bstate, const u8 *msg,
|
|
|
|
u32 timestamp);
|
2018-01-31 17:52:12 +01:00
|
|
|
|
2018-06-08 08:31:51 +02:00
|
|
|
/* Manually delete a broadcast: not usually needed, since destructor does it */
|
|
|
|
void broadcast_del(struct broadcast_state *bstate, u64 index, const u8 *payload);
|
|
|
|
|
2018-06-04 06:26:25 +02:00
|
|
|
/* Return the broadcast with index >= *last_index, timestamp >= min and <= max
|
|
|
|
* and update *last_index.
|
2018-05-10 14:22:37 +02:00
|
|
|
* There's no broadcast with index 0. */
|
2018-06-04 06:26:25 +02:00
|
|
|
const u8 *next_broadcast(struct broadcast_state *bstate,
|
|
|
|
u32 timestamp_min, u32 timestamp_max,
|
|
|
|
u64 *last_index);
|
2018-06-08 08:32:06 +02:00
|
|
|
|
|
|
|
/* Returns b if all OK, otherwise aborts if abortstr non-NULL, otherwise returns
|
|
|
|
* NULL. */
|
|
|
|
struct broadcast_state *broadcast_state_check(struct broadcast_state *b,
|
|
|
|
const char *abortstr);
|
2018-11-21 23:41:49 +01:00
|
|
|
|
2018-03-22 11:36:25 +01:00
|
|
|
#endif /* LIGHTNING_GOSSIPD_BROADCAST_H */
|