Skip to content

Commit

Permalink
Implement full-duplex secret connection (#938)
Browse files Browse the repository at this point in the history
* Implement thread-safe cloning of a secret connection

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Expand documentation for SecretConnection on threading considerations

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract peer construction into its own method

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add test for cloned SecretConnection

This adds a `TcpStream`-based test for parallelizing operations on a
`SecretConnection`. I used `TcpStream` instead of the buffered reader in
the other tests because it wasn't feasible to implement the `TryClone`
trait for that buffered pipe implementation.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add more messages to test

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Expand comment for clarity

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add .changelog entry

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Restore half-duplex operations

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract encrypt/decrypt fns as independent methods

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove unnecessary trait bounds

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract send/receive state

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract read/write functionality as standalone methods

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add logic to facilitate splitting SecretConnection into its sending and receiving halves

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Restore split SecretConnection test using new semantics

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update changelog entry

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update docs for `SecretConnection`

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Condense error reporting

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Extract TryClone trait into its own crate

As per the discussion at
#938 (comment),
this extracts the `TryClone` trait into a new crate called
`tendermint-std-ext` in the `std-ext` directory.

This new crate is intended to contain any code that we need that extends
the Rust standard library.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Reorder imports

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Assert validation regardless of debug build

This introduces the internal encryption assertions at runtime regardless
of build type. This may introduce a small performance hit, but it's
probably worth it to ensure correctness.

Effectively this is keeping an eye on the code in the
`encrypt_and_write` fn to ensure its correctness.

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove remote_pubkey optionality from sender/receiver halves

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Update SecretConnection docs with comment content

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix doc link to TryClone trait

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix doc link to TryClone trait

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Add docs on SecretConnection failures and connection integrity

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Synchronize sending/receiving failures to comply with crypto algorithm constraints

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Rename try_split method to split for SecretConnection

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Remove redundant field name prefixes

Signed-off-by: Thane Thomson <connect@thanethomson.com>

* Fix broken link in docs

Signed-off-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
thanethomson committed Aug 4, 2021
1 parent cedf8de commit 09c8454
Show file tree
Hide file tree
Showing 11 changed files with 513 additions and 180 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- `[tendermint-p2p]` The `SecretConnection` can now be split into two halves to
facilitate full-duplex communication (must be facilitated by using each half
in a separate thread).
([#938](https://github.com/informalsystems/tendermint-rs/pull/938))
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"pbt-gen",
"proto",
"rpc",
"std-ext",
"tendermint",
"test",
"testgen"
Expand Down
1 change: 1 addition & 0 deletions p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ zeroize = "1"
# path dependencies
tendermint = { path = "../tendermint", version = "0.21.0" }
tendermint-proto = { path = "../proto", version = "0.21.0" }
tendermint-std-ext = { path = "../std-ext", version = "0.21.0" }

# optional dependencies
prost-amino = { version = "0.6", optional = true }
Expand Down
Loading

0 comments on commit 09c8454

Please sign in to comment.