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

User-aware relay address generator #422

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

User-aware relay address generator #422

wants to merge 1 commit into from

Conversation

enobufs
Copy link
Member

@enobufs enobufs commented Nov 18, 2024

Resolves #420

Description

Details of this feature are described in #420.
This PR make following changes:

  • Added username argument to AllocatePacketConn and AllocateConn callback methods in RelayAddressGenerator
  • Added/updated corresponding unit tests.

NOTCE: This is a breaking change for TURN server applications.

Reference issue

Fixes #420

@enobufs enobufs requested a review from Sean-Der November 18, 2024 05:59
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 69.23077% with 16 lines in your changes missing coverage. Please review.

Project coverage is 67.43%. Comparing base (3ff9392) to head (2650e82).

Files with missing lines Patch % Lines
internal/server/turn.go 75.00% 2 Missing and 3 partials ⚠️
internal/allocation/allocation_manager.go 57.14% 2 Missing and 1 partial ⚠️
relay_address_generator_none.go 0.00% 2 Missing ⚠️
relay_address_generator_range.go 0.00% 2 Missing ⚠️
server.go 0.00% 2 Missing ⚠️
internal/server/util.go 93.75% 1 Missing ⚠️
relay_address_generator_static.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #422      +/-   ##
==========================================
+ Coverage   66.63%   67.43%   +0.80%     
==========================================
  Files          43       43              
  Lines        2919     2933      +14     
==========================================
+ Hits         1945     1978      +33     
+ Misses        807      793      -14     
+ Partials      167      162       -5     
Flag Coverage Δ
go 67.43% <69.23%> (+0.80%) ⬆️
wasm 28.98% <28.84%> (+1.84%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

server_config.go Outdated Show resolved Hide resolved
internal/server/turn.go Outdated Show resolved Hide resolved
@rg0now
Copy link
Contributor

rg0now commented Nov 20, 2024

Thanks a lot, this makes the code much leaner. I guess we'll have to wait for @Sean-Der to merge this though because API changes will require a new release (I guess we'll be at v5 already!).

@jech
Copy link
Member

jech commented Dec 11, 2024

The basic idea is sound, but we're breaking backwards compatibility for a fairly ad hoc feature. If we're going to break compatibility, why don't we do it right, so that we don't need to break it again in the future?

I would suggest defining a new type:

type TurnContext struct {
    Username string
}

and passing that as the new argument. This way, if we ever feel the need to add extra parameters, we can just add them to TurnContext and not break compatibility again.

@enobufs
Copy link
Member Author

enobufs commented Dec 12, 2024

Agreed. I will update the code.

@enobufs
Copy link
Member Author

enobufs commented Dec 16, 2024

As I was making changes, i had a couple of thoughts:

Name the context as AllocationContext allocation.Context instead of TurnContext

I feel it is more descriptive for what it does. @jech

Update: I thought about AllocationContext, then realized it is in the allocation package. To avoid stuttering, I ended up using allocation.Context.

Add Real field to the context as well

@rg0now I remember you suggested this earlier and I now feel it is good to have it as a piece of the context.

I will push my local changes shortly. Thanks.

@jech
Copy link
Member

jech commented Dec 16, 2024

To avoid stuttering, I ended up using allocation.Context.

That will cause confusion with context.Context. What about Parameters?

(I'll review your code later.)

@enobufs
Copy link
Member Author

enobufs commented Dec 17, 2024

"allocation context" feel right to me, but I agree that it could be confused by context.Context.

I had following candidate in my head:

  • allocation.AllocationContext (stuttering but might not be too bad)
  • allocation.UserInfo
  • allocation.Metadata
  • allocation.Session

(I will fix the lint error later - I have just noticed)

@enobufs
Copy link
Member Author

enobufs commented Dec 30, 2024

Updated the code, and fixed the lint error also.
@jech I chose "Metadata". It is concise and generic enough to accommodate other possible information we may have in the future.

@jech
Copy link
Member

jech commented Dec 30, 2024

Metadata is fine. (Although frankly, why not just use data? What's so meta about it?)

Perhaps you could squash the commits, it would make review easier?

@enobufs
Copy link
Member Author

enobufs commented Dec 31, 2024

Thanks @jech, I have squashed the commits.

I feel "metadata" is a suitable term because it represents contextual information related to the operation. It is not primary data, such as network or port number, nor is it a parameter required for the operation. Instead, it serves as supplemental information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Allow per-user TURN relay allocation
3 participants