Skip to content

Commit 7740ebc

Browse files
committed
Merge bitcoin/bitcoin#22648: doc, test: improve i2p/tor docs and i2p reachable unit tests
0175977 Add I2P network SetReachable/IsReachable unit test assertions (Jon Atack) b87a9c4 Improve doc/i2p.md regarding I2P router options/versions (Jon Atack) bebcf78 Update i2p.md and tor.md regarding -onlynet config option (Jon Atack) Pull request description: This pull addresses bitcoin/bitcoin#22634 (comment) and various user feedback/questions, updates the -onlynet documentation in doc/i2p.md and doc/tor.md per #22651 (src/init.cpp is already fine) and fills in some missing I2P unit test coverage. Note: this PR depends in part on whether #22651 is merged in order to propose the correct -onlynet documentation (it is currently aligned with the change in #22651), so that PR should be decided or merged first. ACKs for top commit: Rspigler: Re-ACK 0175977 prayank23: reACK bitcoin/bitcoin@0175977 vasild: ACK 0175977 Tree-SHA512: ae606437522bfccdfb7508108cddc7dfede2385e30a0561dbd007b784ed2639962c28552eb0e9336412faa323637fe964c26b8d8fc6dcf9fc63734ac00d05736
2 parents 0492b56 + 0175977 commit 7740ebc

File tree

3 files changed

+68
-37
lines changed

3 files changed

+68
-37
lines changed

doc/i2p.md

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@ started with I2P terminology.
1010
## Run Bitcoin Core with an I2P router (proxy)
1111

1212
A running I2P router (proxy) with [SAM](https://geti2p.net/en/docs/api/samv3)
13-
enabled is required (there is an [official one](https://geti2p.net) and
14-
[a few alternatives](https://en.wikipedia.org/wiki/I2P#Routers)). Notice the IP
15-
address and port the SAM proxy is listening to; usually, it is
16-
`127.0.0.1:7656`. Once it is up and running with SAM enabled, use the following
17-
Bitcoin Core options:
13+
enabled is required. Options include:
14+
15+
- [i2prouter (I2P Router)](https://geti2p.net), the official implementation in
16+
Java
17+
- [i2pd (I2P Daemon)](https://github.com/PurpleI2P/i2pd)
18+
([documentation](https://i2pd.readthedocs.io/en/latest)), a lighter
19+
alternative in C++ (successfully tested with version 2.23 and up; version 2.36
20+
or later recommended)
21+
- [i2p-zero](https://github.com/i2p-zero/i2p-zero)
22+
- [other alternatives](https://en.wikipedia.org/wiki/I2P#Routers)
23+
24+
Note the IP address and port the SAM proxy is listening to; usually, it is
25+
`127.0.0.1:7656`.
26+
27+
Once an I2P router with SAM enabled is up and running, use the following Bitcoin
28+
Core configuration options:
1829

1930
```
2031
-i2psam=<ip:port>
@@ -42,15 +53,30 @@ named `i2p_private_key` in the Bitcoin Core data directory.
4253

4354
## Additional configuration options related to I2P
4455

45-
You may set the `debug=i2p` config logging option to have additional
46-
information in the debug log about your I2P configuration and connections. Run
47-
`bitcoin-cli help logging` for more information.
56+
```
57+
-debug=i2p
58+
```
59+
60+
Set the `debug=i2p` config logging option to see additional information in the
61+
debug log about your I2P configuration and connections. Run `bitcoin-cli help
62+
logging` for more information.
63+
64+
```
65+
-onlynet=i2p
66+
```
67+
68+
Make outgoing connections only to I2P addresses. Incoming connections are not
69+
affected by this option. It can be specified multiple times to allow multiple
70+
network types, e.g. onlynet=ipv4, onlynet=ipv6, onlynet=onion, onlynet=i2p.
71+
72+
Warning: if you use -onlynet with values other than onion, and the -onion or
73+
-proxy option is set, then outgoing onion connections will still be made; use
74+
-noonion or -onion=0 to disable outbound onion connections in this case.
4875

49-
It is possible to restrict outgoing connections in the usual way with
50-
`onlynet=i2p`. I2P support was added to Bitcoin Core in version 22.0 (mid-2021)
51-
and there may be fewer I2P peers than Tor or IP ones. Therefore, using
52-
`onlynet=i2p` alone (without other `onlynet=`) may make a node more susceptible
53-
to [Sybil attacks](https://en.bitcoin.it/wiki/Weaknesses#Sybil_attack). Use
76+
I2P support was added to Bitcoin Core in version 22.0 and there may be fewer I2P
77+
peers than Tor or IP ones. Therefore, using I2P alone without other networks may
78+
make a node more susceptible to [Sybil
79+
attacks](https://en.bitcoin.it/wiki/Weaknesses#Sybil_attack). You can use
5480
`bitcoin-cli -addrinfo` to see the number of I2P addresses known to your node.
5581

5682
Another consideration with `onlynet=i2p` is that the initial blocks download

doc/tor.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ outgoing connections, but more is possible.
5757
-onlynet=onion Make outgoing connections only to .onion addresses. Incoming
5858
connections are not affected by this option. This option can be
5959
specified multiple times to allow multiple network types, e.g.
60-
ipv4, ipv6 or onion. If you use this option with values other
61-
than onion you *cannot* disable onion connections; outgoing onion
62-
connections will be enabled when you use -proxy or -onion. Use
63-
-noonion or -onion=0 if you want to be sure there are no outbound
64-
onion connections over the default proxy or your defined -proxy.
60+
onlynet=ipv4, onlynet=ipv6, onlynet=onion, onlynet=i2p.
61+
Warning: if you use -onlynet with values other than onion, and
62+
the -onion or -proxy option is set, then outgoing onion
63+
connections will still be made; use -noonion or -onion=0 to
64+
disable outbound onion connections in this case.
6565

6666
In a typical situation, this suffices to run behind a Tor proxy:
6767

src/test/net_tests.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -627,37 +627,42 @@ BOOST_AUTO_TEST_CASE(ipv4_peer_with_ipv6_addrMe_test)
627627

628628
BOOST_AUTO_TEST_CASE(LimitedAndReachable_Network)
629629
{
630-
BOOST_CHECK_EQUAL(IsReachable(NET_IPV4), true);
631-
BOOST_CHECK_EQUAL(IsReachable(NET_IPV6), true);
632-
BOOST_CHECK_EQUAL(IsReachable(NET_ONION), true);
630+
BOOST_CHECK(IsReachable(NET_IPV4));
631+
BOOST_CHECK(IsReachable(NET_IPV6));
632+
BOOST_CHECK(IsReachable(NET_ONION));
633+
BOOST_CHECK(IsReachable(NET_I2P));
633634

634635
SetReachable(NET_IPV4, false);
635636
SetReachable(NET_IPV6, false);
636637
SetReachable(NET_ONION, false);
638+
SetReachable(NET_I2P, false);
637639

638-
BOOST_CHECK_EQUAL(IsReachable(NET_IPV4), false);
639-
BOOST_CHECK_EQUAL(IsReachable(NET_IPV6), false);
640-
BOOST_CHECK_EQUAL(IsReachable(NET_ONION), false);
640+
BOOST_CHECK(!IsReachable(NET_IPV4));
641+
BOOST_CHECK(!IsReachable(NET_IPV6));
642+
BOOST_CHECK(!IsReachable(NET_ONION));
643+
BOOST_CHECK(!IsReachable(NET_I2P));
641644

642645
SetReachable(NET_IPV4, true);
643646
SetReachable(NET_IPV6, true);
644647
SetReachable(NET_ONION, true);
648+
SetReachable(NET_I2P, true);
645649

646-
BOOST_CHECK_EQUAL(IsReachable(NET_IPV4), true);
647-
BOOST_CHECK_EQUAL(IsReachable(NET_IPV6), true);
648-
BOOST_CHECK_EQUAL(IsReachable(NET_ONION), true);
650+
BOOST_CHECK(IsReachable(NET_IPV4));
651+
BOOST_CHECK(IsReachable(NET_IPV6));
652+
BOOST_CHECK(IsReachable(NET_ONION));
653+
BOOST_CHECK(IsReachable(NET_I2P));
649654
}
650655

651656
BOOST_AUTO_TEST_CASE(LimitedAndReachable_NetworkCaseUnroutableAndInternal)
652657
{
653-
BOOST_CHECK_EQUAL(IsReachable(NET_UNROUTABLE), true);
654-
BOOST_CHECK_EQUAL(IsReachable(NET_INTERNAL), true);
658+
BOOST_CHECK(IsReachable(NET_UNROUTABLE));
659+
BOOST_CHECK(IsReachable(NET_INTERNAL));
655660

656661
SetReachable(NET_UNROUTABLE, false);
657662
SetReachable(NET_INTERNAL, false);
658663

659-
BOOST_CHECK_EQUAL(IsReachable(NET_UNROUTABLE), true); // Ignored for both networks
660-
BOOST_CHECK_EQUAL(IsReachable(NET_INTERNAL), true);
664+
BOOST_CHECK(IsReachable(NET_UNROUTABLE)); // Ignored for both networks
665+
BOOST_CHECK(IsReachable(NET_INTERNAL));
661666
}
662667

663668
CNetAddr UtilBuildAddress(unsigned char p1, unsigned char p2, unsigned char p3, unsigned char p4)
@@ -676,10 +681,10 @@ BOOST_AUTO_TEST_CASE(LimitedAndReachable_CNetAddr)
676681
CNetAddr addr = UtilBuildAddress(0x001, 0x001, 0x001, 0x001); // 1.1.1.1
677682

678683
SetReachable(NET_IPV4, true);
679-
BOOST_CHECK_EQUAL(IsReachable(addr), true);
684+
BOOST_CHECK(IsReachable(addr));
680685

681686
SetReachable(NET_IPV4, false);
682-
BOOST_CHECK_EQUAL(IsReachable(addr), false);
687+
BOOST_CHECK(!IsReachable(addr));
683688

684689
SetReachable(NET_IPV4, true); // have to reset this, because this is stateful.
685690
}
@@ -691,12 +696,12 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
691696

692697
SetReachable(NET_IPV4, true);
693698

694-
BOOST_CHECK_EQUAL(IsLocal(addr), false);
695-
BOOST_CHECK_EQUAL(AddLocal(addr, 1000), true);
696-
BOOST_CHECK_EQUAL(IsLocal(addr), true);
699+
BOOST_CHECK(!IsLocal(addr));
700+
BOOST_CHECK(AddLocal(addr, 1000));
701+
BOOST_CHECK(IsLocal(addr));
697702

698703
RemoveLocal(addr);
699-
BOOST_CHECK_EQUAL(IsLocal(addr), false);
704+
BOOST_CHECK(!IsLocal(addr));
700705
}
701706

702707
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)