Tcp#1845
Conversation
4b8eacd to
d02573d
Compare
| match swarm1.next().await { | ||
| RequestResponseEvent::Message { | ||
| match swarm1.next_event().await { | ||
| SwarmEvent::NewListenAddr(addr) => tx.send(addr).await.unwrap(), |
There was a problem hiding this comment.
since we don't use get-if-addrs which I think blocks the thread, it's not guaranteed that the event is emitted immediately
|
|
||
| /// Perform transport specific multiaddr translation. | ||
| fn address_translation(&self, _server: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr>; | ||
|
|
9993189 to
7d068b0
Compare
1532a92 to
adf6cc1
Compare
mxinden
left a comment
There was a problem hiding this comment.
I haven't fully followed the whole effort, thus please bear with me.
As far as I can tell this pull request does 3 things:
-
Move
libp2p-tcptoasync-io. -
Watch for and react to address changes via
if-watch. -
Allow transport specific address translation.
If I am not mistaken these changes are not directly interdependent and could be proposed as separate pull requests, correct? If that is the case, splitting this pull request would help me as a reviewer and would overall simplify the process.
What do others think?
| let socket = self.create_socket(&socket_addr)?; | ||
| socket.bind(&socket_addr.into())?; | ||
| socket.listen(self.backlog as _)?; | ||
| let listener = Async::new(socket.into_tcp_listener())?; |
There was a problem hiding this comment.
I am not familiar with the async-io ecosystem. If I read the docs correctly one should prefer async-net over async-io:
For higher-level primitives built on top of Async, look into async-net or async-process (on Unix).
https://docs.rs/async-io/1.3.1/async_io/struct.Async.html
Can you explain why async-io is needed here?
There was a problem hiding this comment.
It is required because futures from async-net take &self, making them impossible to box without unsafe code. Also I don't really see why another library is required, when async-io is so easy to use.
|
For what it is worth, I'm currently experimenting with this branch, mainly to explore options without a background task and thread, and without the async contructor for |
|
I think there is a good reason for spawning a background task and it's a shame that there isn't much interest in a "simple" solution (async-rs/async-std#912). I guess we can thank carllerche for that as he was the one lobbying to have task spawning removed from |
|
@romanb I assume you gave up on finding a solution? mdns has an async constructor too, so it really doesn't hurt at this point to make tcp also be an async constructor. I think a background task/thread is required in this case, the only alternative would be for each listener to open it's own netlink socket, which would be wasteful (instead of sharing a netlink socket per transport). |
No, I haven't given up, I'm quite happy with the approach I'm currently pursuing and should have something to share by the end of next Monday.
It's one background task & thread per |
|
I opened my proposal as #1887, which builds on this branch. |
|
Closing in favor of #1887 |
Superceeds #1789 .
Simplifies the tcp transport by using async-io instead of macros. This also helps people who can't update to the latest libp2p because it uses tokio 0.3 . Address changes are handled using
if-watch, the same crate used in #1830, instead of polling "randomly". It also supports reusing ports for outgoing connections and makes the address_translation the resposibility of the transport. While theif_watchmodule is currently in the tcp crate, when adding the quic transport it might make sense to move it into a shared transport utility crate.