13
13
#include <errno.h>
14
14
#include <fcntl.h>
15
15
#include <gossipd/gossip_store_wiregen.h>
16
+ #include <inttypes.h>
16
17
#include <sys/mman.h>
17
18
#include <unistd.h>
18
19
#include <wire/peer_wire.h>
@@ -60,7 +61,7 @@ struct gossmap {
60
61
/* The memory map of the file: u8 for arithmetic portability */
61
62
u8 * mmap ;
62
63
/* 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 ;
64
65
65
66
/* Map of node id -> node */
66
67
struct nodeidx_htable * nodes ;
@@ -93,18 +94,18 @@ struct gossmap {
93
94
void * cb_arg );
94
95
bool (* unknown_record )(struct gossmap * map ,
95
96
int type ,
96
- size_t off ,
97
+ u64 off ,
97
98
size_t msglen ,
98
99
void * cb_arg );
99
100
void * cb_arg ;
100
101
};
101
102
102
103
/* 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 ,
104
105
void * dst , size_t len )
105
106
{
106
107
if (offset >= map -> map_size ) {
107
- size_t localoff = offset - map -> map_size ;
108
+ u64 localoff = offset - map -> map_size ;
108
109
assert (localoff + len <= tal_bytelen (map -> local ));
109
110
memcpy (dst , map -> local + localoff , len );
110
111
} else {
@@ -119,35 +120,35 @@ static void map_copy(const struct gossmap *map, size_t offset,
119
120
}
120
121
}
121
122
122
- static u8 map_u8 (const struct gossmap * map , size_t offset )
123
+ static u8 map_u8 (const struct gossmap * map , u64 offset )
123
124
{
124
125
u8 u8 ;
125
126
map_copy (map , offset , & u8 , sizeof (u8 ));
126
127
return u8 ;
127
128
}
128
129
129
- static u16 map_be16 (const struct gossmap * map , size_t offset )
130
+ static u16 map_be16 (const struct gossmap * map , u64 offset )
130
131
{
131
132
be16 be16 ;
132
133
map_copy (map , offset , & be16 , sizeof (be16 ));
133
134
return be16_to_cpu (be16 );
134
135
}
135
136
136
- static u32 map_be32 (const struct gossmap * map , size_t offset )
137
+ static u32 map_be32 (const struct gossmap * map , u64 offset )
137
138
{
138
139
be32 be32 ;
139
140
map_copy (map , offset , & be32 , sizeof (be32 ));
140
141
return be32_to_cpu (be32 );
141
142
}
142
143
143
- static u64 map_be64 (const struct gossmap * map , size_t offset )
144
+ static u64 map_be64 (const struct gossmap * map , u64 offset )
144
145
{
145
146
be64 be64 ;
146
147
map_copy (map , offset , & be64 , sizeof (be64 ));
147
148
return be64_to_cpu (be64 );
148
149
}
149
150
150
- static void map_nodeid (const struct gossmap * map , size_t offset ,
151
+ static void map_nodeid (const struct gossmap * map , u64 offset ,
151
152
struct node_id * id )
152
153
{
153
154
map_copy (map , offset , id , sizeof (* id ));
@@ -156,7 +157,7 @@ static void map_nodeid(const struct gossmap *map, size_t offset,
156
157
/* Returns optional or compulsory feature if set, otherwise -1 */
157
158
static int map_feature_test (const struct gossmap * map ,
158
159
int compulsory_bit ,
159
- size_t offset , size_t len )
160
+ u64 offset , size_t len )
160
161
{
161
162
size_t bytenum = compulsory_bit / 8 ;
162
163
u8 bits ;
@@ -373,8 +374,8 @@ static struct gossmap_chan *next_free_chan(struct gossmap *map)
373
374
}
374
375
375
376
static 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 ,
378
379
u32 n1idx , u32 n2idx )
379
380
{
380
381
struct gossmap_chan * chan = next_free_chan (map );
@@ -444,13 +445,13 @@ void gossmap_remove_node(struct gossmap *map, struct gossmap_node *node)
444
445
* * [`point`:`node_id_2`]
445
446
*/
446
447
static struct gossmap_chan * add_channel (struct gossmap * map ,
447
- size_t cannounce_off ,
448
+ u64 cannounce_off ,
448
449
size_t msglen )
449
450
{
450
451
/* 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 );
452
453
size_t feature_len ;
453
- size_t plus_scid_off ;
454
+ u64 plus_scid_off ;
454
455
struct short_channel_id scid ;
455
456
struct node_id node_id [2 ];
456
457
struct gossmap_node * n [2 ];
@@ -468,7 +469,7 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
468
469
chan = gossmap_find_chan (map , & scid );
469
470
if (chan ) {
470
471
/* 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 " !" ,
472
473
fmt_short_channel_id (tmpctx , scid ),
473
474
chan -> cann_off , cannounce_off );
474
475
return NULL ;
@@ -522,17 +523,17 @@ static struct gossmap_chan *add_channel(struct gossmap *map,
522
523
* * [`u32`:`fee_proportional_millionths`]
523
524
* * [`u64`:`htlc_maximum_msat`]
524
525
*/
525
- static void update_channel (struct gossmap * map , size_t cupdate_off )
526
+ static void update_channel (struct gossmap * map , u64 cupdate_off )
526
527
{
527
528
/* 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 ;
536
537
struct short_channel_id_dir scidd ;
537
538
struct gossmap_chan * chan ;
538
539
struct half_chan hc ;
@@ -578,7 +579,7 @@ static void update_channel(struct gossmap *map, size_t cupdate_off)
578
579
chan -> cupdate_off [chanflags & 1 ] = cupdate_off ;
579
580
}
580
581
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 )
582
583
{
583
584
struct short_channel_id scid ;
584
585
struct gossmap_chan * chan ;
@@ -616,9 +617,9 @@ struct short_channel_id gossmap_chan_scid(const struct gossmap *map,
616
617
* * [`u16`:`addrlen`]
617
618
* * [`addrlen*byte`:`addresses`]
618
619
*/
619
- static void node_announcement (struct gossmap * map , size_t nann_off )
620
+ static void node_announcement (struct gossmap * map , u64 nann_off )
620
621
{
621
- const size_t feature_len_off = 2 + 64 ;
622
+ const u64 feature_len_off = 2 + 64 ;
622
623
size_t feature_len ;
623
624
struct gossmap_node * n ;
624
625
struct node_id id ;
@@ -629,7 +630,7 @@ static void node_announcement(struct gossmap *map, size_t nann_off)
629
630
n -> nann_off = nann_off ;
630
631
}
631
632
632
- static bool reopen_store (struct gossmap * map , size_t ended_off )
633
+ static bool reopen_store (struct gossmap * map , u64 ended_off )
633
634
{
634
635
int fd ;
635
636
@@ -659,7 +660,7 @@ static bool map_catchup(struct gossmap *map, bool *changed)
659
660
for (; map -> map_end + sizeof (struct gossip_hdr ) < map -> map_size ;
660
661
map -> map_end += reclen ) {
661
662
struct gossip_hdr ghdr ;
662
- size_t off ;
663
+ u64 off ;
663
664
u16 type , flags ;
664
665
665
666
map_copy (map , map -> map_end , & ghdr , sizeof (ghdr ));
@@ -764,8 +765,8 @@ static void destroy_map(struct gossmap *map)
764
765
struct localmod {
765
766
struct short_channel_id scid ;
766
767
/* If this is an entirely-local channel, here's its offset.
767
- * Otherwise, 0xFFFFFFFF . */
768
- u32 local_off ;
768
+ * Otherwise, 0xFFFFFFFFFFFFFFFF . */
769
+ u64 local_off ;
769
770
770
771
/* Are updates in either direction set? */
771
772
bool updates_set [2 ];
@@ -822,7 +823,7 @@ bool gossmap_local_addchan(struct gossmap_localmods *localmods,
822
823
{
823
824
be16 be16 ;
824
825
be64 be64 ;
825
- size_t off ;
826
+ u64 off ;
826
827
struct localmod mod ;
827
828
828
829
/* Don't create duplicate channels. */
@@ -1090,7 +1091,7 @@ struct gossmap *gossmap_load_fd_(const tal_t *ctx, int fd,
1090
1091
void * cb_arg ),
1091
1092
bool (* unknown_record )(struct gossmap * map ,
1092
1093
int type ,
1093
- size_t off ,
1094
+ u64 off ,
1094
1095
size_t msglen ,
1095
1096
void * cb_arg ),
1096
1097
void * cb_arg )
@@ -1130,7 +1131,7 @@ bool gossmap_chan_is_dying(const struct gossmap *map,
1130
1131
const struct gossmap_chan * c )
1131
1132
{
1132
1133
struct gossip_hdr ghdr ;
1133
- size_t off ;
1134
+ u64 off ;
1134
1135
1135
1136
/* FIXME: put this flag in plus_scid_off instead? */
1136
1137
off = c -> cann_off - sizeof (ghdr );
@@ -1144,7 +1145,7 @@ bool gossmap_chan_get_capacity(const struct gossmap *map,
1144
1145
struct amount_sat * amount )
1145
1146
{
1146
1147
struct gossip_hdr ghdr ;
1147
- size_t off ;
1148
+ u64 off ;
1148
1149
u16 type ;
1149
1150
1150
1151
/* Fail for local channels */
@@ -1319,7 +1320,7 @@ int gossmap_chan_get_feature(const struct gossmap *map,
1319
1320
int fbit )
1320
1321
{
1321
1322
/* Note that first two bytes are message type */
1322
- const size_t feature_len_off = 2 + (64 + 64 + 64 + 64 );
1323
+ const u64 feature_len_off = 2 + (64 + 64 + 64 + 64 );
1323
1324
size_t feature_len ;
1324
1325
1325
1326
feature_len = map_be16 (map , c -> cann_off + feature_len_off );
@@ -1334,7 +1335,7 @@ u8 *gossmap_chan_get_features(const tal_t *ctx,
1334
1335
{
1335
1336
u8 * ret ;
1336
1337
/* Note that first two bytes are message type */
1337
- const size_t feature_len_off = 2 + (64 + 64 + 64 + 64 );
1338
+ const u64 feature_len_off = 2 + (64 + 64 + 64 + 64 );
1338
1339
size_t feature_len ;
1339
1340
1340
1341
feature_len = map_be16 (map , c -> cann_off + feature_len_off );
@@ -1391,15 +1392,15 @@ void gossmap_chan_get_update_details(const struct gossmap *map,
1391
1392
struct amount_msat * htlc_maximum_msat )
1392
1393
{
1393
1394
/* Note that first two bytes are message type */
1394
- const size_t scid_off = chan -> cupdate_off [dir ] + 2 + (64 + 32 );
1395
- const size_t timestamp_off = scid_off + 8 ;
1396
- const size_t message_flags_off = timestamp_off + 4 ;
1397
- const size_t channel_flags_off = message_flags_off + 1 ;
1398
- const size_t cltv_expiry_delta_off = channel_flags_off + 1 ;
1399
- const size_t htlc_minimum_off = cltv_expiry_delta_off + 2 ;
1400
- const size_t fee_base_off = htlc_minimum_off + 8 ;
1401
- const size_t fee_prop_off = fee_base_off + 4 ;
1402
- const size_t htlc_maximum_off = fee_prop_off + 4 ;
1395
+ const u64 scid_off = chan -> cupdate_off [dir ] + 2 + (64 + 32 );
1396
+ const u64 timestamp_off = scid_off + 8 ;
1397
+ const u64 message_flags_off = timestamp_off + 4 ;
1398
+ const u64 channel_flags_off = message_flags_off + 1 ;
1399
+ const u64 cltv_expiry_delta_off = channel_flags_off + 1 ;
1400
+ const u64 htlc_minimum_off = cltv_expiry_delta_off + 2 ;
1401
+ const u64 fee_base_off = htlc_minimum_off + 8 ;
1402
+ const u64 fee_prop_off = fee_base_off + 4 ;
1403
+ const u64 htlc_maximum_off = fee_prop_off + 4 ;
1403
1404
1404
1405
assert (gossmap_chan_set (chan , dir ));
1405
1406
/* Not allowed on local updates! */
@@ -1440,7 +1441,7 @@ int gossmap_node_get_feature(const struct gossmap *map,
1440
1441
const struct gossmap_node * n ,
1441
1442
int fbit )
1442
1443
{
1443
- const size_t feature_len_off = 2 + 64 ;
1444
+ const u64 feature_len_off = 2 + 64 ;
1444
1445
size_t feature_len ;
1445
1446
1446
1447
if (n -> nann_off == 0 )
@@ -1458,7 +1459,7 @@ u8 *gossmap_node_get_features(const tal_t *ctx,
1458
1459
{
1459
1460
u8 * ret ;
1460
1461
/* Note that first two bytes are message type */
1461
- const size_t feature_len_off = 2 + 64 ;
1462
+ const u64 feature_len_off = 2 + 64 ;
1462
1463
size_t feature_len ;
1463
1464
1464
1465
if (n -> nann_off == 0 )
@@ -1491,7 +1492,7 @@ bool gossmap_scidd_pubkey(struct gossmap *gossmap,
1491
1492
return sciddir_or_pubkey_from_node_id (sciddpk , & id );
1492
1493
}
1493
1494
1494
- size_t gossmap_lengths (const struct gossmap * map , size_t * total )
1495
+ u64 gossmap_lengths (const struct gossmap * map , u64 * total )
1495
1496
{
1496
1497
* total = map -> map_size ;
1497
1498
return map -> map_end ;
@@ -1549,7 +1550,7 @@ const void *gossmap_stream_next(const tal_t *ctx,
1549
1550
1550
1551
while (iter -> offset + sizeof (h .u .type ) <= map -> map_size ) {
1551
1552
void * ret ;
1552
- size_t len ;
1553
+ u64 len ;
1553
1554
1554
1555
map_copy (map , iter -> offset , & h , sizeof (h .u .type ));
1555
1556
0 commit comments