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

transfer: Feature-gate transfer-v2 #239

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose --all
args: --verbose --workspace --features=all,native-tls,experimental

dist:
runs-on: ${{ matrix.os }}
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ all = ["default", "forwarding"]
# required for optional wss connection to the mailbox server
tls = ["async-tungstenite/async-tls"]
native-tls = ["async-tungstenite/async-native-tls"]
# Enable experimental transfer-v2 support. The protocol is not yet finalized and is subject to change.
experimental-transfer-v2 = []
experimental = ["experimental-transfer-v2"]

[profile.release]
overflow-checks = true
Expand Down
14 changes: 10 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

## Unreleased

- Added compilation support for WASM targets.
- By default websocket TLS support is now disabled in the library crate. TLS is required for secure websocket connections to the mailbox server (`wss://`). As the handshake protocol itself is encrypted, this extra layer of encryption is superfluous. Most WASM targets however refuse to connect to non-TLS websockets. For maximum compatibility with all mailbox servers, or for web browser support, select a TLS implementation by specifying the feature flag `tls` for a statically linked implementation via the `ring` crate, or `native-tls` for dynamically linking with the system-native TLS implementation.
- The CLI includes `native-tls` in the `all` feature preset.
- \[lib\]\[breaking\] replaced `transit::TransitInfo` with a struct containing the address, the old enum has been renamed to `transit::ConnectionType`.
- \[all\]\[breaking\] By default websocket TLS support is now disabled in the library crate. TLS is required for secure websocket connections to the mailbox server (`wss://`). As the handshake protocol itself is encrypted, this extra layer of encryption is superfluous. Most WASM targets however refuse to connect to non-TLS websockets. For maximum compatibility with all mailbox servers, or for web browser support, select a TLS implementation by specifying the feature flag `tls` for a statically linked implementation via the `ring` crate, or `native-tls` for dynamically linking with the system-native TLS implementation.
- \[all\] For experimental (unstable) `transfer-v2` protocol support, enable feature flag `experimental-transfer-v2`. The protocol is not yet finalized.
- \[all\] Added compilation support for WASM targets.
- \[lib\]\[breaking\] replaced `transit::TransitInfo` with a struct containing the address and a `conn_type` field which contains the old enum as `transit::ConnectionType`
- \[lib\]\[breaking\] replaced `transfer::AppVersion` with a struct with private fields that implements `std::default::Default`
- \[lib\]\[breaking\] split `Wormhole` in `MailboxConnection` and `Wormhole`. `Wormhole` now uses accessor methods for the previously exposed fields.
- \[lib\]\[breaking\] `WormholeWelcome` now uses accessor methods for the previously exposed fields.
- \[lib\]\[breaking\] refactor `magic_wormhole::transfer::` methods to take an `OfferSend` and `OfferReceive` instead of using separate methods for files and folders. Use `transfer::send()` and `transfer::receive()`.
- \[lib\]\[breaking\] struct `transfer::ReceiveRequest` became an enum to prepare for transfer v2
- \[lib\]\[breaking\] removed `transit::log_transit_connection` and implemented `Display` on `TransitInfo` instead.

## Version 0.6.1

Expand Down
3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ trycmd = "0.15"
# required for optional wss connection to the mailbox server
tls = ["magic-wormhole/tls"]
native-tls = ["magic-wormhole/native-tls"]
# Enable experimental transfer-v2 support. The protocol is not yet finalized and is subject to change.
experimental-transfer-v2 = ["magic-wormhole/experimental-transfer-v2"]
experimental = ["experimental-transfer-v2"]

default = ["magic-wormhole/default", "magic-wormhole/forwarding"]
all = ["default", "magic-wormhole/native-tls"]
35 changes: 20 additions & 15 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ use futures::{future::Either, Future, FutureExt};
use indicatif::{MultiProgress, ProgressBar};
use std::{io::Write, path::PathBuf};

use magic_wormhole::{forwarding, transfer, transit, MailboxConnection, Wormhole};
use magic_wormhole::{
forwarding, transfer,
transit::{self, TransitInfo},
MailboxConnection, Wormhole,
};

fn install_ctrlc_handler(
) -> eyre::Result<impl Fn() -> futures::future::BoxFuture<'static, ()> + Clone> {
Expand Down Expand Up @@ -461,7 +465,7 @@ async fn main() -> eyre::Result<()> {
};
async_std::task::spawn(forwarding::serve(
wormhole,
&transit::log_transit_connection,
&transit_handler,
relay_hints,
targets.clone(),
ctrl_c(),
Expand Down Expand Up @@ -494,7 +498,7 @@ async fn main() -> eyre::Result<()> {

let offer = forwarding::connect(
wormhole,
&transit::log_transit_connection,
&transit_handler,
relay_hints,
Some(bind_address),
&ports,
Expand Down Expand Up @@ -800,7 +804,7 @@ async fn send(
relay_hints,
transit_abilities,
offer,
&transit::log_transit_connection,
&transit_handler,
create_progress_handler(pb),
ctrl_c(),
)
Expand Down Expand Up @@ -893,7 +897,7 @@ async fn send_many(
relay_hints,
transit_abilities,
offer,
&transit::log_transit_connection,
&transit_handler,
create_progress_handler(pb2),
cancel,
)
Expand Down Expand Up @@ -933,6 +937,7 @@ async fn receive(
Some(transfer::ReceiveRequest::V1(req)) => {
receive_inner_v1(req, target_dir, noconfirm, ctrl_c).await
},
#[cfg(feature = "experimental-transfer-v2")]
Some(transfer::ReceiveRequest::V2(req)) => {
receive_inner_v2(req, target_dir, noconfirm, ctrl_c).await
},
Expand Down Expand Up @@ -990,7 +995,7 @@ async fn receive_inner_v1(
.context("Failed to create destination file")?;
return req
.accept(
&transit::log_transit_connection,
&transit_handler,
&mut file,
create_progress_handler(pb),
ctrl_c(),
Expand All @@ -1016,7 +1021,7 @@ async fn receive_inner_v1(
.open(&file_path)
.await?;
req.accept(
&transit::log_transit_connection,
&transit_handler,
&mut file,
create_progress_handler(pb),
ctrl_c(),
Expand All @@ -1025,6 +1030,7 @@ async fn receive_inner_v1(
.context("Receive process failed")
}

#[cfg(feature = "experimental-transfer-v2")]
async fn receive_inner_v2(
req: transfer::ReceiveRequestV2,
target_dir: &std::path::Path,
Expand Down Expand Up @@ -1075,14 +1081,9 @@ async fn receive_inner_v2(

/* Accept the offer and receive it */
let answer = offer.accept_all(&tmp_dir);
req.accept(
&transit::log_transit_connection,
answer,
on_progress,
ctrl_c(),
)
.await
.context("Receive process failed")?;
req.accept(&transit_handler, answer, on_progress, ctrl_c())
.await
.context("Receive process failed")?;

// /* Put in all the symlinks last, this greatly reduces the attack surface */
// offer.create_symlinks(&tmp_dir).await?;
Expand Down Expand Up @@ -1127,6 +1128,10 @@ async fn receive_inner_v2(
Ok(())
}

fn transit_handler(info: TransitInfo) {
log::info!("{info}");
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
39 changes: 32 additions & 7 deletions src/core/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(irrefutable_let_patterns)]

use super::{Mood, Phase};
use rand::Rng;
use std::{borrow::Cow, time::Duration};
Expand Down Expand Up @@ -33,6 +35,29 @@ fn init_logger() {
.try_init();
}

/// Utility method that logs information of the transit result
///
/// Example usage:
///
/// ```no_run
/// use magic_wormhole as mw;
/// # #[async_std::main] async fn main() -> Result<(), mw::transit::TransitConnectError> {
/// # let derived_key = unimplemented!();
/// # let their_abilities = unimplemented!();
/// # let their_hints = unimplemented!();
/// let connector: mw::transit::TransitConnector = unimplemented!("transit::init(…).await?");
/// let (mut transit, info) = connector
/// .leader_connect(derived_key, their_abilities, their_hints)
/// .await?;
/// mw::log_transit_connection(info);
/// # Ok(())
/// # }
/// ```
#[cfg(not(target_family = "wasm"))]
pub(crate) fn log_transit_connection(info: crate::transit::TransitInfo) {
log::info!("{info}")
}

fn default_relay_hints() -> Vec<transit::RelayHint> {
vec![
transit::RelayHint::from_urls(None, [transit::DEFAULT_RELAY_SERVER.parse().unwrap()])
Expand Down Expand Up @@ -197,7 +222,7 @@ pub async fn test_file_rust2rust_deprecated() -> eyre::Result<()> {
default_relay_hints(),
magic_wormhole::transit::Abilities::ALL_ABILITIES,
offer,
&transit::log_transit_connection,
&log_transit_connection,
|_sent, _total| {},
futures::future::pending(),
)
Expand Down Expand Up @@ -231,7 +256,7 @@ pub async fn test_file_rust2rust_deprecated() -> eyre::Result<()> {
panic!("v2 should be disabled for now")
};
req.accept(
&transit::log_transit_connection,
&log_transit_connection,
&mut answer,
|_received, _total| {},
futures::future::pending(),
Expand Down Expand Up @@ -273,7 +298,7 @@ pub async fn test_file_rust2rust() -> eyre::Result<()> {
default_relay_hints(),
magic_wormhole::transit::Abilities::ALL_ABILITIES,
offer,
&transit::log_transit_connection,
&log_transit_connection,
|_sent, _total| {},
futures::future::pending(),
)
Expand Down Expand Up @@ -306,7 +331,7 @@ pub async fn test_file_rust2rust() -> eyre::Result<()> {
panic!("v2 should be disabled for now")
};
req.accept(
&transit::log_transit_connection,
&log_transit_connection,
&mut answer,
|_received, _total| {},
futures::future::pending(),
Expand Down Expand Up @@ -357,7 +382,7 @@ pub async fn test_send_many() -> eyre::Result<()> {
default_relay_hints(),
magic_wormhole::transit::Abilities::ALL_ABILITIES,
gen_offer().await?,
&transit::log_transit_connection,
&log_transit_connection,
|_, _| {},
futures::future::pending(),
)
Expand Down Expand Up @@ -385,7 +410,7 @@ pub async fn test_send_many() -> eyre::Result<()> {
default_relay_hints(),
magic_wormhole::transit::Abilities::ALL_ABILITIES,
gen_offer().await?,
&transit::log_transit_connection,
&log_transit_connection,
|_, _| {},
futures::future::pending(),
)
Expand Down Expand Up @@ -429,7 +454,7 @@ pub async fn test_send_many() -> eyre::Result<()> {
.await?;

req.accept(
&transit::log_transit_connection,
&log_transit_connection,
&mut answer,
|_, _| {},
futures::future::pending(),
Expand Down
Loading
Loading