-
Notifications
You must be signed in to change notification settings - Fork 965
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
feat(quic): implement hole punching #3964
Merged
Merged
Changes from 36 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
7a714bf
Implement Transport::dial_as_listener for QUIC
arpankapoor 145bf11
Merge QUIC dcutr and relay examples
arpankapoor 0eafaf4
Simplify nested if let
arpankapoor fd70f73
Return error when dial_as_listener is called without an active listener
arpankapoor ddacaa0
Extract peer_id in multiaddr_to_socketaddr
arpankapoor 3325dbe
Add peerid to holepunching key
arpankapoor 271f234
Update dcutr example
arpankapoor 8b9d778
Check if holepunching is already in progress
arpankapoor 2290811
Dedup dial and dial_as_listener
arpankapoor 2621c13
Store random packet on failure
arpankapoor 3b17e38
Use `Display` formatting instead of `Debug`
arpankapoor 45446bb
Use slice pattern
arpankapoor 8a344c7
Resolve merge conflict
arpankapoor 81988c2
Resolve merge conflict
arpankapoor a831f51
Merge branch 'master' into master
arpankapoor 28ece03
Use futures::future::select instead of select! macro
arpankapoor ce86b7c
Merge branch 'master' into master
arpankapoor 794cabc
Implement HolePuncher as an async function
arpankapoor e501175
Remove entry from HolePunchMap on timeout
arpankapoor ad2b644
Run rustfmt
arpankapoor ba60bba
Implement MaybeHolePunchedConnection as an async function
arpankapoor 6c378ef
Use `SendExt::send` instead of `poll_ready` and `start_send`
arpankapoor 3490940
Swap position of hole_puncher and punch_holes
arpankapoor 26cd328
Clean up maybe_hole_punched_connection
arpankapoor 0b1eaa5
Rename hole_punch_map to hole_punch_attempts
arpankapoor fbbd1a1
Create newtype HolePunchMap
arpankapoor 2ad9255
Don't mix private/public imports
arpankapoor bbbf7a1
Return single eligible listener
arpankapoor 26da28d
Return different error on successful holepunch
arpankapoor 8eda5a7
Update external address
arpankapoor 6c2638a
Merge branch 'master' of https://github.com/libp2p/rust-libp2p
arpankapoor 5f58955
Resolve issue after merge
arpankapoor 928314f
Remove peer_id from hole punching key
arpankapoor 6e1b02d
Merge branch 'master' of https://github.com/libp2p/rust-libp2p
arpankapoor 4f4f528
Remove redudant match arm from relay example
arpankapoor 3f6bb59
Update CHANGELOG
arpankapoor 02b1268
Fix imports
arpankapoor 35de850
Review fixes
arpankapoor e46c170
More review fixes
arpankapoor 36655ee
Move timeout and sleep to Provider trait
arpankapoor 49873f0
Implement timeout using sleep
arpankapoor 0eb9246
Loop through listener events
arpankapoor 05b7a9f
Remove unused TimeoutError
arpankapoor 9d001c7
Merge branch 'master' into master
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::{net::SocketAddr, time::Duration}; | ||
|
||
use rand::{distributions, Rng}; | ||
|
||
#[cfg(feature = "async-std")] | ||
use async_std::{future::timeout, task::sleep}; | ||
#[cfg(feature = "tokio")] | ||
use tokio::time::{sleep, timeout}; | ||
thomaseizinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use crate::{ | ||
endpoint::{self, ToEndpoint}, | ||
Error, | ||
}; | ||
|
||
pub(crate) async fn hole_puncher( | ||
endpoint_channel: endpoint::Channel, | ||
remote_addr: SocketAddr, | ||
timeout_duration: Duration, | ||
) -> Error { | ||
timeout(timeout_duration, punch_holes(endpoint_channel, remote_addr)) | ||
.await | ||
.unwrap_or(Error::HandshakeTimedOut) | ||
} | ||
|
||
async fn punch_holes(mut endpoint_channel: endpoint::Channel, remote_addr: SocketAddr) -> Error { | ||
loop { | ||
let sleep_duration = Duration::from_millis(rand::thread_rng().gen_range(10..=200)); | ||
sleep(sleep_duration).await; | ||
|
||
let random_udp_packet = ToEndpoint::SendUdpPacket(quinn_proto::Transmit { | ||
destination: remote_addr, | ||
ecn: None, | ||
contents: rand::thread_rng() | ||
.sample_iter(distributions::Standard) | ||
.take(64) | ||
.collect(), | ||
segment_size: None, | ||
src_ip: None, | ||
}); | ||
|
||
if endpoint_channel.send(random_udp_packet).await.is_err() { | ||
return Error::EndpointDriverCrashed; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which means that there is no way to perform hole punching in the example because
eligible_listener
checksis_loopback
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used the example for testing this in two real networks. If you run this example on localhost, you are not really testing hole punching but just that the protocol is executed. On localhost, the connection should always succeed because there is no need for the random UDP packets to punch a hole. Am I wrong?