| 15 | #define GSTORE_MINOR 10 |
| 16 | |
| 17 | int main(int argc, char *argv[]) |
| 18 | { |
| 19 | int fd; |
| 20 | u8 version; |
| 21 | struct gossip_hdr hdr; |
| 22 | size_t off; |
| 23 | bool print_deleted = false; |
| 24 | bool print_timestamp = false; |
| 25 | |
| 26 | setup_locale(); |
| 27 | opt_register_noarg("--print-deleted", opt_set_bool, &print_deleted, |
| 28 | "Print deleted entries too"); |
| 29 | opt_register_noarg("--print-timestamps", opt_set_bool, &print_timestamp, |
| 30 | "Print timestamp with entries"); |
| 31 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
| 32 | "[<gossip_store>]" |
| 33 | "Dump all gossip messages in the store", |
| 34 | "Print this message."); |
| 35 | |
| 36 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 37 | if (argc > 2) |
| 38 | opt_usage_and_exit("Too many arguments"); |
| 39 | |
| 40 | if (argc == 2) { |
| 41 | fd = open(argv[1], O_RDONLY); |
| 42 | if (fd < 0) |
| 43 | err(1, "Opening %s", argv[1]); |
| 44 | } else |
| 45 | fd = STDIN_FILENO; |
| 46 | |
| 47 | if (read(fd, &version, sizeof(version)) != sizeof(version)) |
| 48 | errx(1, "Empty file"); |
| 49 | |
| 50 | if (GOSSIP_STORE_MAJOR_VERSION(version) != GSTORE_MAJOR) |
| 51 | errx(1, "Unsupported major gossip_version %u (expected %u)", |
| 52 | GOSSIP_STORE_MAJOR_VERSION(version), GSTORE_MAJOR); |
| 53 | |
| 54 | /* Unsupported minor just means we might not understand all fields, |
| 55 | * or all flags. */ |
| 56 | if (GOSSIP_STORE_MINOR_VERSION(version) != GSTORE_MINOR) |
| 57 | warnx("UNKNOWN GOSSIP minor VERSION %u (expected %u)", |
| 58 | GOSSIP_STORE_MINOR_VERSION(version), GSTORE_MINOR); |
| 59 | |
| 60 | printf("GOSSIP VERSION %u/%u\n", |
| 61 | GOSSIP_STORE_MINOR_VERSION(version), |
| 62 | GOSSIP_STORE_MAJOR_VERSION(version)); |
| 63 | off = 1; |
| 64 | |
| 65 | while (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr)) { |
| 66 | struct amount_sat sat; |
| 67 | struct short_channel_id scid; |
| 68 | u32 msglen = be32_to_cpu(hdr.len); |
| 69 | u8 *msg, *inner; |
| 70 | bool deleted, push, ratelimit; |
| 71 | u32 blockheight; |
| 72 | |
| 73 | deleted = (msglen & GOSSIP_STORE_LEN_DELETED_BIT); |
| 74 | push = (msglen & GOSSIP_STORE_LEN_PUSH_BIT); |
nothing calls this directly
no test coverage detected