diff --git a/common/gossip_store.c b/common/gossip_store.c index 298988a13..94a1e6a8e 100644 --- a/common/gossip_store.c +++ b/common/gossip_store.c @@ -3,25 +3,17 @@ #include #include -/* 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 1545e8685..de3d86aab 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,