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

Function append_msg

gossipd/gossip_store.c:49–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49static bool append_msg(int fd, const u8 *msg, u32 timestamp, u64 *len,
50 const u8 ***msgs)
51{
52 struct gossip_hdr *hdr;
53 u32 msglen;
54
55 /* Don't ever overwrite the version header! */
56 assert(*len);
57
58 /* Never NULL */
59 assert(msg);
60 msglen = tal_count(msg);
61 /* All messages begin with a 16-bit type */
62 assert(msglen >= 2);
63
64 hdr = (struct gossip_hdr *)tal_arr(tmpctx, u8, sizeof(*hdr) + msglen);
65 hdr->len = cpu_to_be16(msglen);
66 hdr->flags = 0;
67 hdr->crc = cpu_to_be32(crc32c(timestamp, msg, msglen));
68 hdr->timestamp = cpu_to_be32(timestamp);
69 memcpy(hdr + 1, msg, msglen);
70
71 if (pwrite(fd, hdr, sizeof(*hdr) + msglen, *len) != sizeof(*hdr) + msglen)
72 return false;
73
74 /* Update the hdr with the complete bit as a single-byte write */
75 hdr->flags = CPU_TO_BE16(GOSSIP_STORE_COMPLETED_BIT);
76 if (pwrite(fd, &hdr->flags, 1, *len) != 1)
77 return false;
78
79 *len += sizeof(*hdr) + msglen;
80 if (msgs)
81 tal_arr_expand(msgs, (const u8 *)tal_steal(*msgs, hdr));
82 return true;
83}
84
85/* v9 added the GOSSIP_STORE_LEN_RATELIMIT_BIT.
86 * v10 removed any remaining non-htlc-max channel_update.

Callers 3

new_uuid_recordFunction · 0.85
gossip_store_upgradeFunction · 0.85
gossip_store_addFunction · 0.85

Calls 3

cpu_to_be16Function · 0.85
cpu_to_be32Function · 0.85
crc32cFunction · 0.85

Tested by

no test coverage detected