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

Found some bugs in the socketfiles code #16

Merged
merged 15 commits into from
Apr 28, 2020
Merged

Conversation

puellanivis
Copy link
Owner

When, I started up an allcat tcp listener with: allcat tcp://:8080 I got a log message: redirected: //[::]:8080. Looking at the code, I missed a Scheme: "tcp" in the tcpreader.go code.

When I went to fix that, I found a few other issues:

  • there were some dial misspellings as dail.
  • Open("tcp://:8080") will not properly cancel listening on a context cancel
  • setForWriter and setForReader were poorly designed.
  • How I was building url.URLs for filenames was kind of wonky.
  • Putting packet_size as a parameter accepted for tcp: but unused, removes a special case for UDP
  • setInt was not a useful helper function. It is a one-line function-call to a one-line function.
  • getInt and getSize do not need to return a bool, none of them accept 0 as a valid value.
  • don’t embed ipSocket instead, make it a named field. (There are weird receiver method exposure with these)
  • for local addresses, use net.ResolveProtoAddr("proto", net.JoinHostPort(…)) rather than a flimsy self-implementation
  • reuse the internal buffer as much as possible when setting packet sizes
  • reuse the time.Ticker in throttling code, which also requires better channel draining hygiene.
  • automatically call updateDelay when updating bitrate on throttler, rather than requiring the caller to call it themselves (it was always being called anyways)
  • We don’t actually need to fully wrap the UDPConn in udpReader, we don’t do anything but redirect the calls, so they could just be done directly with embedding. It’s not our type, and we already leak receiver method implementations for local files, so this fits well.

@puellanivis
Copy link
Owner Author

After extensive testing, I think this is safe to commit. This will follow up with a PR on allcat to support an buffer-size and packet-size argument so that copying, so that you can set buffer to a multiple of a packet-size to ensure that a UDP stream does not get chunked wrong.

I’m thinking I should inpart reimplement files.Copy so that UDP streams are not inherently broken, and thus require setting a proper buffer size. We simply shouldn’t be dropping some parts of packets.

@puellanivis puellanivis merged commit a0b7ad0 into master Apr 28, 2020
@puellanivis puellanivis deleted the patch/socket-bugs branch April 28, 2020 11:52
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.

1 participant