2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2019-06-11 07:30:54 +02:00
|
|
|
#include <ccan/crc32c/crc32c.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
#include <ccan/err/err.h>
|
2019-09-12 02:24:00 +02:00
|
|
|
#include <ccan/opt/opt.h>
|
2020-10-22 02:57:07 +02:00
|
|
|
#include <common/gossip_store.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
#include <common/type_to_string.h>
|
|
|
|
#include <fcntl.h>
|
2020-08-25 04:05:45 +02:00
|
|
|
#include <gossipd/gossip_store_wiregen.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2020-09-07 23:06:50 +02:00
|
|
|
#include <wire/peer_wire.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
u8 version;
|
2019-06-03 20:17:25 +02:00
|
|
|
struct gossip_hdr hdr;
|
2019-06-03 20:06:25 +02:00
|
|
|
size_t off;
|
2019-09-12 02:24:00 +02:00
|
|
|
bool print_deleted = false;
|
2018-08-30 02:04:28 +02:00
|
|
|
|
|
|
|
setup_locale();
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_register_noarg("--print-deleted", opt_set_bool, &print_deleted,
|
|
|
|
"Print deleted entries too");
|
|
|
|
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
|
|
|
"[<gossip_store>]"
|
|
|
|
"Dump all gossip messages in the store",
|
|
|
|
"Print this message.");
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_parse(&argc, argv, opt_log_stderr_exit);
|
2018-08-30 02:04:28 +02:00
|
|
|
if (argc > 2)
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_usage_and_exit("Too many arguments");
|
2018-08-30 02:04:28 +02:00
|
|
|
|
|
|
|
if (argc == 2) {
|
|
|
|
fd = open(argv[1], O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
err(1, "Opening %s", argv[1]);
|
|
|
|
} else
|
|
|
|
fd = STDIN_FILENO;
|
|
|
|
|
|
|
|
if (read(fd, &version, sizeof(version)) != sizeof(version))
|
|
|
|
errx(1, "Empty file");
|
|
|
|
|
|
|
|
if (version != GOSSIP_STORE_VERSION)
|
|
|
|
warnx("UNSUPPORTED GOSSIP VERSION %u (expected %u)",
|
|
|
|
version, GOSSIP_STORE_VERSION);
|
|
|
|
|
|
|
|
printf("GOSSIP VERSION %u\n", version);
|
2019-06-03 20:06:25 +02:00
|
|
|
off = 1;
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-06-03 20:17:25 +02:00
|
|
|
while (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr)) {
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat;
|
2020-10-20 05:59:30 +02:00
|
|
|
struct short_channel_id scid;
|
2019-06-03 20:17:25 +02:00
|
|
|
u32 msglen = be32_to_cpu(hdr.len);
|
2019-06-03 20:09:25 +02:00
|
|
|
u8 *msg, *inner;
|
2022-05-04 15:48:59 +02:00
|
|
|
bool deleted, push, ratelimit;
|
2019-09-12 02:24:00 +02:00
|
|
|
|
|
|
|
deleted = (msglen & GOSSIP_STORE_LEN_DELETED_BIT);
|
2019-11-04 01:37:02 +01:00
|
|
|
push = (msglen & GOSSIP_STORE_LEN_PUSH_BIT);
|
2022-05-04 15:48:59 +02:00
|
|
|
ratelimit = (msglen & GOSSIP_STORE_LEN_RATELIMIT_BIT);
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-11-04 01:37:02 +01:00
|
|
|
msglen &= GOSSIP_STORE_LEN_MASK;
|
2019-06-03 20:09:25 +02:00
|
|
|
msg = tal_arr(NULL, u8, msglen);
|
2018-08-30 02:04:28 +02:00
|
|
|
if (read(fd, msg, msglen) != msglen)
|
2019-06-03 20:06:25 +02:00
|
|
|
errx(1, "%zu: Truncated file?", off);
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-06-03 20:17:25 +02:00
|
|
|
if (be32_to_cpu(hdr.crc)
|
|
|
|
!= crc32c(be32_to_cpu(hdr.timestamp), msg, msglen))
|
2018-08-30 02:04:28 +02:00
|
|
|
warnx("Checksum verification failed");
|
|
|
|
|
2022-05-04 15:48:59 +02:00
|
|
|
printf("%zu: %s%s%s", off,
|
2019-11-04 01:37:02 +01:00
|
|
|
deleted ? "DELETED " : "",
|
2022-05-04 15:48:59 +02:00
|
|
|
push ? "PUSH " : "",
|
|
|
|
ratelimit ? "RATE-LIMITED " : "");
|
2019-09-12 02:24:00 +02:00
|
|
|
if (deleted && !print_deleted) {
|
|
|
|
printf("\n");
|
2019-10-08 03:06:24 +02:00
|
|
|
goto end;
|
2019-09-12 02:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fromwire_gossip_store_channel_amount(msg, &sat)) {
|
|
|
|
printf("channel_amount: %s\n",
|
2019-05-04 07:53:12 +02:00
|
|
|
type_to_string(tmpctx, struct amount_sat, &sat));
|
|
|
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("t=%u channel_announcement: %s\n",
|
|
|
|
be32_to_cpu(hdr.timestamp),
|
2019-06-03 20:17:25 +02:00
|
|
|
tal_hex(msg, msg));
|
2019-05-04 07:53:12 +02:00
|
|
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_UPDATE) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("t=%u channel_update: %s\n",
|
|
|
|
be32_to_cpu(hdr.timestamp),
|
2019-06-03 20:17:25 +02:00
|
|
|
tal_hex(msg, msg));
|
2019-05-04 07:53:12 +02:00
|
|
|
} else if (fromwire_peektype(msg) == WIRE_NODE_ANNOUNCEMENT) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("t=%u node_announcement: %s\n",
|
|
|
|
be32_to_cpu(hdr.timestamp),
|
2019-06-03 20:17:25 +02:00
|
|
|
tal_hex(msg, msg));
|
2020-10-20 05:59:30 +02:00
|
|
|
} else if (fromwire_gossip_store_private_channel(msg, msg, &sat,
|
|
|
|
&inner)) {
|
|
|
|
printf("private channel_announcement: %s %s\n",
|
|
|
|
type_to_string(tmpctx, struct amount_sat, &sat),
|
|
|
|
tal_hex(msg, inner));
|
2019-06-03 20:06:25 +02:00
|
|
|
} else if (fromwire_gossip_store_private_update(msg, msg,
|
|
|
|
&inner)) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("private channel_update: %s\n",
|
|
|
|
tal_hex(msg, inner));
|
2020-10-20 05:59:30 +02:00
|
|
|
} else if (fromwire_gossip_store_delete_chan(msg, &scid)) {
|
|
|
|
printf("delete channel: %s\n",
|
|
|
|
type_to_string(tmpctx, struct short_channel_id,
|
|
|
|
&scid));
|
2018-08-30 02:04:28 +02:00
|
|
|
} else {
|
2019-09-12 02:24:00 +02:00
|
|
|
warnx("Unknown message %u",
|
|
|
|
fromwire_peektype(msg));
|
2018-08-30 02:04:28 +02:00
|
|
|
}
|
2019-10-08 03:06:24 +02:00
|
|
|
end:
|
2019-06-03 20:17:25 +02:00
|
|
|
off += sizeof(hdr) + msglen;
|
2018-08-30 02:04:28 +02:00
|
|
|
tal_free(msg);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|