Skip to content

Commit

Permalink
Refactor transit hints again
Browse files Browse the repository at this point in the history
According to the newest spec proposal in magic-wormhole/magic-wormhole-protocols#16.
  • Loading branch information
piegamesde committed Feb 4, 2022
1 parent 0759d36 commit a4231d4
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 152 deletions.
4 changes: 2 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ async fn main() -> eyre::Result<()> {
loop {
let (wormhole, _code, relay_server) =
parse_and_connect(&mut term, matches, true, forwarding::APP_CONFIG).await?;
let relay_server = vec![transit::RelayHint::from_url(relay_server)];
let relay_server = vec![transit::RelayHint::from_urls(None, [relay_server])];
async_std::task::spawn(forwarding::serve(wormhole, relay_server, targets.clone()));
}
} else if let Some(matches) = matches.subcommand_matches("connect") {
Expand All @@ -380,7 +380,7 @@ async fn main() -> eyre::Result<()> {
let bind_address: std::net::IpAddr = matches.value_of("bind").unwrap().parse()?;
let (wormhole, _code, relay_server) =
parse_and_connect(&mut term, matches, false, forwarding::APP_CONFIG).await?;
let relay_server = vec![transit::RelayHint::from_url(relay_server)];
let relay_server = vec![transit::RelayHint::from_urls(None, [relay_server])];

forwarding::connect(wormhole, relay_server, Some(bind_address), &custom_ports).await?;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ where
H: FnMut(u64, u64) + 'static,
{
let _peer_version: AppVersion = serde_json::from_value(wormhole.peer_version.clone())?;
let relay_hints = vec![transit::RelayHint::from_url(relay_url)];
let relay_hints = vec![transit::RelayHint::from_urls(None, [relay_url])];
// if peer_version.supports_v2() && false {
// v2::send_file(wormhole, relay_url, file, file_name, file_size, progress_handler, peer_version).await
// } else {
Expand Down Expand Up @@ -288,7 +288,7 @@ where
M: Into<PathBuf>,
H: FnMut(u64, u64) + 'static,
{
let relay_hints = vec![transit::RelayHint::from_url(relay_url)];
let relay_hints = vec![transit::RelayHint::from_urls(None, [relay_url])];
v1::send_folder(
wormhole,
relay_hints,
Expand All @@ -309,7 +309,7 @@ pub async fn request_file(
mut wormhole: Wormhole,
relay_url: url::Url,
) -> Result<ReceiveRequest, TransferError> {
let relay_hints = vec![transit::RelayHint::from_url(relay_url)];
let relay_hints = vec![transit::RelayHint::from_urls(None, [relay_url])];
let connector = transit::init(transit::Abilities::ALL_ABILITIES, None, relay_hints).await?;

// send the transit message
Expand Down
35 changes: 28 additions & 7 deletions src/transfer/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,36 @@ mod test {
let abilities = Abilities::ALL_ABILITIES;
let hints = transit::Hints::new(
[DirectHint::new("192.168.1.8", 46295)],
[RelayHint::from_url(
"tcp://magic-wormhole-transit.debian.net:4001"
.parse()
.unwrap(),
[RelayHint::new(
None,
[DirectHint::new("magic-wormhole-transit.debian.net", 4001)],
[],
)],
);
let t =
serde_json::json!(crate::transfer::PeerMessage::transit(abilities, hints)).to_string();
assert_eq!(t, "{\"transit\":{\"abilities-v1\":[{\"type\":\"direct-tcp-v1\"},{\"type\":\"relay-v1\",\"url-hints\":true}],\"hints-v1\":[{\"hostname\":\"192.168.1.8\",\"port\":46295,\"type\":\"direct-tcp-v1\"},{\"hints\":[{\"hostname\":\"magic-wormhole-transit.debian.net\",\"port\":4001}],\"type\":\"relay-v1\",\"urls\":[\"tcp://magic-wormhole-transit.debian.net:4001\"]}]}}")
assert_eq!(
serde_json::json!(crate::transfer::PeerMessage::transit(abilities, hints)),
serde_json::json!({
"transit": {
"abilities-v1": [{"type":"direct-tcp-v1"},{"type":"relay-v1"},{"type":"relay-v2"}],
"hints-v1": [
{"hostname":"192.168.1.8","port":46295,"type":"direct-tcp-v1"},
{
"type": "relay-v1",
"hints": [
{"hostname": "magic-wormhole-transit.debian.net", "port": 4001 }
]
},
{
"type": "relay-v2",
"hints": [
{"type": "tcp", "hostname": "magic-wormhole-transit.debian.net", "port": 4001}
],
"name": null
}
],
}
})
);
}

#[test]
Expand Down
Loading

0 comments on commit a4231d4

Please sign in to comment.