| 73 | #endif /* !HAVE_PWRITEV */ |
| 74 | |
| 75 | static bool append_msg(int fd, const u8 *msg, u32 timestamp, |
| 76 | bool push, bool spam, u64 *len) |
| 77 | { |
| 78 | struct gossip_hdr hdr; |
| 79 | u32 msglen; |
| 80 | struct iovec iov[2]; |
| 81 | |
| 82 | /* Don't ever overwrite the version header! */ |
| 83 | assert(*len); |
| 84 | |
| 85 | msglen = tal_count(msg); |
| 86 | hdr.len = cpu_to_be32(msglen); |
| 87 | if (push) |
| 88 | hdr.len |= CPU_TO_BE32(GOSSIP_STORE_LEN_PUSH_BIT); |
| 89 | if (spam) |
| 90 | hdr.len |= CPU_TO_BE32(GOSSIP_STORE_LEN_RATELIMIT_BIT); |
| 91 | hdr.crc = cpu_to_be32(crc32c(timestamp, msg, msglen)); |
| 92 | hdr.timestamp = cpu_to_be32(timestamp); |
| 93 | |
| 94 | /* pwritev makes it more likely to appear at once, plus it's |
| 95 | * exactly what we want. */ |
| 96 | iov[0].iov_base = &hdr; |
| 97 | iov[0].iov_len = sizeof(hdr); |
| 98 | iov[1].iov_base = (void *)msg; |
| 99 | iov[1].iov_len = msglen; |
| 100 | if (gossip_pwritev(fd, iov, ARRAY_SIZE(iov), *len) != sizeof(hdr) + msglen) |
| 101 | return false; |
| 102 | *len += sizeof(hdr) + msglen; |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | /* v9 added the GOSSIP_STORE_LEN_RATELIMIT_BIT. |
| 107 | * v10 removed any remaining non-htlc-max channel_update. |
no test coverage detected