|
@ -130,16 +130,25 @@ static void map_nodeid(const struct gossmap *map, size_t offset, |
|
|
map_copy(map, offset, id, sizeof(*id)); |
|
|
map_copy(map, offset, id, sizeof(*id)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static bool map_feature_set(const struct gossmap *map, int bit, |
|
|
/* Returns optional or compulsory feature if set, otherwise -1 */ |
|
|
|
|
|
static int map_feature_test(const struct gossmap *map, |
|
|
|
|
|
int compulsory_bit, |
|
|
size_t offset, size_t len) |
|
|
size_t offset, size_t len) |
|
|
{ |
|
|
{ |
|
|
size_t bytenum = bit / 8; |
|
|
size_t bytenum = compulsory_bit / 8; |
|
|
|
|
|
u8 bits; |
|
|
|
|
|
|
|
|
|
|
|
assert(COMPULSORY_FEATURE(compulsory_bit) == compulsory_bit); |
|
|
if (bytenum >= len) |
|
|
if (bytenum >= len) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
/* Note reversed! */ |
|
|
/* Note reversed! */ |
|
|
return map_u8(map, offset + len - 1 - bytenum) & (1 << (bit % 8)); |
|
|
bits = map_u8(map, offset + len - 1 - bytenum); |
|
|
|
|
|
if (bits & (1 << (compulsory_bit % 8))) |
|
|
|
|
|
return compulsory_bit; |
|
|
|
|
|
if (bits & (1 << (OPTIONAL_FEATURE(compulsory_bit) % 8))) |
|
|
|
|
|
return OPTIONAL_FEATURE(compulsory_bit); |
|
|
|
|
|
return -1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* These values can change across calls to gossmap_check. */ |
|
|
/* These values can change across calls to gossmap_check. */ |
|
@ -877,13 +886,8 @@ int gossmap_chan_has_feature(const struct gossmap *map, |
|
|
|
|
|
|
|
|
feature_len = map_be16(map, c->cann_off + feature_len_off); |
|
|
feature_len = map_be16(map, c->cann_off + feature_len_off); |
|
|
|
|
|
|
|
|
if (map_feature_set(map, OPTIONAL_FEATURE(fbit), |
|
|
return map_feature_test(map, COMPULSORY_FEATURE(fbit), |
|
|
c->cann_off + feature_len_off + 2, feature_len)) |
|
|
c->cann_off + feature_len_off + 2, feature_len); |
|
|
return OPTIONAL_FEATURE(fbit); |
|
|
|
|
|
if (map_feature_set(map, COMPULSORY_FEATURE(fbit), |
|
|
|
|
|
c->cann_off + feature_len_off + 2, feature_len)) |
|
|
|
|
|
return COMPULSORY_FEATURE(fbit); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* BOLT #7:
|
|
|
/* BOLT #7:
|
|
@ -911,11 +915,6 @@ int gossmap_node_has_feature(const struct gossmap *map, |
|
|
|
|
|
|
|
|
feature_len = map_be16(map, n->nann_off + feature_len_off); |
|
|
feature_len = map_be16(map, n->nann_off + feature_len_off); |
|
|
|
|
|
|
|
|
if (map_feature_set(map, OPTIONAL_FEATURE(fbit), |
|
|
return map_feature_test(map, COMPULSORY_FEATURE(fbit), |
|
|
n->nann_off + feature_len_off + 2, feature_len)) |
|
|
n->nann_off + feature_len_off + 2, feature_len); |
|
|
return OPTIONAL_FEATURE(fbit); |
|
|
|
|
|
if (map_feature_set(map, COMPULSORY_FEATURE(fbit), |
|
|
|
|
|
n->nann_off + feature_len_off + 2, feature_len)) |
|
|
|
|
|
return COMPULSORY_FEATURE(fbit); |
|
|
|
|
|
return -1; |
|
|
|
|
|
} |
|
|
} |
|
|