MCPcopy Create free account
hub / github.com/ElementsProject/lightning / copy_records

Function copy_records

gossipd/compactd.c:54–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54static u64 copy_records(int oldfd, int newfd, u64 old_off, u64 limit,
55 bool keep_delete_chan)
56{
57 u8 buffer[65535];
58
59 while (old_off < limit) {
60 size_t reclen;
61 struct gossip_hdr_and_type hdr;
62
63 old_off += readx(oldfd, &hdr, GOSSIP_HDR_AND_TYPE_SIZE);
64
65 /* We read 2 bytes already */
66 reclen = be16_to_cpu(hdr.hdr.len) - 2;
67
68 /* Skip old uuid and deleted records, */
69 if (be16_to_cpu(hdr.type) == WIRE_GOSSIP_STORE_UUID
70 || (be16_to_cpu(hdr.hdr.flags) & GOSSIP_STORE_DELETED_BIT)) {
71 old_off += skipx(oldfd, reclen);
72 continue;
73 }
74
75 /* Are we supposed to skip deleted markers? */
76 if (!keep_delete_chan
77 && be16_to_cpu(hdr.type) == WIRE_GOSSIP_STORE_DELETE_CHAN) {
78 old_off += skipx(oldfd, reclen);
79 continue;
80 }
81
82 if (!((be16_to_cpu(hdr.hdr.flags) & GOSSIP_STORE_COMPLETED_BIT)))
83 errx(1, "Incomplete gossip_store record at %"PRIu64,
84 old_off - GOSSIP_HDR_AND_TYPE_SIZE);
85
86 old_off += readx(oldfd, buffer, reclen);
87
88 writex(newfd, &hdr, GOSSIP_HDR_AND_TYPE_SIZE);
89 writex(newfd, buffer, reclen);
90 }
91
92 return old_off;
93}
94
95int main(int argc, char *argv[])
96{

Callers 1

mainFunction · 0.85

Calls 5

readxFunction · 0.85
be16_to_cpuFunction · 0.85
skipxFunction · 0.85
errxFunction · 0.85
writexFunction · 0.85

Tested by

no test coverage detected