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

Function gossip_store_next

common/gossip_store.c:109–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109u8 *gossip_store_next(const tal_t *ctx,
110 int *gossip_store_fd,
111 u32 timestamp_min, u32 timestamp_max,
112 bool push_only,
113 bool with_spam,
114 size_t *off, size_t *end)
115{
116 u8 *msg = NULL;
117 size_t initial_off = *off;
118
119 while (!msg) {
120 struct gossip_hdr hdr;
121 u32 msglen, checksum, timestamp;
122 bool push, ratelimited;
123 int type, r;
124
125 r = pread(*gossip_store_fd, &hdr, sizeof(hdr), *off);
126 if (r != sizeof(hdr))
127 return NULL;
128
129 msglen = be32_to_cpu(hdr.len);
130 push = (msglen & GOSSIP_STORE_LEN_PUSH_BIT);
131 ratelimited = (msglen & GOSSIP_STORE_LEN_RATELIMIT_BIT);
132 msglen &= GOSSIP_STORE_LEN_MASK;
133
134 /* Skip any deleted entries. */
135 if (be32_to_cpu(hdr.len) & GOSSIP_STORE_LEN_DELETED_BIT) {
136 *off += r + msglen;
137 continue;
138 }
139
140 /* Skip any timestamp filtered */
141 timestamp = be32_to_cpu(hdr.timestamp);
142 if (!push &&
143 !timestamp_filter(timestamp_min, timestamp_max,
144 timestamp)) {
145 *off += r + msglen;
146 continue;
147 }
148
149 /* Messages can be up to 64k, but we also have internal ones:
150 * 128k is plenty. */
151 if (msglen > 128 * 1024)
152 status_failed(STATUS_FAIL_INTERNAL_ERROR,
153 "gossip_store: oversize msg len %u at"
154 " offset %zu (was at %zu)",
155 msglen, *off, initial_off);
156
157 checksum = be32_to_cpu(hdr.crc);
158 msg = tal_arr(ctx, u8, msglen);
159 r = pread(*gossip_store_fd, msg, msglen, *off + r);
160 if (r != msglen)
161 return tal_free(msg);
162
163 if (checksum != crc32c(be32_to_cpu(hdr.timestamp), msg, msglen))
164 status_failed(STATUS_FAIL_INTERNAL_ERROR,
165 "gossip_store: bad checksum at offset %zu"
166 "(was at %zu): %s",

Callers 1

maybe_from_gossip_storeFunction · 0.85

Calls 9

be32_to_cpuFunction · 0.85
timestamp_filterFunction · 0.85
tal_freeFunction · 0.85
crc32cFunction · 0.85
tal_hexFunction · 0.85
reopen_gossip_storeFunction · 0.85
public_msg_typeFunction · 0.85
status_failedFunction · 0.70
fromwire_peektypeFunction · 0.50

Tested by

no test coverage detected