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

add support for TrafficPolicy #145

Merged
merged 1 commit into from
Jul 22, 2024
Merged

Conversation

TheConcierge
Copy link
Contributor

@TheConcierge TheConcierge commented Jul 3, 2024

Why

The ngrok backend is now accepting a new field for policy called TrafficPolicy. Unlike the original Policy field which was a highly structured protobuf, this new field is simply a string. The SDK therefore needs to be supported to send this new String policy field to the backend.
Additionally, we want users who are using the old Policy field to still be able to use that until we fully deprecate inbound/outbound so they only have to update their code once. Therefore, this change also serializes the old Policy field as a JSON string and sends it to the backend as TrafficPolicy.

How

The policy field in the proto representation was renamed to TrafficPolicy and changed to a new enum type called PolicyWrapper. This new enum allows it to be either a String (new configuration) or a Policy (old configuration). For string, this just gets sent as is, over the wire, which works. For Policy, a new serialization method was added to convert it into a string upon serialization. Additionally, the serialization for action configs had to be updated to convert it from a Vec<u8> to a String.

In the BindOpts for each connection type, the PolicyWrapper is populated by either the String or the Policy type, depending on what the user set.

Validation

Tunnels using the old Policy stuff and the new TrafficPolicy field were opened through the axum example. Both successfully started and had working policy.

A unit test was added to make sure Policy serializes and deserializes as we expect.

Why did I update the flake?

I was getting an error from a number of different CI test, stating that the #[diagnostic] namespace is experimental. I found this thread stating that it could be caused by using an outdated version of rust nightly. Considering we hadn't updated since Feb, I ran a quick nix flake update and everything seemed to work.

@TheConcierge TheConcierge force-pushed the ngrok/ryan/support-traffic-policy branch 2 times, most recently from ec7bae8 to 8b528e4 Compare July 9, 2024 18:32
@TheConcierge TheConcierge marked this pull request as ready for review July 9, 2024 18:42
Copy link

@rkolavo rkolavo left a comment

Choose a reason for hiding this comment

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

looks okay to me, would love to have someone who has submitted rust into their eyeballs before look at it too

Copy link
Member

@masonj5n masonj5n left a comment

Choose a reason for hiding this comment

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

The serializer stuff turned out pretty good imo, nice work!

@TheConcierge TheConcierge force-pushed the ngrok/ryan/support-traffic-policy branch from c399af3 to 66222c7 Compare July 22, 2024 13:12
@TheConcierge TheConcierge merged commit a59fdcb into main Jul 22, 2024
11 checks passed
@TheConcierge TheConcierge deleted the ngrok/ryan/support-traffic-policy branch July 22, 2024 13:19
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.

3 participants