refactor: Use span instead of vector for data in util/asmap

This prevents holding the asmap data in memory twice.

The version hash changes due to spans being serialized without their size-prefix (unlike vectors).
This commit is contained in:
Fabian Jahr
2025-04-23 00:13:32 +02:00
parent 385c34a052
commit cf4943fdcd
13 changed files with 87 additions and 51 deletions

View File

@@ -325,7 +325,7 @@ BOOST_AUTO_TEST_CASE(subnet_test)
BOOST_AUTO_TEST_CASE(netbase_getgroup)
{
NetGroupManager netgroupman{{}}; // use /16
auto netgroupman{NetGroupManager::NoAsmap()}; // use /16
BOOST_CHECK(netgroupman.GetGroup(ResolveIP("127.0.0.1")) == std::vector<unsigned char>({0})); // Local -> !Routable()
BOOST_CHECK(netgroupman.GetGroup(ResolveIP("257.0.0.1")) == std::vector<unsigned char>({0})); // !Valid -> !Routable()
BOOST_CHECK(netgroupman.GetGroup(ResolveIP("10.0.0.1")) == std::vector<unsigned char>({0})); // RFC1918 -> !Routable()
@@ -631,7 +631,7 @@ BOOST_AUTO_TEST_CASE(asmap_test_vectors)
"63dc33d28f757a4a5e15d6a08"_hex};
// Construct NetGroupManager with this data.
NetGroupManager netgroup{std::vector(ASMAP_DATA.begin(), ASMAP_DATA.end())};
auto netgroup{NetGroupManager::WithEmbeddedAsmap(ASMAP_DATA)};
BOOST_CHECK(netgroup.UsingASMap());
// Check some randomly-generated IPv6 addresses in it (biased towards the very beginning and