1313#include <errno.h>
1414#include <fcntl.h>
1515#include <gossipd/gossip_store_wiregen.h>
16+ #include <inttypes.h>
1617#include <sys/mman.h>
1718#include <unistd.h>
1819#include <wire/peer_wire.h>
@@ -60,7 +61,7 @@ struct gossmap {
6061 /* The memory map of the file: u8 for arithmetic portability */
6162 u8 * mmap ;
6263 /* map_end is where we read to so far, map_size is total size */
63- size_t map_end , map_size ;
64+ u64 map_end , map_size ;
6465
6566 /* Map of node id -> node */
6667 struct nodeidx_htable * nodes ;
@@ -93,18 +94,18 @@ struct gossmap {
9394 void * cb_arg );
9495 bool (* unknown_record )(struct gossmap * map ,
9596 int type ,
96- size_t off ,
97+ u64 off ,
9798 size_t msglen ,
9899 void * cb_arg );
99100 void * cb_arg ;
100101};
101102
102103/* Accessors for the gossmap */
103- static void map_copy (const struct gossmap * map , size_t offset ,
104+ static void map_copy (const struct gossmap * map , u64 offset ,
104105 void * dst , size_t len )
105106{
106107 if (offset >= map -> map_size ) {
107- size_t localoff = offset - map -> map_size ;
108+ u64 localoff = offset - map -> map_size ;
108109 assert (localoff + len <= tal_bytelen (map -> local ));
109110 memcpy (dst , map -> local + localoff , len );
110111 } else {
@@ -119,35 +120,35 @@ static void map_copy(const struct gossmap *map, size_t offset,
119120 }
120121}
121122
122- static u8 map_u8 (const struct gossmap * map , size_t offset )
123+ static u8 map_u8 (const struct gossmap * map , u64 offset )
123124{
124125 u8 u8 ;
125126 map_copy (map , offset , & u8 , sizeof (u8 ));
126127 return u8 ;
127128}
128129
129- static u16 map_be16 (const struct gossmap * map , size_t offset )
130+ static u16 map_be16 (const struct gossmap * map , u64 offset )
130131{
131132 be16 be16 ;
132133 map_copy (map , offset , & be16 , sizeof (be16 ));
133134 return be16_to_cpu (be16 );
134135}
135136
136- static u32 map_be32 (const struct gossmap * map , size_t offset )
137+ static u32 map_be32 (const struct gossmap * map , u64 offset )
137138{
138139 be32 be32 ;
139140 map_copy (map , offset , & be32 , sizeof (be32 ));
140141 return be32_to_cpu (be32 );
141142}
142143
143- static u64 map_be64 (const struct gossmap * map , size_t offset )
144+ static u64 map_be64 (const struct gossmap * map , u64 offset )
144145{
145146 be64 be64 ;
146147 map_copy (map , offset , & be64 , sizeof (be64 ));
147148 return be64_to_cpu (be64 );
148149}
149150
150- static void map_nodeid (const struct gossmap * map , size_t offset ,
151+ static void map_nodeid (const struct gossmap * map , u64 offset ,
151152 struct node_id * id )
152153{
153154 map_copy (map , offset , id , sizeof (* id ));
@@ -156,7 +157,7 @@ static void map_nodeid(const struct gossmap *map, size_t offset,
156157/* Returns optional or compulsory feature if set, otherwise -1 */
157158static int map_feature_test (const struct gossmap * map ,
158159 int compulsory_bit ,
159- size_t offset , size_t len )
160+ u64 offset , size_t len )
160161{
161162 size_t bytenum = compulsory_bit / 8 ;
162163 u8 bits ;
@@ -373,8 +374,8 @@ static struct gossmap_chan *next_free_chan(struct gossmap *map)
373374}
374375
375376static struct gossmap_chan * new_channel (struct gossmap * map ,
376- u32 cannounce_off ,
377- u32 plus_scid_off ,
377+ u64 cannounce_off ,
378+ u64 plus_scid_off ,
378379 u32 n1idx , u32 n2idx )
379380{
380381 struct gossmap_chan * chan = next_free_chan (map );
@@ -444,13 +445,13 @@ void gossmap_remove_node(struct gossmap *map, struct gossmap_node *node)
444445 * * [`point`:`node_id_2`]
445446 */
446447static struct gossmap_chan * add_channel (struct gossmap * map ,
447- size_t cannounce_off ,
448+ u64 cannounce_off ,
448449 size_t msglen )
449450{
450451 /* Note that first two bytes are message type */
451- const size_t feature_len_off = 2 + (64 + 64 + 64 + 64 );
452+ const u64 feature_len_off = 2 + (64 + 64 + 64 + 64 );
452453 size_t feature_len ;
453- size_t plus_scid_off ;
454+ u64 plus_scid_off ;
454455 struct short_channel_id scid ;
455456 struct node_id node_id [2 ];
456457 struct gossmap_node * n [2 ];
@@ -468,7 +469,7 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
468469 chan = gossmap_find_chan (map , & scid );
469470 if (chan ) {
470471 /* FIXME: Report this better! */
471- warnx ("gossmap: redundant channel_announce for %s, offsets %u and %zu !" ,
472+ warnx ("gossmap: redundant channel_announce for %s, offsets %" PRIu64 " and %" PRIu64 " !" ,
472473 fmt_short_channel_id (tmpctx , scid ),
473474 chan -> cann_off , cannounce_off );
474475 return NULL ;
@@ -522,17 +523,17 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
522523 * * [`u32`:`fee_proportional_millionths`]
523524 * * [`u64`:`htlc_maximum_msat`]
524525 */
525- static void update_channel (struct gossmap * map , size_t cupdate_off )
526+ static void update_channel (struct gossmap * map , u64 cupdate_off )
526527{
527528 /* Note that first two bytes are message type */
528- const size_t scid_off = cupdate_off + 2 + (64 + 32 );
529- const size_t message_flags_off = scid_off + 8 + 4 ;
530- const size_t channel_flags_off = message_flags_off + 1 ;
531- const size_t cltv_expiry_delta_off = channel_flags_off + 1 ;
532- const size_t htlc_minimum_off = cltv_expiry_delta_off + 2 ;
533- const size_t fee_base_off = htlc_minimum_off + 8 ;
534- const size_t fee_prop_off = fee_base_off + 4 ;
535- const size_t htlc_maximum_off = fee_prop_off + 4 ;
529+ const u64 scid_off = cupdate_off + 2 + (64 + 32 );
530+ const u64 message_flags_off = scid_off + 8 + 4 ;
531+ const u64 channel_flags_off = message_flags_off + 1 ;
532+ const u64 cltv_expiry_delta_off = channel_flags_off + 1 ;
533+ const u64 htlc_minimum_off = cltv_expiry_delta_off + 2 ;
534+ const u64 fee_base_off = htlc_minimum_off + 8 ;
535+ const u64 fee_prop_off = fee_base_off + 4 ;
536+ const u64 htlc_maximum_off = fee_prop_off + 4 ;
536537 struct short_channel_id_dir scidd ;
537538 struct gossmap_chan * chan ;
538539 struct half_chan hc ;
@@ -578,7 +579,7 @@ static void update_channel(struct gossmap *map, size_t cupdate_off)
578579 chan -> cupdate_off [chanflags & 1 ] = cupdate_off ;
579580}
580581
581- static void remove_channel_by_deletemsg (struct gossmap * map , size_t del_off )
582+ static void remove_channel_by_deletemsg (struct gossmap * map , u64 del_off )
582583{
583584 struct short_channel_id scid ;
584585 struct gossmap_chan * chan ;
@@ -616,9 +617,9 @@ struct short_channel_id gossmap_chan_scid(const struct gossmap *map,
616617 * * [`u16`:`addrlen`]
617618 * * [`addrlen*byte`:`addresses`]
618619 */
619- static void node_announcement (struct gossmap * map , size_t nann_off )
620+ static void node_announcement (struct gossmap * map , u64 nann_off )
620621{
621- const size_t feature_len_off = 2 + 64 ;
622+ const u64 feature_len_off = 2 + 64 ;
622623 size_t feature_len ;
623624 struct gossmap_node * n ;
624625 struct node_id id ;
@@ -629,7 +630,7 @@ static void node_announcement(struct gossmap *map, size_t nann_off)
629630 n -> nann_off = nann_off ;
630631}
631632
632- static bool reopen_store (struct gossmap * map , size_t ended_off )
633+ static bool reopen_store (struct gossmap * map , u64 ended_off )
633634{
634635 int fd ;
635636
@@ -659,7 +660,7 @@ static bool map_catchup(struct gossmap *map, bool *changed)
659660 for (; map -> map_end + sizeof (struct gossip_hdr ) < map -> map_size ;
660661 map -> map_end += reclen ) {
661662 struct gossip_hdr ghdr ;
662- size_t off ;
663+ u64 off ;
663664 u16 type , flags ;
664665
665666 map_copy (map , map -> map_end , & ghdr , sizeof (ghdr ));
@@ -765,8 +766,8 @@ static void destroy_map(struct gossmap *map)
765766struct localmod {
766767 struct short_channel_id scid ;
767768 /* If this is an entirely-local channel, here's its offset.
768- * Otherwise, 0xFFFFFFFF . */
769- u32 local_off ;
769+ * Otherwise, 0xFFFFFFFFFFFFFFFF . */
770+ u64 local_off ;
770771
771772 /* Non-NULL values mean change existing ones */
772773 struct localmod_changes {
@@ -776,16 +777,16 @@ struct localmod {
776777 const u16 * delay ;
777778 } changes [2 ];
778779
779- /* orig[n] defined if local_off == 0xFFFFFFFF */
780+ /* orig[n] defined if local_off == 0xFFFFFFFFFFFFFFFF */
780781 struct half_chan orig [2 ];
781782
782783 /* Original update offsets */
783- u32 orig_cupdate_off [2 ];
784+ u64 orig_cupdate_off [2 ];
784785};
785786
786787static bool localmod_is_local_chan (const struct localmod * mod )
787788{
788- return mod -> local_off != 0xFFFFFFFF ;
789+ return mod -> local_off != 0xFFFFFFFFFFFFFFFFULL ;
789790}
790791
791792struct gossmap_localmods {
@@ -833,7 +834,7 @@ bool gossmap_local_addchan(struct gossmap_localmods *localmods,
833834{
834835 be16 be16 ;
835836 be64 be64 ;
836- size_t off ;
837+ u64 off ;
837838 struct localmod mod ;
838839
839840 /* Don't create duplicate channels. */
@@ -944,7 +945,7 @@ bool gossmap_local_updatechan(struct gossmap_localmods *localmods,
944945 mod = & localmods -> mods [nmods ];
945946 mod -> scid = scidd -> scid ;
946947 memset (& mod -> changes , 0 , sizeof (mod -> changes ));
947- mod -> local_off = 0xFFFFFFFF ;
948+ mod -> local_off = 0xFFFFFFFFFFFFFFFFULL ;
948949 }
949950
950951 lc = & mod -> changes [scidd -> dir ];
@@ -1062,7 +1063,7 @@ void gossmap_apply_localmods(struct gossmap *map,
10621063 /* Is it all defined?
10631064 * This controls gossmap_chan_set(chan, h); */
10641065 if (was_set || all_changed )
1065- chan -> cupdate_off [h ] = 0xFFFFFFFF ;
1066+ chan -> cupdate_off [h ] = 0xFFFFFFFFFFFFFFFFULL ;
10661067 else
10671068 chan -> cupdate_off [h ] = 0 ;
10681069 }
@@ -1184,7 +1185,7 @@ struct gossmap *gossmap_load_fd_(const tal_t *ctx, int fd,
11841185 void * cb_arg ),
11851186 bool (* unknown_record )(struct gossmap * map ,
11861187 int type ,
1187- size_t off ,
1188+ u64 off ,
11881189 size_t msglen ,
11891190 void * cb_arg ),
11901191 void * cb_arg )
@@ -1224,7 +1225,7 @@ bool gossmap_chan_is_dying(const struct gossmap *map,
12241225 const struct gossmap_chan * c )
12251226{
12261227 struct gossip_hdr ghdr ;
1227- size_t off ;
1228+ u64 off ;
12281229
12291230 /* FIXME: put this flag in plus_scid_off instead? */
12301231 off = c -> cann_off - sizeof (ghdr );
@@ -1237,7 +1238,7 @@ struct amount_msat gossmap_chan_get_capacity(const struct gossmap *map,
12371238 const struct gossmap_chan * c )
12381239{
12391240 struct gossip_hdr ghdr ;
1240- size_t off ;
1241+ u64 off ;
12411242 u16 type ;
12421243 struct amount_sat sat ;
12431244 struct amount_msat msat ;
@@ -1418,7 +1419,7 @@ int gossmap_chan_get_feature(const struct gossmap *map,
14181419 int fbit )
14191420{
14201421 /* Note that first two bytes are message type */
1421- const size_t feature_len_off = 2 + (64 + 64 + 64 + 64 );
1422+ const u64 feature_len_off = 2 + (64 + 64 + 64 + 64 );
14221423 size_t feature_len ;
14231424
14241425 feature_len = map_be16 (map , c -> cann_off + feature_len_off );
@@ -1433,7 +1434,7 @@ u8 *gossmap_chan_get_features(const tal_t *ctx,
14331434{
14341435 u8 * ret ;
14351436 /* Note that first two bytes are message type */
1436- const size_t feature_len_off = 2 + (64 + 64 + 64 + 64 );
1437+ const u64 feature_len_off = 2 + (64 + 64 + 64 + 64 );
14371438 size_t feature_len ;
14381439
14391440 feature_len = map_be16 (map , c -> cann_off + feature_len_off );
@@ -1490,15 +1491,15 @@ void gossmap_chan_get_update_details(const struct gossmap *map,
14901491 struct amount_msat * htlc_maximum_msat )
14911492{
14921493 /* Note that first two bytes are message type */
1493- const size_t scid_off = chan -> cupdate_off [dir ] + 2 + (64 + 32 );
1494- const size_t timestamp_off = scid_off + 8 ;
1495- const size_t message_flags_off = timestamp_off + 4 ;
1496- const size_t channel_flags_off = message_flags_off + 1 ;
1497- const size_t cltv_expiry_delta_off = channel_flags_off + 1 ;
1498- const size_t htlc_minimum_off = cltv_expiry_delta_off + 2 ;
1499- const size_t fee_base_off = htlc_minimum_off + 8 ;
1500- const size_t fee_prop_off = fee_base_off + 4 ;
1501- const size_t htlc_maximum_off = fee_prop_off + 4 ;
1494+ const u64 scid_off = chan -> cupdate_off [dir ] + 2 + (64 + 32 );
1495+ const u64 timestamp_off = scid_off + 8 ;
1496+ const u64 message_flags_off = timestamp_off + 4 ;
1497+ const u64 channel_flags_off = message_flags_off + 1 ;
1498+ const u64 cltv_expiry_delta_off = channel_flags_off + 1 ;
1499+ const u64 htlc_minimum_off = cltv_expiry_delta_off + 2 ;
1500+ const u64 fee_base_off = htlc_minimum_off + 8 ;
1501+ const u64 fee_prop_off = fee_base_off + 4 ;
1502+ const u64 htlc_maximum_off = fee_prop_off + 4 ;
15021503
15031504 assert (gossmap_chan_set (chan , dir ));
15041505 /* Not allowed on local updates! */
@@ -1539,7 +1540,7 @@ int gossmap_node_get_feature(const struct gossmap *map,
15391540 const struct gossmap_node * n ,
15401541 int fbit )
15411542{
1542- const size_t feature_len_off = 2 + 64 ;
1543+ const u64 feature_len_off = 2 + 64 ;
15431544 size_t feature_len ;
15441545
15451546 if (n -> nann_off == 0 )
@@ -1557,7 +1558,7 @@ u8 *gossmap_node_get_features(const tal_t *ctx,
15571558{
15581559 u8 * ret ;
15591560 /* Note that first two bytes are message type */
1560- const size_t feature_len_off = 2 + 64 ;
1561+ const u64 feature_len_off = 2 + 64 ;
15611562 size_t feature_len ;
15621563
15631564 if (n -> nann_off == 0 )
@@ -1590,7 +1591,7 @@ bool gossmap_scidd_pubkey(struct gossmap *gossmap,
15901591 return sciddir_or_pubkey_from_node_id (sciddpk , & id );
15911592}
15921593
1593- size_t gossmap_lengths (const struct gossmap * map , size_t * total )
1594+ u64 gossmap_lengths (const struct gossmap * map , u64 * total )
15941595{
15951596 * total = map -> map_size ;
15961597 return map -> map_end ;
@@ -1648,7 +1649,7 @@ const void *gossmap_stream_next(const tal_t *ctx,
16481649
16491650 while (iter -> offset + sizeof (h .u .type ) <= map -> map_size ) {
16501651 void * ret ;
1651- size_t len ;
1652+ u64 len ;
16521653
16531654 map_copy (map , iter -> offset , & h , sizeof (h .u .type ));
16541655
0 commit comments