2017-08-28 18:06:01 +02:00
|
|
|
#ifndef LIGHTNING_LIGHTNINGD_GOSSIP_BROADCAST_H
|
|
|
|
#define LIGHTNING_LIGHTNINGD_GOSSIP_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;
|
2017-01-26 22:47:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct broadcast_state *new_broadcast_state(tal_t *ctx);
|
|
|
|
|
2018-01-31 17:52:12 +01:00
|
|
|
/* Replace a queued message with @index, if it matches the type and
|
|
|
|
* tag for the new message. The new message will be queued with the
|
|
|
|
* next highest index. @index is updated to hold the index of the
|
|
|
|
* newly queued message*/
|
2018-03-13 16:38:55 +01:00
|
|
|
bool replace_broadcast(const tal_t *ctx,
|
|
|
|
struct broadcast_state *bstate,
|
2018-01-31 17:52:12 +01:00
|
|
|
u64 *index,
|
2018-03-13 16:39:55 +01:00
|
|
|
const u8 *payload TAKES);
|
2018-01-31 17:52:12 +01:00
|
|
|
|
|
|
|
|
2018-03-13 16:45:55 +01:00
|
|
|
const u8 *next_broadcast(struct broadcast_state *bstate, u64 *last_index);
|
2017-01-26 22:47:52 +01:00
|
|
|
|
2018-03-13 16:40:55 +01:00
|
|
|
const u8 *get_broadcast(struct broadcast_state *bstate, u64 msgidx);
|
2017-08-28 18:06:01 +02:00
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_GOSSIP_BROADCAST_H */
|