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

feat: add UDP support #20

Merged
merged 17 commits into from
Jun 20, 2023
Merged

feat: add UDP support #20

merged 17 commits into from
Jun 20, 2023

Conversation

antiphp
Copy link
Contributor

@antiphp antiphp commented Jun 19, 2023

Goal of this PR

Resolves #10

Commit-based review recommended.

Checklist

Does the PR require tests to be added or updated?

Yes

Misc

  • PR title is explicit
  • PR includes unit tests for the added code / regression tests for the fixed bugs
  • PR is against the correct branch (likely main)
  • PR is linked to an issue

@antiphp
Copy link
Contributor Author

antiphp commented Jun 19, 2023

How it looks like locally and with adjusted log level for the server:
image

Some notes:

internal/bufio is an implementation from an internal UDP project to solve the issue of buffered reading. Without that, reading partially from UDP packets will most likely result in the rest of the message getting discarded (by the OS?).

We were not consistent in how we call our messages: Sometimes we refer to message, probe or data. Another PR could make it more consistent, but out of scope for now.

WDYT?

@antiphp antiphp requested a review from Ullaakut June 19, 2023 15:47
@antiphp antiphp self-assigned this Jun 19, 2023
@Ullaakut Ullaakut added the enhancement New feature or request label Jun 19, 2023
@Ullaakut
Copy link
Member

We were not consistent in how we call our messages: Sometimes we refer to message, probe or data. Another PR could make it more consistent, but out of scope for now.

IMO those three are different things, the message is the body of the probe, the probe is the packet sent over the network, and data is a generic word that could be used to talk about both of those things. We probably do need a quick round of renamings for consistency if those are scrambled currently, in another PR then yes :)

Copy link
Member

@Ullaakut Ullaakut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small suggestions and nitpicks 👍

Comment on lines 25 to 32
var protocol string
switch {
case c.Bool(flagProtocolTCP) && !c.Bool(flagProtocolUDP):
protocol = "tcp"
case c.Bool(flagProtocolUDP) && !c.Bool(flagProtocolTCP):
protocol = "udp"
default:
return fmt.Errorf("either --%s or --%s must be set", flagProtocolTCP, flagProtocolUDP)
}
log = log.With(lctx.Str("protocol", protocol))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to have one --protocol flag that would be required and allow us to choose between the two protocols? Do we ever want to start both at the same time? If we do, it would be clearer to do it using two connqc processes, WDYT?

Either that or make the protocol a subcommand instead of a flag, i.e. ./server udp --addr=<xxx> / ./server tcp --addr=<xxx>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a discussion around this in Slack (without your input, so you might have missed that?), where we agreed on this approach, at least from my understanding.

Now that I think about it, I mainly voted for --udp & --tcp to allow both connections at once, which is not supported in this implementation haha. As @DrPsychick also insisted that --tcp & --udp "makes it more complicated", I will update this to --protocol with a default to tcp.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we concluded that there are use cases where one would want to send/receive UDP and TCP on the same port, but I would do this in a separate PR now. If one needs to test both, one can run separate instances on 2 different ports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server accepts TCP and UDP on the same port, these params were just for the client.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you prefer, I just thought this could simplify things but if there is a justification for it I am fine with it 👍

In the future make sure to talk about those things on the issue rather than on Slack though, to make the repository more transparent/open 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for clarification: It is now updated to use --protocol=tcp / --protocol=udp on the client side. The server already worked for both. See bc63aed.

Copy link
Member

@Ullaakut Ullaakut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@antiphp antiphp merged commit 9f78270 into nitrado:main Jun 20, 2023
@antiphp antiphp deleted the udp branch June 20, 2023 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add UDP support
3 participants