Skip to content

Conversation

@vasild
Copy link
Contributor

@vasild vasild commented May 11, 2021

There are two issues:

1. Our I2P address not added to local addresses.

  • externalip= is used with an IPv4 address (this sets automatically discover=0)
  • No discover=1 is used
  • i2psam= is used
  • No externalip= is used for our I2P address
  • listenonion=1 torcontrol= are used

In this case AddLocal(LOCAL_MANUAL) is used for our .onion address and AddLocal(LOCAL_BIND) for our .b32.i2p address, the latter being ignored due to discover=0.

2. Our I2P address removed from local addresses even if specified with externalip= on I2P proxy restart.

  • externalip= is used with our I2P address (this sets automatically discover=0)
  • No discover=1 is used
  • i2psam= is used

In this case, initially externalip= causes our I2P address to be added with AddLocal(LOCAL_MANUAL) which overrides discover=0 and works as expected. However, if later the I2P proxy is shut down we do RemoveLocal() in order to stop advertising our I2P address (since we have lost I2P connectivity). When the I2P proxy is started and we reconnect to it, restoring the I2P connectivity, we do AddLocal(LOCAL_BIND) which does nothing due to discover=0.

To resolve those two issues, use AddLocal(LOCAL_MANUAL) for I2P which is also what we do with Tor.

There are two issues:

1. Our I2P address not added to local addresses.

* `externalip=` is used with an IPv4 address (this sets automatically
  `discover=0`)
* No `discover=1` is used
* `i2psam=` is used
* No `externalip=` is used for our I2P address
* `listenonion=1 torcontrol=` are used

In this case `AddLocal(LOCAL_MANUAL)` is used for our `.onion` address
and `AddLocal(LOCAL_BIND)` for our `.b32.i2p` address, the latter being
ignored due to `discover=0`.

2. Our I2P address removed from local addresses even if specified
with `externalip=` on I2P proxy restart.

* `externalip=` is used with our I2P address (this sets automatically
  `discover=0`)
* No `discover=1` is used
* `i2psam=` is used

In this case, initially `externalip=` causes our I2P address to be added
with `AddLocal(LOCAL_MANUAL)` which overrides `discover=0` and works as
expected. However, if later the I2P proxy is shut down we do
`RemoveLocal()` in order to stop advertising our I2P address (since we
have lost I2P connectivity). When the I2P proxy is started and we
reconnect to it, restoring the I2P connectivity, we do
`AddLocal(LOCAL_BIND)` which does nothing due to `discover=0`.

To resolve those two issues, use `AddLocal(LOCAL_MANUAL)` for I2P which
is also what we do with Tor.
@vasild
Copy link
Contributor Author

vasild commented May 11, 2021

The first issue was reported by @sdaftuar in #20685 (comment), thanks!

@jonatack
Copy link
Member

Concept ACK, thanks for following up on this.

@laanwj
Copy link
Member

laanwj commented May 13, 2021

It makes sense to do the same for I2P as for Tor.

Code review ACK 105941b

@laanwj laanwj merged commit 4741aec into bitcoin:master May 13, 2021
@vasild vasild deleted the i2p_local branch May 13, 2021 13:47
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 13, 2021
105941b net: use stronger AddLocal() for our I2P address (Vasil Dimov)

Pull request description:

  There are two issues:

  ### 1. Our I2P address not added to local addresses.

  * `externalip=` is used with an IPv4 address (this sets automatically `discover=0`)
  * No `discover=1` is used
  * `i2psam=` is used
  * No `externalip=` is used for our I2P address
  * `listenonion=1 torcontrol=` are used

  In this case `AddLocal(LOCAL_MANUAL)` [is used](https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392eb75e/src/torcontrol.cpp#L354) for our `.onion` address and `AddLocal(LOCAL_BIND)` [for our](https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392eb75e/src/net.cpp#L2247) `.b32.i2p` address, the latter being [ignored](https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392eb75e/src/net.cpp#L232-L233) due to `discover=0`.

  ### 2. Our I2P address removed from local addresses even if specified with `externalip=` on I2P proxy restart.

  * `externalip=` is used with our I2P address (this sets automatically `discover=0`)
  * No `discover=1` is used
  * `i2psam=` is used

  In this case, initially `externalip=` causes our I2P address to be [added](https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392eb75e/src/init.cpp#L1266) with `AddLocal(LOCAL_MANUAL)` which overrides `discover=0` and works as expected. However, if later the I2P proxy is shut down [we do](https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392eb75e/src/net.cpp#L2234) `RemoveLocal()` in order to stop advertising our I2P address (since we have lost I2P connectivity). When the I2P proxy is started and we reconnect to it, restoring the I2P connectivity, [we do](https://github.com/bitcoin/bitcoin/blob/94f83534e4b771944af7d9ed0f40746f392eb75e/src/net.cpp#L2247) `AddLocal(LOCAL_BIND)` which does nothing due to `discover=0`.

  To resolve those two issues, use `AddLocal(LOCAL_MANUAL)` for I2P which is also what we do with Tor.

ACKs for top commit:
  laanwj:
    Code review ACK 105941b

Tree-SHA512: 0c9daf6116b8d9c34ad7e6e9bbff6e8106e94e4394a815d7ae19287aea22a8c7c4e093c8dd8c58a4a1b1412b2575a9b42b8a93672c8d17f11c24508c534506c7
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 15, 2022
…ng connections from CConnman

Summary:
> 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.

bitcoin/bitcoin@9559bd1

> net: make outgoing I2P connections from CConnman

bitcoin/bitcoin@0635233

> net: accept incoming I2P connections from CConnman

https://github.com/bitcoin/bitcoin/pull/20685/commits/b905363fa8b0bb03fe34b53b5410880f42e0af39i

> net: use stronger AddLocal() for our I2P address
bitcoin/bitcoin@105941b

This is a backport of  [[bitcoin/bitcoin#20685 | core#20685]] [16,17,18/20] and [[bitcoin/bitcoin#21914 | core#21914]]

Depends on D11027

Test Plan:
`ninja all check-all`

Run `bitcoind` using I2P (see detailed test plan in D11027).
`ninja && src/bitcoind -regtest -i2psam=127.0.0.1:7656 -debug=i2p`

Now you can see new interesting log messages:

```
2022-02-11T14:35:42Z i2paccept thread start
2022-02-11T14:35:42Z I2P: Creating SAM session with 127.0.0.1:7656
2022-02-11T14:35:45Z I2P: SAM session created: session id=xxxxxxxxxx, my address=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.b32.i2p:18444
2022-02-11T14:35:45Z AddLocal(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.b32.i2p:18444,2)
```

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11029
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants