Commit graph

105 commits

Author SHA1 Message Date
Jon Atack
4ecfd3eaf4 Inline short, often-called, rarely-changed basic CNetAddr getters
and make them nodiscard.

Member functions containing a few lines of code are usually inlined, either
implicitly by defining them in the declaration as done here, or declared inline.

References
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-inline
https://google.github.io/styleguide/cppguide#Inline_Functions
https://www.ibm.com/docs/en/i/7.1?topic=only-inline-member-functions-c
2023-07-19 12:43:05 -06:00
Jon Atack
fb4265747c Add and use CNetAddr::HasCJDNSPrefix() helper 2023-07-19 11:49:27 -06:00
Martin Zumsande
e4d541c7cf net, refactor: pass reference for peer address in GetReachabilityFrom
The address of the peer always exists (because addr is a member of
CNode), so it was not possible to pass a nullptr before.
Also remove NET_UNKNOWN, which is unused now.
2023-06-05 11:02:47 -04:00
Andrew Chow
35fbc97208
Merge bitcoin/bitcoin#25619: net: avoid overriding non-virtual ToString() in CService and use better naming
c9d548c91f net: remove CService::ToStringPort() (Vasil Dimov)
fd4f0f41e9 gui: simplify OptionsDialog::updateDefaultProxyNets() (Vasil Dimov)
96c791dd20 net: remove CService::ToString() use ToStringAddrPort() instead (Vasil Dimov)
944a9de08a net: remove CNetAddr::ToString() and use ToStringAddr() instead (Vasil Dimov)
043b9de59a scripted-diff: rename ToStringIP[Port]() to ToStringAddr[Port]() (Vasil Dimov)

Pull request description:

  Before this PR we had the somewhat confusing combination of methods:

  `CNetAddr::ToStringIP()`
  `CNetAddr::ToString()` (duplicate of the above)
  `CService::ToStringIPPort()`
  `CService::ToString()` (duplicate of the above, overrides a non-virtual method from `CNetAddr`)
  `CService::ToStringPort()`

  Avoid [overriding non-virtual methods](https://github.com/bitcoin/bitcoin/pull/25349/#issuecomment-1185226396).

  "IP" stands for "Internet Protocol" and while sometimes "IP addresses" are called just "IPs", it is incorrect to call Tor or I2P addresses "IPs". Thus use "Addr" instead of "IP".

  Change the above to:

  `CNetAddr::ToStringAddr()`
  `CService::ToStringAddrPort()`

  The changes touch a lot of files, but are mostly mechanical.

ACKs for top commit:
  sipa:
    utACK c9d548c91f
  achow101:
    ACK c9d548c91f
  jonatack:
    re-ACK c9d548c91f only change since my previous reviews is rebase, but as a sanity check rebased to current master and at each commit quickly re-reviewed and re-verified clean build and green unit tests
  LarryRuane:
    ACK c9d548c91f

Tree-SHA512: 633fb044bdecf9f551b5e3314c385bf10e2b78e8027dc51ec324b66b018da35e5b01f3fbe6295bbc455ea1bcd1a3629de1918d28de510693afaf6a52693f2157
2023-02-17 13:34:40 -05:00
Jon Atack
0e015146bd net: remove orphaned CSubNet::SanityCheck()
CSubNet::SanityCheck() was added in #20140, and not removed in #22570
when it became orphaned code.
2023-02-15 14:41:58 -08:00
Sebastian Falbesoner
3076f1815d doc: net: fix link to onion address encoding scheme [ONIONADDRESS]
Instead of referring to a fixed line number to a file in master (which
is obviously always quickly outdated), use a permalink tied to the
latest commit.
2023-01-10 14:23:27 +01:00
Hennadii Stepanov
306ccd4927
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
- 2021: f47dda2c58
- 2020: fa0074e2d8
- 2019: aaaaad6ac9
2022-12-24 23:49:50 +00:00
Vasil Dimov
c9d548c91f
net: remove CService::ToStringPort()
It is used only internally in `CService::ToStringAddrPort()`.
2022-12-12 11:54:23 +01:00
Vasil Dimov
96c791dd20
net: remove CService::ToString() use ToStringAddrPort() instead
Both methods do the same thing, so simplify to having just one.

`ToString()` is too generic in this case and it is unclear what it does,
given that there are similar methods:
`ToStringAddr()` (inherited from `CNetAddr`),
`ToStringPort()` and
`ToStringAddrPort()`.
2022-12-12 11:54:20 +01:00
Vasil Dimov
944a9de08a
net: remove CNetAddr::ToString() and use ToStringAddr() instead
Both methods do the same thing, so simplify to having just one.

Further, `CService` inherits `CNetAddr` and `CService::ToString()`
overrides `CNetAddr::ToString()` but the latter is not virtual which
may be confusing. Avoid such a confusion by not having non-virtual
methods with the same names in inheritance.
2022-12-12 11:48:31 +01:00
Vasil Dimov
043b9de59a
scripted-diff: rename ToStringIP[Port]() to ToStringAddr[Port]()
"IP" stands for "Internet Protocol".

"IP address" is sometimes shortened to just "IP" or "address".

However, Tor or I2P addresses are not "IP addresses", nor "IPs".

Thus, use "Addr" instead of "IP" for addresses that could be IP, Tor or
I2P addresses:

`CService::ToStringIPPort()` -> `CService::ToStringAddrPort()`
`CNetAddr::ToStringIP()` -> `CNetAddr::ToStringAddr()`

-BEGIN VERIFY SCRIPT-
sed -i 's/ToStringIPPort/ToStringAddrPort/g' -- $(git grep -l ToStringIPPort src)
sed -i 's/ToStringIP/ToStringAddr/g' -- $(git grep -l ToStringIP src)
-END VERIFY SCRIPT-
2022-12-12 11:48:30 +01:00
dergoegge
c9ba3f836e [netaddress] Make OnionToString public 2022-11-17 14:52:45 +00:00
fanquake
7aa40f5563
refactor: use C++11 default initializers 2022-05-17 17:18:58 +01:00
fanquake
c2b295881f
tidy: add readability-redundant-declaration 2022-05-01 10:39:40 +01:00
MacroFake
fa7078d84f
scripted-diff: Rename ValidAsCString to ContainsNoNUL
-BEGIN VERIFY SCRIPT-
 sed -i 's,ValidAsCString,ContainsNoNUL,g' $(git grep -l ValidAsCString)
-END VERIFY SCRIPT-
2022-04-27 14:16:35 +02:00
Pieter Wuille
8ffbd1412d Make DecodeBase{32,64} take string_view arguments 2022-04-27 14:12:55 +02:00
Pieter Wuille
78f3ac51b7 Make DecodeBase{32,64} return optional instead of taking bool* 2022-04-27 14:12:55 +02:00
Pieter Wuille
a65931e3ce Make DecodeBase{32,64} always return vector, not string
Base32/base64 are mechanisms for encoding binary data. That they'd
decode to a string is just bizarre. The fact that they'd do that
based on the type of input arguments even more so.
2022-04-27 14:12:55 +02:00
John Newbery
1b978a7e8c [netgroupman] Move GetMappedAS() and GetGroup() logic to NetGroupManager
Reviewer hint: use:

`git diff --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space`
2022-04-20 14:35:52 +01:00
John Newbery
ddb4101e63 [net] Only use public CNetAddr functions and data in GetMappedAS() and GetGroup()
Also change parameter/variable names. This makes the next commit mostly
move-only.
2022-04-20 14:35:52 +01:00
Vasil Dimov
36ee76d1af
net: remove unused CNetAddr::GetHash() 2022-02-11 15:21:52 +01:00
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
Pieter Wuille
11daf6ceb1 More Span simplifications
Based on suggestions by MarcoFalke <falke.marco@gmail.com>
2021-11-29 17:59:44 -05:00
Pieter Wuille
568dd2f839 Replace MakeSpan helper with Span deduction guide 2021-11-29 17:58:53 -05:00
Vasil Dimov
f9c28330a0
net: take the first 4 random bits from CJDNS addresses in GetGroup()
CJDNS addresses start with constant 8 bits, so in order to account for
the first 4 random ones, we must take the first 12. Otherwise the entire
CJDNS network will belong to one group.
2021-11-03 14:58:54 +01:00
Vasil Dimov
c2d751abba
net: take CJDNS into account in CNetAddr::GetReachabilityFrom()
This way `GetLocal()` will pick our CJDNS address for a CJDNS peer.
2021-11-03 14:58:52 +01:00
Vasil Dimov
aedd02ef27
net: make it possible to connect to CJDNS addresses
Connecting to CJDNS addresses works without a proxy, just like
connecting to an IPv6 address. Thus adapt `CService::GetSockAddr()` to
retrieve the `struct sockaddr*` even for `CService::IsCJDNS()` objects.
2021-11-03 14:41:09 +01:00
Amiti Uttarwar
dd8f7f2500 scripted-diff: Rename CAddrMan to AddrMan
-BEGIN VERIFY SCRIPT-
git grep -l CAddrMan src/ test/ | xargs sed -i 's/CAddrMan/AddrMan/g'
-END VERIFY SCRIPT-
2021-09-28 22:21:10 -04:00
John Newbery
bfdf4ef334 [asmap] Remove SanityCheckASMap() from netaddress
SanityCheckASMap(asmap, bits) simply calls through to SanityCheckASMap(asmap)
in util/asmap. Update all callers to simply call that function.
2021-09-07 13:31:10 +01:00
W. J. van der Laan
d968616422
Merge bitcoin/bitcoin#22179: Torv2 removal followups
00b875ba94 addrman: remove invalid addresses when unserializing (Vasil Dimov)
bdb62096f0 fuzz: reduce possible networks check (Vasil Dimov)
a164cd3ba6 net: simplify CNetAddr::IsRoutable() (Vasil Dimov)

Pull request description:

  * Simplify some code, now that we know `CNetAddr::IsRFC4193()` and `CNetAddr::IsTor()` cannot be `true` at the same time.
  * Drop Tor v2 addresses when loading addrman from `peers.dat` - they would have been loaded as dummy-all-zeros IPv6 addresses and linger in addrman, wasting space.

ACKs for top commit:
  sipa:
    ACK 00b875ba94. Reviewed the code, and tested with -DDEBUG_ADDRMAN (unit tests + mainnet run with peers.dat that contained v2 onions).
  laanwj:
    Code review and lightly tested ACK 00b875ba94
  jonatack:
    ACK 00b875ba94 reviewed, debug-built with -DEBUG_ADDRMAN rebased to current master, restarted node on mainnet/signet/testnet and verified that on each chain -addrinfo shows no change in address counts (as expected). Added some sanity check asserts, rebuilt/re-ran test. Checked that the new test fails on master with "test/addrman_tests.cpp(824): error: in "addrman_tests/remove_invalid": check addrman.size() == 2 has failed [4 != 2]"
  jarolrod:
    ACK 00b875ba94

Tree-SHA512: 6ed8e6745134b1b94fffaba28482de909ea39483b46b7f57bda61cdbae7a51251d15cb674de3631772fbeabe153d77a19269f96e62a89102a2d5c01e48f0ba06
2021-07-08 17:20:35 +02:00
Jon Atack
c274574458
p2p, rpc, fuzz: various tiny follow-ups 2021-06-06 15:49:22 +02:00
Vasil Dimov
a164cd3ba6
net: simplify CNetAddr::IsRoutable()
Reduce the condition `IsRFC4193() && !IsTor()` to `IsRFC4193()`. We know
that if `IsRFC4193()` is `true` then, for sure, the address is not Tor,
so `!IsTor()` is also `true`.
2021-06-04 16:09:25 +02:00
Jon Atack
8be56f0f8e
p2p, refactor: extract OnionToString() from CNetAddr::ToStringIp() 2021-06-03 13:36:50 +02:00
Jon Atack
5f9d3c09b4
p2p: remove torv2 from CNetAddr::ToStringIP() 2021-06-03 13:36:48 +02:00
Jon Atack
3d39042144
p2p: remove torv2 in SetIP() and ADDR_TORV2_SIZE constant 2021-06-03 13:36:46 +02:00
Jon Atack
4192a74413
p2p: ignore torv2-in-ipv6 addresses in SetLegacyIPv6() 2021-06-03 13:36:42 +02:00
Jon Atack
1d631e956f
p2p: remove BIP155Network::TORV2 from GetBIP155Network() 2021-06-03 13:36:40 +02:00
Jon Atack
7d1769bc45
p2p: remove torv2 from SetNetFromBIP155Network() 2021-05-28 01:46:29 +02:00
Jon Atack
c56a1c9b18
p2p: drop onions from IsAddrV1Compatible(), no longer relay torv2 2021-05-28 01:42:21 +02:00
Jon Atack
f8e94002fc
p2p: remove torv2/ADDR_TORV2_SIZE from SetTor() 2021-05-27 22:54:39 +02:00
W. J. van der Laan
6c280adcd8 net: Return IPv6 scope id in CNetAddr::ToStringIP()
If a scope id is provided, return it back in the string representation.
Also bring back the test. Closes #21982.

Co-authored-by: Jon Atack <jon@atack.com>
2021-05-18 21:01:32 +02:00
practicalswift
54548bae80 net: Avoid calling getnameinfo when formatting IPv6 addresses in CNetAddr::ToStringIP 2021-04-22 15:52:14 +00:00
practicalswift
c10f27fdb2 net: Make IPv6ToString do zero compression as described in RFC 5952 2021-04-22 15:53:53 +00:00
practicalswift
58580a827d net: Avoid calling getnameinfo when formatting IPv4 addresses in CNetAddr::ToStringIP 2021-04-01 08:06:01 +00:00
practicalswift
5858057384 net: Add IPv4ToString (we already have IPv6ToString) 2021-04-01 08:00:48 +00:00
Vasil Dimov
9559bd1404
net: add I2P to the reachability map
Update `CNetAddr::GetReachabilityFrom()` to recognize the I2P network so
that we would prefer to advertise our I2P address to I2P peers.
2021-03-01 18:19:46 +01:00
Vasil Dimov
cff65c4a27
net: extend CNetAddr::SetSpecial() to support I2P
Recognize also I2P addresses in the form `base32hashofpublickey.b32.i2p`
from `CNetAddr::SetSpecial()`.

This makes `Lookup()` support them, which in turn makes it possible to
manually connect to an I2P node by using
`-proxy=i2p_socks5_proxy:port -addnode=i2p_address.b32.i2p:port`

Co-authored-by: Lucas Ontivero <lucasontivero@gmail.com>
2021-03-01 13:22:11 +01:00
Vasil Dimov
94d335da7f
net: allow CSubNet of non-IP networks
Allow creation of valid `CSubNet` objects of non-IP networks and only
match the single address they were created from (like /32 for IPv4 or
/128 for IPv6).

This fixes a deficiency in `CConnman::DisconnectNode(const CNetAddr& addr)`
and in `BanMan` which assume that creating a subnet from any address
using the `CSubNet(CNetAddr)` constructor would later match that address
only. Before this change a non-IP subnet would be invalid and would not
match any address.
2021-01-10 15:51:15 +01:00
Lucas Ontivero
f7264fff0a Check if Cjdns address is valid 2020-12-14 14:48:52 -03:00
lontivero
d355a302d9 Break circuit earlier
There is no need to calculate the full checksum for an Tor v3 onion
address if the version byte is not the expected one.
2020-11-16 15:54:24 -03:00