HomePhabricator

net: save the network type explicitly in CNetAddr

Description

net: save the network type explicitly in CNetAddr

Summary:

Before this change, we would analyze the contents of CNetAddr::ip[16]
in order to tell which type is an address. Change this by introducing a
new member CNetAddr::m_net that explicitly tells the type of the
address.

This is necessary because in BIP155 we will not be able to tell the
address type by just looking at its raw representation (e.g. both TORv3
and I2P are "seemingly random" 32 bytes).

As a side effect of this change we no longer need to store IPv4
addresses encoded as IPv6 addresses - we can store them in proper 4
bytes (will be done in a separate commit). Also the code gets
somewhat simplified - instead of
memcmp(ip, pchIPv4, sizeof(pchIPv4)) == 0 we can use
m_net == NET_IPV4.

Backport of core PR19534.

Depends on D9170 and D9171.

Test Plan:

ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9172

Details

Provenance
Vasil Dimov <vd@FreeBSD.org>Authored on May 14 2020, 08:47
FabienCommitted on Feb 5 2021, 17:32
FabienPushed on Feb 5 2021, 17:34
Reviewer
Restricted Project
Differential Revision
D9172: net: save the network type explicitly in CNetAddr
Parents
rABC2184cc687dab: net: improve encapsulation of CNetAddr
Branches
Unknown
Tags
Unknown