2021-02-01 03:58:50 +01:00
|
|
|
#include "config.h"
|
2019-06-11 07:30:54 +02:00
|
|
|
#include <ccan/crc32c/crc32c.h>
|
2019-05-04 07:53:13 +02:00
|
|
|
#include <common/gossip_store.h>
|
2019-06-03 20:15:25 +02:00
|
|
|
#include <common/per_peer_state.h>
|
2019-05-04 07:53:13 +02:00
|
|
|
#include <common/status.h>
|
|
|
|
#include <errno.h>
|
2021-05-22 09:09:53 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <gossipd/gossip_store_wiregen.h>
|
2019-05-04 07:53:13 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <unistd.h>
|
2020-09-07 23:06:50 +02:00
|
|
|
#include <wire/peer_wire.h>
|
2019-05-04 07:53:13 +02:00
|
|
|
|
2023-01-30 07:24:16 +01:00
|
|
|
/* We cheat and read first two bytes of message too. */
|
|
|
|
struct hdr_and_type {
|
|
|
|
struct gossip_hdr hdr;
|
|
|
|
be16 type;
|
|
|
|
};
|
|
|
|
/* Beware padding! */
|
|
|
|
#define HDR_AND_TYPE_SIZE (sizeof(struct gossip_hdr) + sizeof(u16))
|
|
|
|
|
|
|
|
bool gossip_store_readhdr(int gossip_store_fd, size_t off,
|
|
|
|
size_t *len,
|
|
|
|
u32 *timestamp,
|
|
|
|
u16 *flags,
|
|
|
|
u16 *type)
|
2022-01-08 14:28:29 +01:00
|
|
|
{
|
2023-01-30 07:24:16 +01:00
|
|
|
struct hdr_and_type buf;
|
2022-01-08 14:28:29 +01:00
|
|
|
int r;
|
|
|
|
|
2023-01-30 07:24:16 +01:00
|
|
|
r = pread(gossip_store_fd, &buf, HDR_AND_TYPE_SIZE, off);
|
|
|
|
if (r != HDR_AND_TYPE_SIZE)
|
|
|
|
return false;
|
|
|
|
*len = be16_to_cpu(buf.hdr.len);
|
|
|
|
if (flags)
|
|
|
|
*flags = be16_to_cpu(buf.hdr.flags);
|
|
|
|
if (timestamp)
|
|
|
|
*timestamp = be32_to_cpu(buf.hdr.timestamp);
|
|
|
|
if (type)
|
|
|
|
*type = be16_to_cpu(buf.type);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t find_gossip_store_end(int gossip_store_fd, size_t off)
|
|
|
|
{
|
|
|
|
size_t msglen;
|
|
|
|
u16 type;
|
2022-01-08 14:28:29 +01:00
|
|
|
|
2023-01-30 07:24:16 +01:00
|
|
|
while (gossip_store_readhdr(gossip_store_fd, off,
|
|
|
|
&msglen, NULL, NULL, &type)) {
|
2022-01-08 14:28:29 +01:00
|
|
|
/* Don't swallow end marker! */
|
2023-01-30 07:24:16 +01:00
|
|
|
if (type == WIRE_GOSSIP_STORE_ENDED)
|
2022-01-08 14:28:29 +01:00
|
|
|
break;
|
|
|
|
|
2023-01-30 07:24:16 +01:00
|
|
|
off += sizeof(struct gossip_hdr) + msglen;
|
2022-01-08 14:28:29 +01:00
|
|
|
}
|
|
|
|
return off;
|
|
|
|
}
|