Add I2P support by using the I2P SAM protocol. Unlike Tor, for incoming connections we get the I2P address of the peer (and they also receive ours when we are the connection initiator).
Two new options are added:
0 -i2psam=<ip:port>
1 I2P SAM proxy to reach I2P peers and accept I2P connections (default:
2 none)
3
4 -i2pacceptincoming
5 If set and -i2psam is also set then incoming I2P connections are
6 accepted via the SAM proxy. If this is not set but -i2psam is set
7 then only outgoing connections will be made to the I2P network.
8 Ignored if -i2psam is not set. Notice that listening for incoming
9 I2P connections is done through the SAM proxy, not by binding to
10 a local address and port (default: true)
Overview of the changes
Make ReadBinary()
and WriteBinary()
reusable
We would need to dump the I2P private key to a file and read it back later. Move those two functions out of torcontrol.cpp
.
0util: extract {Read,Write}BinaryFile() to its own files
1util: fix ReadBinaryFile() returning partial contents
2util: fix WriteBinaryFile() claiming success even if error occurred
Split CConnman::AcceptConnection()
Most of CConnman::AcceptConnection()
is agnostic of how the socket was accepted. The other part of it deals with the details of the accept(2)
system call. Split those so that the protocol-agnostic part can be reused if we accept a socket by other means.
0net: check for invalid socket earlier in CConnman::AcceptConnection()
1net: get the bind address earlier in CConnman::AcceptConnection()
2net: isolate the protocol-agnostic part of CConnman::AcceptConnection()
3net: avoid unnecessary GetBindAddress() call
Implement the I2P SAM protocol (not all of it)
Just the parts that would enable us to make outgoing and accept incoming I2P connections.
0net: extend CNetAddr::SetSpecial() to support I2P
1net: move the constant maxWait out of InterruptibleRecv()
2net: dedup MSG_NOSIGNAL and MSG_DONTWAIT definitions
3net: extend Sock::Wait() to report a timeout
4net: extend Sock with methods for robust send & read until terminator
5net: extend Sock with a method to check whether connected
6net: implement the necessary parts of the I2P SAM protocol
Use I2P SAM to connect to and accept connections from I2P peers
Profit from all of the preceding commits.
0init: introduce I2P connectivity options
1net: add I2P to the reachability map
2net: make outgoing I2P connections from CConnman
3net: accept incoming I2P connections from CConnman
4net: recognize I2P from ParseNetwork() so that -onlynet=i2p works
5net: Do not skip the I2P network from GetNetworkNames()