Skip to content

Commit

Permalink
scripted-diff: use SER_PARAMS_OPFUNC
Browse files Browse the repository at this point in the history
-BEGIN VERIFY SCRIPT-
sed -i 's/WithParams(\(CAddress::V[12]_[A-Z]*\) *, */\1(/g' $(git grep -l 'WithParams' src/)
sed -i 's/WithParams(\(CNetAddr::V[12]\) *, */\1(/g' $(git grep -l 'WithParams' src/)
sed -i 's@\(CNetAddr::V1.CService{}.*\)    //@\1                //@' src/test/util/net.cpp
-END VERIFY SCRIPT-
  • Loading branch information
ajtowns committed Sep 14, 2023
1 parent 5e5c8f8 commit fb6a2ab
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ util::Result<std::unique_ptr<AddrMan>> LoadAddrman(const NetGroupManager& netgro
void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors)
{
LOG_TIME_SECONDS(strprintf("Flush %d outbound block-relay-only peer addresses to anchors.dat", anchors.size()));
SerializeFileDB("anchors", anchors_db_path, WithParams(CAddress::V2_DISK, anchors));
SerializeFileDB("anchors", anchors_db_path, CAddress::V2_DISK(anchors));
}

std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path)
{
std::vector<CAddress> anchors;
try {
DeserializeFileDB(anchors_db_path, WithParams(CAddress::V2_DISK, anchors));
DeserializeFileDB(anchors_db_path, CAddress::V2_DISK(anchors));
LogPrintf("Loaded %i addresses from %s\n", anchors.size(), fs::quoted(fs::PathToString(anchors_db_path.filename())));
} catch (const std::exception&) {
anchors.clear();
Expand Down
6 changes: 3 additions & 3 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,8 +1415,8 @@ void PeerManagerImpl::PushNodeVersion(CNode& pnode, const Peer& peer)

const bool tx_relay{!RejectIncomingTxs(pnode)};
m_connman.PushMessage(&pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, my_services, nTime,
your_services, WithParams(CNetAddr::V1, addr_you), // Together the pre-version-31402 serialization of CAddress "addrYou" (without nTime)
my_services, WithParams(CNetAddr::V1, CService{}), // Together the pre-version-31402 serialization of CAddress "addrMe" (without nTime)
your_services, CNetAddr::V1(addr_you), // Together the pre-version-31402 serialization of CAddress "addrYou" (without nTime)
my_services, CNetAddr::V1(CService{}), // Together the pre-version-31402 serialization of CAddress "addrMe" (without nTime)
nonce, strSubVersion, nNodeStartingHeight, tx_relay));

if (fLogIPs) {
Expand Down Expand Up @@ -3293,7 +3293,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
nTime = 0;
}
vRecv.ignore(8); // Ignore the addrMe service bits sent by the peer
vRecv >> WithParams(CNetAddr::V1, addrMe);
vRecv >> CNetAddr::V1(addrMe);
if (!pfrom.IsInboundConn())
{
m_addrman.SetServices(pfrom.addr, nServices);
Expand Down
2 changes: 1 addition & 1 deletion src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ static auto MakeCorruptPeersDat()
std::optional<CNetAddr> resolved{LookupHost("252.2.2.2", false)};
BOOST_REQUIRE(resolved.has_value());
AddrInfo info = AddrInfo(addr, resolved.value());
s << WithParams(CAddress::V1_DISK, info);
s << CAddress::V1_DISK(info);

return s;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/fuzz/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ CNetAddr RandAddr(FuzzedDataProvider& fuzzed_data_provider, FastRandomContext& f
s << net;
s << fast_random_context.randbytes(net_len_map.at(net));

s >> WithParams(CAddress::V2_NETWORK, addr);
s >> CAddress::V2_NETWORK(addr);
}

// Return a dummy IPv4 5.5.5.5 if we generated an invalid address.
Expand Down
4 changes: 2 additions & 2 deletions src/test/net_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
std::chrono::microseconds time_received_dummy{0};

const auto msg_version =
msg_maker.Make(NetMsgType::VERSION, PROTOCOL_VERSION, services, time, services, WithParams(CAddress::V1_NETWORK, peer_us));
msg_maker.Make(NetMsgType::VERSION, PROTOCOL_VERSION, services, time, services, CAddress::V1_NETWORK(peer_us));
CDataStream msg_version_stream{msg_version.data, SER_NETWORK, PROTOCOL_VERSION};

m_node.peerman->ProcessMessage(
Expand All @@ -876,7 +876,7 @@ BOOST_AUTO_TEST_CASE(initial_advertise_from_version_message)
DataStream s{data};
std::vector<CAddress> addresses;

s >> WithParams(CAddress::V1_NETWORK, addresses);
s >> CAddress::V1_NETWORK(addresses);

for (const auto& addr : addresses) {
if (addr == expected) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/netbase_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ BOOST_AUTO_TEST_CASE(caddress_serialize_v1)
{
DataStream s{};

s << WithParams(CAddress::V1_NETWORK, fixture_addresses);
s << CAddress::V1_NETWORK(fixture_addresses);
BOOST_CHECK_EQUAL(HexStr(s), stream_addrv1_hex);
}

Expand All @@ -570,15 +570,15 @@ BOOST_AUTO_TEST_CASE(caddress_unserialize_v1)
DataStream s{ParseHex(stream_addrv1_hex)};
std::vector<CAddress> addresses_unserialized;

s >> WithParams(CAddress::V1_NETWORK, addresses_unserialized);
s >> CAddress::V1_NETWORK(addresses_unserialized);
BOOST_CHECK(fixture_addresses == addresses_unserialized);
}

BOOST_AUTO_TEST_CASE(caddress_serialize_v2)
{
DataStream s{};

s << WithParams(CAddress::V2_NETWORK, fixture_addresses);
s << CAddress::V2_NETWORK(fixture_addresses);
BOOST_CHECK_EQUAL(HexStr(s), stream_addrv2_hex);
}

Expand All @@ -587,7 +587,7 @@ BOOST_AUTO_TEST_CASE(caddress_unserialize_v2)
DataStream s{ParseHex(stream_addrv2_hex)};
std::vector<CAddress> addresses_unserialized;

s >> WithParams(CAddress::V2_NETWORK, addresses_unserialized);
s >> CAddress::V2_NETWORK(addresses_unserialized);
BOOST_CHECK(fixture_addresses == addresses_unserialized);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/util/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void ConnmanTestMsg::Handshake(CNode& node,
Using<CustomUintFormatter<8>>(remote_services), //
int64_t{}, // dummy time
int64_t{}, // ignored service bits
WithParams(CNetAddr::V1, CService{}), // dummy
CNetAddr::V1(CService{}), // dummy
int64_t{}, // ignored service bits
WithParams(CNetAddr::V1, CService{}), // ignored
CNetAddr::V1(CService{}), // ignored
uint64_t{1}, // dummy nonce
std::string{}, // dummy subver
int32_t{}, // dummy starting_height
Expand Down

0 comments on commit fb6a2ab

Please sign in to comment.