Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] P2P: initial I2P support #2932

Closed
wants to merge 54 commits into from
Closed

Conversation

chisa0a
Copy link

@chisa0a chisa0a commented Jun 29, 2019

Adds initial support for I2P P2P connections. Includes @ignopeverell's initial work supporting I2P, finishes a large amount of the remaining work for E2E I2P connections, and rebases onto the milestone/2.x.x branch.

Supports connecting to an I2P seeding peer via the List seeding option in the config. Other config peer lists (peers_allow, peers_deny) also support I2P peers. Further testing is needed to see how other peer lists handle I2P peers.

Due to the size of this PR, will split remaining work into separate PRs building on top of this one.

Remaining work:

  • seeding I2P peers (currently I2P seeder only seeds TCP peers)
  • connecting exclusively through I2P
  • wallet I2P connections
  • miner I2P connections
  • creating bootstrap list of I2P seeders
  • reporting connected I2P peers in TUI
  • (maybe) installing i2pd automatically (if not found locally)

Changes have been tested on Mainnet and Floonet, with successful I2P connections on both. Currently, I2P peer connections have to be manually verified through i2pd user interface.

Seeding peer was able to sync exclusively from I2P seeder, get a TCP peer list from I2P seeder, and sync from TCP peers.

I've added a wiki entry for initial setup to aid with testing, and as WIP documentation for connecting Grin nodes over I2P (thanks for the suggestion @Kargakis).

Includes unit tests for de/serializing I2P peers from/to the config. Tests for creating I2P streams require a running I2P node that supports SAM connections.

ignopeverell and others added 20 commits June 27, 2019 22:25
Adds necessary configuration bits to enable I2P in various modes,
unused for now but will soon. Also add peer address wrappers for
I2P so those addresses can be understood and exchanged between
peers. Doesn't compile yet as serde needs to be supported in
i2p-rs first.
Convert use of panic! to return result + error.

Adds PeerAddrType enum for converting address type to/from raw u8.
Adds I2P to fullnode capabilities, modifies tests accordingly.

Other rustfmt changes.
Shutdown I2P streams gracefully on stop_state.
Includes `i2p_mode` and I2P peer examples in the default config file.
Adds implementation to start i2pd automatically when I2P support enabled.
Fixes references for non-`Copy` `PeerAddr`, other minor fixups for
return types, and removing unneeded functions.
@chisa0a
Copy link
Author

chisa0a commented Jun 29, 2019

macosx test failed, but looks unrelated to the changes in this PR:

thread 'hard_forks' panicked at 'assertion failed: valid_header_version(YEAR_HEIGHT / 2 - 1, HeaderVersion::new(1))', core/tests/consensus.rs:628:3
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:208
   4: <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
             at src/libstd/panicking.rs:474
   5: alloc::alloc::dealloc
             at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libstd/panicking.rs:408
   6: consensus::hard_forks
             at core/tests/consensus.rs:628
   7: consensus::hard_forks::{{closure}}
             at core/tests/consensus.rs:620
   8: core::ops::function::FnOnce::call_once
             at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/ops/function.rs:231
   9: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/liballoc/boxed.rs:702
  10: panic_unwind::dwarf::eh::read_encoded_pointer
             at src/libpanic_unwind/lib.rs:87
  11: test::run_test::run_test_inner::{{closure}}
             at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libstd/panicking.rs:272
             at /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libstd/panic.rs:388
             at src/libtest/lib.rs:1468

Copy link
Contributor

@hashmap hashmap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great works, some minor comments

p2p/Cargo.toml Outdated Show resolved Hide resolved
p2p/src/handshake.rs Outdated Show resolved Hide resolved
p2p/src/peers.rs Outdated Show resolved Hide resolved
p2p/src/peers.rs Outdated Show resolved Hide resolved
p2p/src/peers.rs Outdated Show resolved Hide resolved
servers/src/grin/seed.rs Outdated Show resolved Hide resolved
servers/src/grin/seed.rs Outdated Show resolved Hide resolved
servers/src/grin/seed.rs Show resolved Hide resolved
servers/src/grin/seed.rs Outdated Show resolved Hide resolved
servers/src/grin/server.rs Show resolved Hide resolved
@hashmap
Copy link
Contributor

hashmap commented Jul 5, 2019

@chisa0a if you don't mind I can remove extra clone calls

@chisa0a
Copy link
Author

chisa0a commented Jul 5, 2019

@chisa0a if you don't mind I can remove extra clone calls

Sounds good to me. I can also take care of them when working on the other refactors, either way.

Many thanks for the review!

#mode = \"Enabled\"

#[server.p2p_config.i2p_mode.i2p_config]
#autostart = true/false - start I2P automatically
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More admin-friendly config:

# Start I2P automatically
# autostart = true
# Exclusively connect through I2P, or also use TCP/IP
# exclusive = true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this before the most recent push of updates. Can add with next round of changes.

hashmap added 2 commits July 10, 2019 23:37
We are interested only in behaviour of Stream, so it sounds right to
model it as a trait. It allows also reuse implementation of existing
traits (Read, Write) as is without wrapping. It simplifies client code
because it can work directly with TcpStream and I2pStream.

At the same time it brings some complexity - one more type parameter for
some functions and some boilerplate code to implement trait for
references.
ignopeverell and others added 21 commits August 9, 2019 05:06
Convert use of panic! to return result + error.

Adds PeerAddrType enum for converting address type to/from raw u8.
Adds I2P to fullnode capabilities, modifies tests accordingly.

Other rustfmt changes.
Shutdown I2P streams gracefully on stop_state.
Includes `i2p_mode` and I2P peer examples in the default config file.
Adds implementation to start i2pd automatically when I2P support enabled.
Fixes references for non-`Copy` `PeerAddr`, other minor fixups for
return types, and removing unneeded functions.
We are interested only in behaviour of Stream, so it sounds right to
model it as a trait. It allows also reuse implementation of existing
traits (Read, Write) as is without wrapping. It simplifies client code
because it can work directly with TcpStream and I2pStream.

At the same time it brings some complexity - one more type parameter for
some functions and some boilerplate code to implement trait for
references.
Adds `set_read_timeout` and `set_write_timeout` handlers to the
Stream trait.

Requires updates in i2p-rs for calling the functions on I2pStream.
Adds I2P thread handle to deal with any potential errors when
joining on shutdown.
Various small fixups for rebase onto master at commit ea1d14d.
Changes the i2p-rs crate to the fork hosted on the mimblewimble org repo.
}
}

fn start_i2pd() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see us stopping i2pd. Is that intentional?

@quentinlesceller
Copy link
Member

Closing due to lack of activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants