-
Notifications
You must be signed in to change notification settings - Fork 3
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
Prototype listening on SocketAddr instead of port (WIP) #4
Conversation
The basic idea is the same, but it better mimics the normal socket interface. The Switchboard can now be thought of as a parody of the entire internet instead of a single machine. Most everything is a direct mapping, but there are two uncertain situations: * When connect() is called, there is no clear indicator as to where the client is connecting *from*. So if we ever wanted to implement e.g. peer_addr on a MemorySocket, the behaviour would be undefined. * It is not clear what address to listen on when connecting to 0.0.0.0. Both of these *could* be solved by mapping to the local machine address (using e.g the get_if_addrs crate), but I'm not sure that make sense. Another option I toyed with was having a "set_connect_address" global, but that simply lacked elegance. ( Discussion in bmwill#3 )
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.
Sorry this took me a little bit to get to. I think some of my concerns mostly stem from the awkwardness of how to handle the ip portion of a socketaddr and I'm remembering more and more why i punted on it at the time :)
I think this is on the right track though I'm not 100% sure what the right way to handle some of the edge API cases would be (ie ToScoketAddr
doing hostname resolution), it just might take some more time to think through it.
d489cad
to
2b14545
Compare
2b14545
to
40ad6c4
Compare
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.
This is looking much closer. There's just a couple tweaks left and then this should be good!
src/async.rs
Outdated
@@ -41,7 +41,7 @@ impl MemoryListener { | |||
IncomingStream { inner: self } | |||
} | |||
|
|||
fn poll_accept(&mut self, context: &mut Context) -> Poll<Result<MemorySocket>> { | |||
pub fn poll_accept(&mut self, context: &mut Context) -> Poll<Result<MemorySocket>> { |
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 don't think this needs to be made public?
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.
It's public in tokio, so I'm not sure. accept
is also async in tokio, but not in this impl, so I'm not sure how close to match it.
src/lib.rs
Outdated
// Similarly, it doesn't make a sense to listen on "all interfaces" | ||
// in this environment, so return an error if they requested 0.0.0.0 | ||
// TODO: We could use get_if_addrs and use the host's real name? |
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.
This comment could probably be tweaked a bit, I'm not sure what "similarly" is referring to in this context.
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.
Must have been referring to something that got deleted when I switch to SocketAddr
. Will reword.
src/lib.rs
Outdated
if let Some(sender) = switchboard.0.get_mut(&address) { | ||
let (socket_a, socket_b) = Self::new_pair(); | ||
// Send the socket to the listener | ||
sender | ||
.send(socket_a) | ||
.map_err(|_| ErrorKind::AddrNotAvailable)?; | ||
|
||
Ok(socket_b) | ||
} else { | ||
Err(ErrorKind::AddrNotAvailable.into()) | ||
} |
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.
This is probably a little bit easier to read if you remove the if let
and just map the get_mut
result to an error with ok_or_else
and ?
like was done before.
I believe the only thing that needs to be changed here is just changing from port to address, the construction of the new socket and sending one half over the channel shouldn't need to be changed.
src/lib.rs
Outdated
pub fn local_addr(&self) -> Result<SocketAddr> { | ||
Ok(self.address) |
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'm not sure if there is value in having this returning a result since its an infallible call. You might have had some reason to tweak it though
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.
It returns a Result
in std::net
and tokio::net
, so I was going for drop-in symmetry. I'm happy to go either way, though; your call.
Made most of the requested changes; awaiting guidance on whether to match the other implementations for the public |
I think that since getting I also think that
If this isn't needed now then it could probably wait to be added at a later point in time (mostly because it doesn't really relate to converting the lib to use SocketAddrs which is the primary focus of this PR) |
0fc22e2
to
6df9301
Compare
6df9301
to
c3da08b
Compare
Should have hit all the points hit now; I had them in my local directory for several days but apparently forgot to push. 🤦♂️ |
Sorry this took me a bit to get back to, thanks for making those tweaks! |
The basic idea is the same, but it better mimics
the normal socket interface.
The Switchboard can now be thought of as
a parody of the entire internet
instead of a single machine.
Most everything is a direct mapping,
but there are two uncertain situations:
as to where the client is connecting from.
So if we ever wanted to implement e.g. peer_addr
on a MemorySocket,
the behaviour would be undefined.
connecting to 0.0.0.0.
Both of these could be solved by mapping to the local
machine address (using e.g the get_if_addrs crate),
but I'm not sure that make sense.
Another option I toyed with was having a "set_connect_address"
global, but that simply lacked elegance.
( Discussion in #3 )