Skip to content

Conversation

@Sean-Der
Copy link
Member

Relates to #118

@Sean-Der
Copy link
Member Author

@JoeTurki @rg0now I am going to try and implement this with lots of small PRs. Not done yet with this, but wanted to get just [0] working, and then get accepting in a subsequent PR.

We should also allow the user to provide a customer dialer. I saw this suggested in previous PRs. I will mark this with Co-author also, lots of people have worked on this :)

[0] https://datatracker.ietf.org/doc/html/rfc6062#section-4.3

@JoeTurki
Copy link
Member

@Sean-Der This is sooo dope, this was on my todo list for a while, and I feel bad when people ask for features in pion turn and i direct them to coturn or other implementations instead.

@Sean-Der Sean-Der force-pushed the issue-118 branch 3 times, most recently from 9a7e56a to 1620a16 Compare December 22, 2025 04:37
@rg0now
Copy link
Contributor

rg0now commented Dec 22, 2025

I was just wondering how this would change the ServerConfig. Do you plan a ListenerConfig type to mean the server port is a TURN/TCP listener? Or just add a "type" or "protocol" field to all PacketConnConfigs and ListenerConfigs with sane defaults? Can we encapsulate the peer-side complexity (the same TCP relay address must work both as a TCP server for peers to be able to connect back to the TURN client and a TCP client for the reverse direction to work) into the RelayAddressGenerator.AllocateConn()? And all this with a proper net.Dialer like interface (this is the point where the last attempt petered out). Just pondering here, no specific opinions

@Sean-Der Sean-Der force-pushed the issue-118 branch 6 times, most recently from bf4cdbf to fd2e568 Compare December 23, 2025 03:14
@codecov
Copy link

codecov bot commented Dec 23, 2025

Codecov Report

❌ Patch coverage is 79.67480% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.59%. Comparing base (75000e8) to head (6831447).

Files with missing lines Patch % Lines
internal/server/turn.go 80.00% 7 Missing and 7 partials ⚠️
internal/allocation/allocation_manager.go 70.27% 6 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #500      +/-   ##
==========================================
+ Coverage   80.24%   80.59%   +0.35%     
==========================================
  Files          45       46       +1     
  Lines        2693     2809     +116     
==========================================
+ Hits         2161     2264     +103     
+ Misses        354      352       -2     
- Partials      178      193      +15     
Flag Coverage Δ
go 80.59% <79.67%> (+0.35%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sean-Der
Copy link
Member Author

@rg0now I am not sure yet!

What do you think of me landing things with zero configuration, and then we add it back when everything is working?

@Sean-Der Sean-Der force-pushed the issue-118 branch 5 times, most recently from 89b579f to dc83505 Compare December 23, 2025 03:52
@Sean-Der
Copy link
Member Author

@JoeTurki @rg0now Ok can I get a review now?

It's not future complete, but I think this is a good moment to stop and rip into it :)

  • Our TURN Client works against it
  • TURN server hardcodes UDP everywhere when dealing with FiveTuple (this was a problem before)
  • I need to add 30 second timeouts
  • Add things to ServerConfig to give users control
  • and probably more!

At least a few more PRs!

@JoeTurki
Copy link
Member

@Sean-Der I'll review and test this :)

return 0, err
}

conn, err := net.DialTCP("tcp4", nil, &net.TCPAddr{IP: peerAddress.IP, Port: peerAddress.Port}) // nolint: noctx
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the critical point: (1) the Dialer should be an abstract interface and (2) the local address:port must be the transport relay address for the allocation (the TCPAddr we create an allocation.CreateAllocation once we change that to call AllocateConn per the requested transport). The former can be taken care of later, but for the latter we will need to add the SO_REUSEADDR (and maybe also the SO_REUSEPORT? I always forget the difference) otherwise we cannot bind multiple peer connections to the same local addr:port. AFAIK SO_REUSEADDR is supported in all major OSes but SO_REUSEPORT is Linux only

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 Ok I think I can get this right.

What do you think of landing this PR and then I can follow up with a small commit just getting that in?

}
}()

if _, err = io.Copy(stunConn.Conn(), tcpConn); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this one go into the goroutine? I'm confused

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry might be missing the issue :(

We want to block the main Read loop for this connection. This way it doesn't try to read it as a STUN Connection.

io.Copy is uni-directional. I see some examples do the io.Copy in two routines and then use a wait group. That seems like more LoC for same behavior?

@rg0now
Copy link
Contributor

rg0now commented Dec 23, 2025

What do you think of me landing things with zero configuration, and then we add it back when everything is working?

+1 for the pragmatic approach

It just occurred to me that the same TCP listener can work both for creating UDP relay connections and TCP relay connections depending on the requested-transport. Consider my request for adding a "protocol" field to {PacketConn,Listener}Configs void

Otherwise I think the code is pretty nice already!

@Sean-Der
Copy link
Member Author

@rg0now 100% agree with your API.

What do you think of landing this, and then I will expose an API so users can adjust the Listener + Dialer. Easier to review/make progress, but if that has downsides happy to merge as one big PR!

@JoeTurki
Copy link
Member

Okay i reviewed half of this :)
will continue tomorrow.

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.

4 participants