bmwill / memory-socket

An in-memory socket abstraction for Rust
Apache License 2.0
7 stars 3 forks source link

Thoughts on SocketAddr switchboard #3

Open dusty-phillips opened 4 years ago

dusty-phillips commented 4 years ago

For my use as a test socket, I'm looking for memory-socket to mimic a normal socket as much as possible.

In order to fully mimic them, I'd like the keys in the SWITCHBOARD to be SocketAddr instead of u16s. This would allow me to call it seamlessly with other socket traits. I know that'd be a huge breaking change for memory-socket, and I'm happy to maintain my own fork. But I wanted to run it by you in case a) you'd accept the contribution and b) you had a good reason not to implement it that way so I can avoid making such a mistake. ;-)

bmwill commented 4 years ago

I'd be happy to accept any contributions :)

That would probably be a good change since it would make the type more interchangeable. I wish there was a set of standard socket traits for connecting/listening so that they would be completely interchangeable but such is the current state of things.

The primary reason I implemented the address using a u16 instead of a full SocketAddr was mostly because I wanted to punt the question of what to do with the ip address part since anything but localhost doesn't quite make sense (and even then localhost can be misleading). One way to possibly implement this is to just change the public interfaces of the various connect/listen functions to take in a SocketAddr instead of a u16 and then convert the SocketAddr into a u16 by just grabbing the port, ensuring that the ip address part is equal to some static value like localhost. Or...

Though thinking about this more perhaps the SWITCHBOARD can use a SocketAddr as a key and then you can bind and connect to the whole address/port space fairly easily. This probably sounds closer to what you're trying to achieve correct?

dusty-phillips commented 4 years ago

Yeah, I figure the switchboard can have keys for every possible host/port combo, and therefore mimic "The entire internet" instead of just one port.

It wouldn't make sense to listen on 0.0.0.0 in that case, but if we assume one ip per machine, I think it's reasonable to set up test nets with multiple addresses.

I'll throw together a prototype tomorrow and see what issues come up.

bmwill commented 4 years ago

Sounds good! Look forward to seeing it :)

dusty-phillips commented 4 years ago

It's not quite working yet, but before I forget: Kudos from a fellow Brandon Sanderson fan. ;-)

dusty-phillips commented 4 years ago

There it is.

BTW, in a parallel project, I've been trying to make that set of dialer traits you mentioned, but only for async usage. I'll talk to my boss about open sourcing it since you mentioned it as being useful. They're a bit of a mess, I'm afraid; without generic abstract traits, Rust is, in my opinion, an unfinished language!

Nautigsam commented 3 months ago

If I'm not mistaken, this change was pushed on master but never released. Could you please publish a new version on Cargo so we can use it?