common: expose gossip_store "header and type" single-read struct.
What changed, and why it matters
This commit is a small internal code cleanup. It moves a private data structure for reading gossip message headers from a source file into a shared header file so other parts of the program can reuse it. It also updates an outdated comment. There is no security-relevant change.
No action required. This is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch exposes struct gossip_hdr_and_type and the GOSSIP_HDR_AND_TYPE_SIZE macro in common/gossip_store.h, replacing the previously file-local struct hdr_and_type and HDR_AND_TYPE_SIZE in common/gossip_store.c. The gossip_store_readhdr() function is updated to use the new names. The comment for gossip_store_readhdr() is corrected to reflect current behavior. No logic, parsing, bounds handling, or file operations are changed.
Changed components
common/gossip_store.ccommon/gossip_store.hInspect captured patch +13 / −16
diff --git a/common/gossip_store.c b/common/gossip_store.c
index 298988a1..94a1e6a8 100644
--- a/common/gossip_store.c
+++ b/common/gossip_store.c
@@ -3,25 +3,17 @@
#include <common/gossip_store_wiregen.h>
#include <unistd.h>
-/* 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)
{
- struct hdr_and_type buf;
+ struct gossip_hdr_and_type buf;
int r;
- r = pread(gossip_store_fd, &buf, HDR_AND_TYPE_SIZE, off);
- if (r != HDR_AND_TYPE_SIZE)
+ r = pread(gossip_store_fd, &buf, GOSSIP_HDR_AND_TYPE_SIZE, off);
+ if (r != GOSSIP_HDR_AND_TYPE_SIZE)
return false;
if (!(buf.hdr.flags & CPU_TO_BE16(GOSSIP_STORE_COMPLETED_BIT)))
return false;
diff --git a/common/gossip_store.h b/common/gossip_store.h
index 1545e868..de3d86aa 100644
--- a/common/gossip_store.h
+++ b/common/gossip_store.h
@@ -50,6 +50,14 @@ struct gossip_hdr {
beint32_t timestamp; /* timestamp of msg. */
};
+/* Useful to read gossip_hdr and type of msg. */
+struct gossip_hdr_and_type {
+ struct gossip_hdr hdr;
+ be16 type;
+};
+/* Beware padding! */
+#define GOSSIP_HDR_AND_TYPE_SIZE (sizeof(struct gossip_hdr) + sizeof(u16))
+
/**
* Direct store accessor: read gossip msg hdr from store.
* @gossip_store_fd: the readable file descriptor
@@ -59,11 +67,8 @@ struct gossip_hdr {
* @flags (out): if non-NULL, set to the flags.
* @type (out): if non-NULL, set to the msg type.
*
- * Returns false if there are no more gossip msgs. If you
- * want to read the message, use gossip_store_next, if you
- * want to skip, simply add sizeof(gossip_hdr) + *len to *off.
- * Note: it's possible that entire record isn't there yet,
- * so gossip_store_next can fail.
+ * Returns false if there are no more gossip msgs, or message
+ * is incomplete. To iterate, simply add sizeof(gossip_hdr) + *len to off.
*/
bool gossip_store_readhdr(int gossip_store_fd, size_t off,
size_t *len,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.