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

Function gossmap_stream_next

common/gossmap.c:1879–1987  ·  view source on GitHub ↗

FIXME: I tried returning a direct ptr into mmap where possible, but * we would have to re-engineer packet paths to handle non-talarr msgs! */

Source from the content-addressed store, hash-verified

1877/* FIXME: I tried returning a direct ptr into mmap where possible, but
1878 * we would have to re-engineer packet paths to handle non-talarr msgs! */
1879const void *gossmap_stream_next(const tal_t *ctx,
1880 const struct gossmap *map,
1881 struct gossmap_iter *iter,
1882 u32 *timestamp)
1883{
1884 /* We grab hdr and type together. Beware alignment! */
1885 struct hdr {
1886 union {
1887 struct gossip_hdr ghdr;
1888 struct {
1889 u8 raw_hdr[sizeof(struct gossip_hdr)];
1890 be16 type;
1891 } type;
1892 } u;
1893 };
1894 struct hdr h;
1895
1896 /* If we have reopened (unlikely!), we need to restart iteration */
1897 if (iter->generation != map->generation) {
1898 iter->generation = map->generation;
1899 /* Skip version byte */
1900 iter->offset = 1;
1901 }
1902
1903 while (iter->offset + sizeof(h.u.type) <= map->map_size) {
1904 void *ret;
1905 u64 len;
1906
1907 map_copy(map, iter->offset, &h, sizeof(h.u.type));
1908
1909 /* Make sure we can read entire record. */
1910 len = be16_to_cpu(h.u.ghdr.len);
1911 if (iter->offset + sizeof(h.u.ghdr) + len > map->map_size)
1912 break;
1913
1914 /* Increase iterator now we're committed. */
1915 iter->offset += sizeof(h.u.ghdr) + len;
1916
1917 /* Ignore deleted and dying */
1918 if (be16_to_cpu(h.u.ghdr.flags) &
1919 (GOSSIP_STORE_DELETED_BIT|GOSSIP_STORE_DYING_BIT))
1920 continue;
1921
1922 /* Use a switch as insurance against addition of new public
1923 * gossip messages! */
1924 switch ((enum peer_wire)be16_to_cpu(h.u.type.type)) {
1925 case WIRE_CHANNEL_ANNOUNCEMENT:
1926 case WIRE_CHANNEL_UPDATE:
1927 case WIRE_NODE_ANNOUNCEMENT:
1928 ret = tal_arr(ctx, u8, len);
1929 map_copy(map, iter->offset - len, ret, len);
1930 if (timestamp)
1931 *timestamp = be32_to_cpu(h.u.ghdr.timestamp);
1932 return ret;
1933
1934 case WIRE_INIT:
1935 case WIRE_ERROR:
1936 case WIRE_WARNING:

Callers 1

maybe_gossip_msgFunction · 0.85

Calls 3

map_copyFunction · 0.85
be16_to_cpuFunction · 0.85
be32_to_cpuFunction · 0.85

Tested by

no test coverage detected