1 #ifndef LIGHTNING_GOSSIPD_GOSSIP_STORE_H 2 #define LIGHTNING_GOSSIPD_GOSSIP_STORE_H 3 4 #include "config.h" 5 6 #include <bitcoin/short_channel_id.h> 7 #include <ccan/list/list.h> 8 #include <ccan/short_types/short_types.h> 9 #include <ccan/tal/tal.h> 10 #include <gossipd/routing.h> 11 12 /** 13 * gossip_store -- On-disk storage related information 14 */ 15 16 struct gossip_store; 17 struct routing_state; 18 19 struct gossip_store *gossip_store_new(struct routing_state *rstate, 20 struct list_head *peers); 21 22 /** 23 * Load the initial gossip store, if any. 24 * 25 * @param rstate The routing state to load init. 26 * @param gs The `gossip_store` to read from 27 * 28 * Returns the last-modified time of the store, or 0 if it was created new. 29 */ 30 u32 gossip_store_load(struct routing_state *rstate, struct gossip_store *gs); 31 32 /** 33 * Add a private channel_update message to the gossip_store 34 */ 35 u64 gossip_store_add_private_update(struct gossip_store *gs, const u8 *update); 36 37 /** 38 * Add a gossip message to the gossip_store (and optional addendum) 39 * @gs: gossip store 40 * @gossip_msg: the gossip message to insert. 41 * @timestamp: the timestamp for filtering of this messsage. 42 * @push: true if this should be sent to peers despite any timestamp filters. 43 * @addendum: another message to append immediately after this 44 * (for appending amounts to channel_announcements for internal use). 45 */ 46 u64 gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg, 47 u32 timestamp, bool push, const u8 *addendum); 48 49 50 /** 51 * Delete the broadcast associated with this (if any). 52 * 53 * In developer mode, checks that type is correct. 54 */ 55 void gossip_store_delete(struct gossip_store *gs, 56 struct broadcastable *bcast, 57 int type); 58 59 /** 60 * Mark that the channel is about to be deleted, for convenience of 61 * others mapping the gossip_store. 62 */ 63 void gossip_store_mark_channel_deleted(struct gossip_store *gs, 64 const struct short_channel_id *scid); 65 66 /** 67 * Direct store accessor: loads gossip msg back from store. 68 * 69 * Caller must ensure offset != 0. Never returns NULL. 70 */ 71 const u8 *gossip_store_get(const tal_t *ctx, 72 struct gossip_store *gs, 73 u64 offset); 74 75 /** 76 * Direct store accessor: loads private gossip msg back from store. 77 * 78 * Caller must ensure offset != 0. Never returns NULL. 79 */ 80 const u8 *gossip_store_get_private_update(const tal_t *ctx, 81 struct gossip_store *gs, 82 u64 offset); 83 84 /* Exposed for dev-compact-gossip-store to force compaction. */ 85 bool gossip_store_compact(struct gossip_store *gs); 86 87 /** 88 * Get a readonly fd for the gossip_store. 89 * @gs: the gossip store. 90 * 91 * Returns -1 on failure, and sets errno. 92 */ 93 int gossip_store_readonly_fd(struct gossip_store *gs); 94 95 /* Callback inside gossipd when store is compacted */ 96 void update_peers_broadcast_index(struct list_head *peers, u32 offset); 97 98 #endif /* LIGHTNING_GOSSIPD_GOSSIP_STORE_H */ 99