Skip to content
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

more work on net::tcp and net::ip #2731

Closed
wants to merge 45 commits into from
Closed

more work on net::tcp and net::ip #2731

wants to merge 45 commits into from

Conversation

olsonjeffery
Copy link
Contributor

(hopefully) just in time for 0.3!

What's included

  • more work/cleanup on tcp tests. found and fixed a few bugs/memory leaks around failures to bind/connect
  • reworked net::ip to utilize libuv's facilities for representing IP addresses. As a consequence, we have IPv6 support, now! (see caveat below)
  • added net::ip::get_addr() that will return an [ip_addr]/~, utilizing libuv's uv_getaddrinfo call under the hood. We have (albeit simplistic) name resolution!
  • I dumped a large chunk of the net::tcp API (the server workflow that returned a port-like object to listen on for new connections).. we're still stuck with the callback that runs on the libuv thread .. I was going to add another overload that will just accept() every new connection, sidestepping the need for running a blocking callback, but then I took an array to the knee (just kidding.. I ran into a wild CC bug and decided to back out the work). But the code around the tcp server workflow was pretty well refactored that I can add this new workflow with relatively little additional LOCs.
  • impls for io::reader and io::writer that wrap net::tcp::tcp_socket in a simple buffer. This is happening as part of a larger conversation/proof-of-concept for revisiting Streams as a generalized concept, in rust.

What's next?

  • We need to rebase the libuv submodule (node.js 0.8.0 just dropped and there's been a lot of change in upstream libuv). This will bring a few API changes that could prove to be pretty useful to us. Hopefully this won't entail too much work on our end.
  • I'd love to take a crack at using rust-bindgen to generate the libuv bindings, but there'll all kinds of pitfalls that this entails. I'll probably give it a try, but not hammer on it too hard if I hit a wall.
  • There are a few dangling pieces of tcp API i haven't added (like setting the keepalive).
  • UDP
  • async filesystem stuff that libuv exposes.
  • ...?

caveat about IPv6:

By the admission of libuv's devs, IPv6 support is somewhat spotty, atm. Insofar as a malformed address that is passed in to uv_ip6_addr/name will still parse correctly. So users don't have any sanity checks that what they're plugging in will actually work. We're still in a better place than we were, though. The "right answer", in the mid-term, is to roll a pure-rust string parser for IPv6 addresses, like what we already have for IPv4. That way we can be sure we're passing valid input to libuv.

questions/feedback apprecaited, as always.

msullivan and others added 30 commits June 28, 2012 22:55
* updated rustdoc info for several functions
* changed read_stop to take control of the port returned by read_start
* made write_future do an explicit data copy with the binary vector it is
passed
…yet.

need to do some other work, in the subsequent commit, to add io::writer,
then tests.
…fails.

needs work. probably the slice code and/or the way that the tcp_socket_buf
is wrapped in a shared box
…test

i mistook an "unconstrained type" error, due to type-inference messup
because i didnt have return vals in some closure wired-up right, for being
due to not having a str as a str/& (a str will actually auto-coerce to a
str/&, so str::as_slice was erroneously added. my bad).
…dr_in6

.. but the test is kind of broken.. it appears that rust pads structs for
alignment purposes? I can't get the struct to == 28.. that appears to
be the native size of sockaddr_in6.. so we have a size 32 struct, for now.
replaces net::ip's previously, hand-rolled impl for ipv4 addr parsing..
we're relying on libuv, now
.. stub out some brokeness in net::tcp as a result of ipv6 coming online
…eats)

libuv's own ip vetting code appears to in a somewhat woeful state,
for both ipv4 and ipv6 (there are some notes in the tests for net_ip, as
well as stuff added in uv_ll). They are aware of this and welcome patches.

I have rudimentary code in place that can verify whether the provided str
ip was, in fact, validly parsed by libuv, making a few assumptions:

* for ipv4, we assume that the platform's INADDR_NONE val is 0xffffffff ,
I should write a helper to return this value from the platform's libc
headers instead of hard-coding it in rust.
* for ipv6, we assume that the library will always return '::' for
malformed inputs.. as is the case in 64bit ubuntu. I need to verify this
on other platforms.. but at least the debugging output is in place, so
if expectations don't line up, it'll be straightforward to address
now the best of what we had prior to libuv integration (proper
validation of an ipv4 string), along with libuv support
(initial ipv6 support)

libuv has even weaker facilities for validating an input ipv6
(but still more than what we had), so eventually the "right"
answer would be to roll a proper ipv6 address string parser
in rust
.. there are some additional FIXME nags in net_tcp (L 1012) about blocking
because libuv is holding unsafe ptrs to task local data. the proposed
fix going is not really feasible w/ the current design, IMO, but i'll
leave it there in case someone really wants to make the case without
creating more hassle than it's worth.
@olsonjeffery
Copy link
Contributor Author

closing and re-opening as #2751

RalfJung pushed a commit to RalfJung/rust that referenced this pull request Dec 24, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants