mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-02 18:35:00 +01:00
Keeping the uintmap ordering all the broadcastable messages is expensive: 130MB for the million-channels project. But now we delete obsolete entries from the store, we can have the per-peer daemons simply read that sequentially and stream the gossip itself. This is the most primitive version, where all gossip is streamed; successive patches will bring back proper handling of timestamp filtering and initial_routing_sync. We add a gossip_state field to track what's happening with our gossip streaming: it's initialized in gossipd, and currently always set, but once we handle timestamps the per-peer daemon may do it when the first filter is sent. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
59 lines
2.1 KiB
C
59 lines
2.1 KiB
C
#ifndef LIGHTNING_COMMON_PER_PEER_STATE_H
|
|
#define LIGHTNING_COMMON_PER_PEER_STATE_H
|
|
#include "config.h"
|
|
|
|
#include <ccan/tal/tal.h>
|
|
#include <ccan/time/time.h>
|
|
#include <common/crypto_state.h>
|
|
|
|
struct gossip_state {
|
|
/* Time for next gossip burst. */
|
|
struct timemono next_gossip;
|
|
};
|
|
|
|
/* Things we hand between daemons to talk to peers. */
|
|
struct per_peer_state {
|
|
/* Cryptographic state needed to exchange messages with the peer (as
|
|
* featured in BOLT #8) */
|
|
struct crypto_state cs;
|
|
/* NULL if it's not initialized yet */
|
|
struct gossip_state *gs;
|
|
#if DEVELOPER
|
|
/* Normally 60000, but adjustable for dev mode */
|
|
u32 dev_gossip_broadcast_msec;
|
|
#endif /* DEVELOPER */
|
|
/* If not -1, closed on freeing */
|
|
int peer_fd, gossip_fd, gossip_store_fd;
|
|
};
|
|
|
|
/* Allocate a new per-peer state and add destructor to close fds if set;
|
|
* sets fds to -1 and ->gs to NULL.. */
|
|
struct per_peer_state *new_per_peer_state(const tal_t *ctx,
|
|
const struct crypto_state *cs);
|
|
|
|
/* Initialize the fds (must be -1 previous) */
|
|
void per_peer_state_set_fds(struct per_peer_state *pps,
|
|
int peer_fd, int gossip_fd, int gossip_store_fd);
|
|
|
|
/* Array version of above: tal_count(fds) must be 3 */
|
|
void per_peer_state_set_fds_arr(struct per_peer_state *pps, const int *fds);
|
|
|
|
/* These routines do *part* of the work: you need to per_peer_state_fdpass_send
|
|
* or receive the three fds afterwards! */
|
|
void towire_per_peer_state(u8 **pptr, const struct per_peer_state *pps);
|
|
void per_peer_state_fdpass_send(int fd, const struct per_peer_state *pps);
|
|
|
|
struct per_peer_state *fromwire_per_peer_state(const tal_t *ctx,
|
|
const u8 **cursor, size_t *max);
|
|
|
|
void towire_gossip_state(u8 **pptr, const struct gossip_state *gs);
|
|
void fromwire_gossip_state(const u8 **cursor, size_t *max,
|
|
struct gossip_state *gs);
|
|
|
|
/* How long until we have to check gossip store, if any? */
|
|
bool time_to_next_gossip(const struct per_peer_state *pps,
|
|
struct timerel *t);
|
|
|
|
/* Reset pps->next_gossip now we've drained gossip_store */
|
|
void per_peer_state_reset_gossip_timer(struct per_peer_state *pps);
|
|
#endif /* LIGHTNING_COMMON_PER_PEER_STATE_H */
|