Skip to content

Commit

Permalink
Merge pull request #130: Transit improvements
Browse files Browse the repository at this point in the history
Fancy things! And code cleanup.

- We now do firewall hole punching. If your device got a firewall connected (and it really should, and by default), direct transfers should now work for you too.
- If you aren't behind any NATs (IPv6 users rejoice), **direct connections should now work across the internet** 🎉
- NAT traversal using STUN, for our poor IPv4 users. Gives you direct connections as well, provided that the NAT behaves well (fortunately, they mostly do).
- If we found a connection over a relay, we wait some longer in the hope of a direct connection.

See also magic-wormhole/magic-wormhole-protocols#16 for some more words on what this code does in a bit more detail.
  • Loading branch information
piegamesde committed Oct 10, 2021
2 parents a5c60c7 + 3e3dd4e commit 53a90d7
Show file tree
Hide file tree
Showing 6 changed files with 1,073 additions and 585 deletions.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ futures_ringbuf = "0.3.1"
tar = "0.4.33"
chrono = "0.4.19"

derive_more = { version = "0.99.0", default-features = false, features = ["display", "deref"] }
derive_more = { version = "0.99.0", default-features = false, features = ["display", "deref", "from"] }
thiserror = "1.0.24"

futures = "0.3.12"
async-std = { version = "1.9.0", features = ["attributes", "unstable"] }
async-tungstenite = { version = "0.14.0", features = ["async-std-runtime", "async-tls"] }
async-io = "1.6.0"
socket2 = "0.4.1"
libc = "0.2.101"
stun_codec = "0.1.13"
bytecodec = "0.4.15"

# for "bin" feature
clap = { version = "2.33.3", optional = true }
Expand Down
9 changes: 7 additions & 2 deletions src/core/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl Key<WormholeKey> {
let derived_key = self.derive_subkey_from_purpose(&transit_purpose);
trace!(
"Input key: {}, Transit key: {}, Transit purpose: '{}'",
hex::encode(&**self),
hex::encode(&**derived_key),
self.to_hex(),
derived_key.to_hex(),
&transit_purpose
);
derived_key
Expand All @@ -65,6 +65,11 @@ impl<P: KeyPurpose> Key<P> {
pub fn new(key: Box<secretbox::Key>) -> Self {
Self(key, std::marker::PhantomData)
}

pub fn to_hex(&self) -> String {
hex::encode(&**self)
}

/**
* Derive a new sub-key from this one
*/
Expand Down
12 changes: 2 additions & 10 deletions src/core/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ pub async fn test_file_rust2rust() -> eyre::Result<()> {
std::fs::metadata("examples/example-file.bin")
.unwrap()
.len(),
|sent, total| {
log::info!("Sent {} of {} bytes", sent, total);
},
|_sent, _total| {},
)
.await?,
)
Expand All @@ -72,13 +70,7 @@ pub async fn test_file_rust2rust() -> eyre::Result<()> {
.await?;

let mut buffer = Vec::<u8>::new();
req.accept(
|received, total| {
log::info!("Received {} of {} bytes", received, total);
},
&mut buffer,
)
.await?;
req.accept(|_received, _total| {}, &mut buffer).await?;
Ok(buffer)
})?;

Expand Down

0 comments on commit 53a90d7

Please sign in to comment.