forked from libp2p/rust-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor UdpMuxNewAddr
to be lock-less
#1
Merged
melekes
merged 24 commits into
melekes:anton/webrtc-transport
from
thomaseizinger:rewrite-udp-mux
Aug 31, 2022
Merged
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9b298e2
Dirty PoC for lock-less UdpMuxNewAddr
thomaseizinger f5483e7
Remove locks from handle
thomaseizinger a137a07
Merge branch 'anton/webrtc-transport' into rewrite-udp-mux
thomaseizinger 8f522bb
Replace `flume` with `futures::mpsc` channels
thomaseizinger 9d9c9a4
Introduce `req_res_chan` module
thomaseizinger 54444b7
Move locking into `req_res_chan::Sender`
thomaseizinger ce44836
Fill in more implementations
thomaseizinger c111c46
Add TODO
thomaseizinger ac14b9f
Implement send command handling, buffering items if we can't send them
thomaseizinger 3c214cb
Remove tokio::spawn for handling waiting for closed sockets
thomaseizinger eb35b18
Remove futures::block_on in favor of local task set
thomaseizinger 744ad62
Fix clippy warnings
thomaseizinger eb976f2
Don't loop inside a loop
thomaseizinger 8a77b6e
Use match instead of `ready!`
thomaseizinger 6d49c5a
Fix webrtc version to rev prior to monorepo merge
thomaseizinger 521da48
Never have more than one write future
thomaseizinger 676d50d
Resolve TODO's for error handling
thomaseizinger 9a32e4f
Make `recv_buf` as short-lived as possible
thomaseizinger 64f8021
Replace AtomicBool with regular bool
thomaseizinger 1d8094b
Remove unused import
thomaseizinger cc66761
Merge remote-tracking branch 'melekes/anton/webrtc-transport' into re…
thomaseizinger 6bce388
Merge remote-tracking branch 'melekes/anton/webrtc-transport' into re…
thomaseizinger 16fb8e4
Simplify send_buffer handling
thomaseizinger 211baae
Cargo fmt
thomaseizinger 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
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 |
---|---|---|
|
@@ -86,6 +86,7 @@ pub mod transport; | |
|
||
mod fingerprint; | ||
mod in_addr; | ||
mod req_res_chan; | ||
mod sdp; | ||
mod udp_mux; | ||
mod webrtc_connection; |
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,49 @@ | ||
use futures::channel::mpsc; | ||
use futures::channel::oneshot; | ||
use futures::SinkExt; | ||
use futures_lite::StreamExt; | ||
use std::io; | ||
use std::task::{Context, Poll}; | ||
|
||
pub fn new<Req, Res>(capacity: usize) -> (Sender<Req, Res>, Receiver<Req, Res>) { | ||
let (sender, receiver) = mpsc::channel(capacity); | ||
|
||
( | ||
Sender { | ||
inner: futures::lock::Mutex::new(sender), | ||
}, | ||
Receiver { inner: receiver }, | ||
) | ||
} | ||
|
||
pub struct Sender<Req, Res> { | ||
inner: futures::lock::Mutex<mpsc::Sender<(Req, oneshot::Sender<Res>)>>, | ||
thomaseizinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
impl<Req, Res> Sender<Req, Res> { | ||
pub async fn send(&self, req: Req) -> io::Result<Res> { | ||
let (sender, receiver) = oneshot::channel(); | ||
|
||
self.inner | ||
.lock() | ||
.await | ||
.send((req, sender)) | ||
.await | ||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; | ||
let res = receiver | ||
.await | ||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; | ||
|
||
Ok(res) | ||
} | ||
} | ||
|
||
pub struct Receiver<Req, Res> { | ||
inner: mpsc::Receiver<(Req, oneshot::Sender<Res>)>, | ||
} | ||
|
||
impl<Req, Res> Receiver<Req, Res> { | ||
pub fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<(Req, oneshot::Sender<Res>)>> { | ||
self.inner.poll_next(cx) | ||
} | ||
} |
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.
Missing license header. Feel free to ignore.
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.
Can I? I'd love to get rid of those 😅
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.
Haha, I meant "Feel free to ignore [for now]".
I think we should be consistent in this pull request.
I am fine getting rid of them in general, though I would need to check back with some legal experts first.