Open rg0now opened 1 week ago
CC @renandincer
Attention: Patch coverage is 90.86294%
with 18 lines
in your changes missing coverage. Please review.
Project coverage is 68.62%. Comparing base (
cc03474
) to head (dae4d0c
). Report is 1 commits behind head on master.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
I just looked at it briefly @rg0now! Thank you for PRing this in.
I think it might be useful to get a handle to the PacketConn from OnAllocatedCreated as well. This might be useful for rate limiting. What do you think?
I think a better way to handle rate limiting would be to provide a RelayAddressGenerator.AllocatePacketConn
to the server that will emit rate-limited packetconns. This works even today. The only issue with that approach is if we need user context for applying rate limiting (i.e., when different users may get different rate limits), since currently we miss the user context in the RelayAddressGenerator
interface handlers. But then again, it would somehow be more adequate to add the user context there. Wdyt?
Agreed. Only issue is that would be a breaking API change.
Fixes https://github.com/pion/turn/issues/324, https://github.com/pion/turn/pull/325, and https://github.com/pion/turn/pull/402
This PR adds a set of callbacks that can be used to track the lifecycle of TURN allocations in the server. This allows user code to be called whenever an authentication request has been processed (this can be used to mitigate DoS attacks against a server, see https://github.com/pion/turn/pull/402), when an allocation has been created/removed (e.g., to implement user tracking for adding quota support, see https://github.com/pion/turn/issues/324), when a permission has been created/removed (e.g., to log the peers a user tries to reach via the server), a channel has been created/removed (this will simplify integrating external TURN accelerators, see https://github.com/pion/turn/pull/360), or when an allocation ends with an error.
The implementation adds a new
EventHandlers
struct to theServerConfig
, defined as follows:It is OK to handle only a subset of the events.
Caveats:
Refresh
,CreatePermission
orChannelBind
message may use a different credential. Since this does not seem to be easy to implement with thePeerConnection
API, credential swaps are currently no tracked.