2019-05-04 07:53:13 +02:00
|
|
|
#ifndef LIGHTNING_COMMON_GOSSIP_STORE_H
|
|
|
|
#define LIGHTNING_COMMON_GOSSIP_STORE_H
|
|
|
|
#include "config.h"
|
2019-06-03 20:17:25 +02:00
|
|
|
#include <ccan/endian/endian.h>
|
2019-05-04 07:53:13 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
|
2022-01-08 14:28:29 +01:00
|
|
|
struct gossip_state;
|
|
|
|
struct gossip_rcvd_filter;
|
2019-06-03 20:15:25 +02:00
|
|
|
|
2019-05-04 07:53:13 +02:00
|
|
|
/**
|
|
|
|
* gossip_store -- On-disk storage related information
|
|
|
|
*/
|
2022-09-14 05:50:31 +02:00
|
|
|
|
|
|
|
/* First byte of file is the version.
|
|
|
|
*
|
|
|
|
* Top three bits mean incompatible change.
|
2022-09-14 05:50:31 +02:00
|
|
|
* As of this writing, major == 0, minor == 11.
|
2022-09-14 05:50:31 +02:00
|
|
|
*/
|
|
|
|
#define GOSSIP_STORE_MAJOR_VERSION_MASK 0xE0
|
|
|
|
#define GOSSIP_STORE_MINOR_VERSION_MASK 0x1F
|
|
|
|
|
|
|
|
/* Extract version from first byte */
|
|
|
|
#define GOSSIP_STORE_MAJOR_VERSION(verbyte) (((u8)(verbyte)) >> 5)
|
|
|
|
#define GOSSIP_STORE_MINOR_VERSION(verbyte) ((verbyte) & GOSSIP_STORE_MINOR_VERSION_MASK)
|
2019-06-03 20:09:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bit of length we use to mark a deleted record.
|
|
|
|
*/
|
|
|
|
#define GOSSIP_STORE_LEN_DELETED_BIT 0x80000000U
|
2019-05-04 07:53:13 +02:00
|
|
|
|
2019-11-04 01:37:02 +01:00
|
|
|
/**
|
|
|
|
* Bit of length we use to mark an important record.
|
|
|
|
*/
|
|
|
|
#define GOSSIP_STORE_LEN_PUSH_BIT 0x40000000U
|
|
|
|
|
2022-05-03 19:42:31 +02:00
|
|
|
/**
|
|
|
|
* Bit of length used to define a rate-limited record (do not rebroadcast)
|
|
|
|
*/
|
2022-09-14 05:50:31 +02:00
|
|
|
#define GOSSIP_STORE_LEN_RATELIMIT_BIT 0x20000000U
|
|
|
|
|
2022-12-16 17:25:47 +01:00
|
|
|
/**
|
|
|
|
* Bit used to mark a channel announcement as inactive (needs channel updates.)
|
|
|
|
*/
|
|
|
|
#define GOSSIP_STORE_LEN_ZOMBIE_BIT 0x10000000U
|
|
|
|
|
2022-09-14 05:50:31 +02:00
|
|
|
/**
|
|
|
|
* Full flags mask
|
|
|
|
*/
|
|
|
|
#define GOSSIP_STORE_FLAGS_MASK 0xFFFF0000U
|
2022-05-03 19:42:31 +02:00
|
|
|
|
2019-11-04 01:37:02 +01:00
|
|
|
/* Mask for extracting just the length part of len field */
|
|
|
|
#define GOSSIP_STORE_LEN_MASK \
|
2022-09-14 05:50:31 +02:00
|
|
|
(~(GOSSIP_STORE_FLAGS_MASK))
|
2019-11-04 01:37:02 +01:00
|
|
|
|
2019-06-03 20:17:25 +02:00
|
|
|
/**
|
|
|
|
* gossip_hdr -- On-disk format header.
|
|
|
|
*/
|
|
|
|
struct gossip_hdr {
|
|
|
|
beint32_t len; /* Length of message after header. */
|
|
|
|
beint32_t crc; /* crc of message of timestamp, after header. */
|
|
|
|
beint32_t timestamp; /* timestamp of msg. */
|
|
|
|
};
|
|
|
|
|
2022-01-08 14:28:29 +01:00
|
|
|
/**
|
|
|
|
* Direct store accessor: loads gossip msg from store.
|
|
|
|
*
|
|
|
|
* Returns NULL if there are no more gossip msgs.
|
2022-01-11 02:15:43 +01:00
|
|
|
* Updates *end if the known end of file has moved.
|
|
|
|
* Updates *gossip_store_fd if file has been compacted.
|
2022-01-08 14:28:29 +01:00
|
|
|
*/
|
2022-01-11 02:15:43 +01:00
|
|
|
u8 *gossip_store_next(const tal_t *ctx,
|
2022-01-08 14:28:29 +01:00
|
|
|
int *gossip_store_fd,
|
2022-01-11 02:15:43 +01:00
|
|
|
u32 timestamp_min, u32 timestamp_max,
|
2022-04-19 23:46:35 +02:00
|
|
|
bool push_only,
|
2022-05-03 19:42:31 +02:00
|
|
|
bool with_spam,
|
2022-01-11 02:15:43 +01:00
|
|
|
size_t *off, size_t *end);
|
2022-01-08 14:28:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gossipd will be writing to this, and it's not atomic! Safest
|
|
|
|
* way to find the "end" is to walk through.
|
|
|
|
* @old_end: 1 if no previous end.
|
|
|
|
*/
|
|
|
|
size_t find_gossip_store_end(int gossip_store_fd, size_t old_end);
|
|
|
|
|
2022-07-15 07:59:26 +02:00
|
|
|
/**
|
|
|
|
* Return offset of first entry >= this timestamp.
|
|
|
|
*/
|
|
|
|
size_t find_gossip_store_by_timestamp(int gossip_store_fd,
|
|
|
|
size_t off,
|
|
|
|
u32 timestamp);
|
2019-05-04 07:53:13 +02:00
|
|
|
#endif /* LIGHTNING_COMMON_GOSSIP_STORE_H */
|