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