Skip to content

Commit d4d09ba

Browse files
committed
feat: Add STUN servers to enable P2P
This exposes a `--stun-server` option for listing STUN servers. By default it uses the Google STUN server, but this is not required.
1 parent 8ff0c8b commit d4d09ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cli/gitssh.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"os"
66
"os/exec"
77

8-
"github.com/coder/coder/codersdk"
98
"github.com/spf13/cobra"
109
"golang.org/x/xerrors"
10+
11+
"github.com/coder/coder/codersdk"
1112
)
1213

1314
func gitssh() *cobra.Command {

cli/server.go

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/coreos/go-systemd/daemon"
2121
"github.com/google/go-github/v43/github"
2222
"github.com/pion/turn/v2"
23+
"github.com/pion/webrtc/v3"
2324
"github.com/spf13/cobra"
2425
"golang.org/x/oauth2"
2526
xgithub "golang.org/x/oauth2/github"
@@ -46,6 +47,7 @@ import (
4647
"github.com/coder/coder/provisionersdk/proto"
4748
)
4849

50+
// nolint:gocyclo
4951
func server() *cobra.Command {
5052
var (
5153
accessURL string
@@ -67,6 +69,7 @@ func server() *cobra.Command {
6769
tlsMinVersion string
6870
turnRelayAddress string
6971
skipTunnel bool
72+
stunServers []string
7073
traceDatadog bool
7174
secureAuthCookie bool
7275
sshKeygenAlgorithmRaw string
@@ -176,8 +179,15 @@ func server() *cobra.Command {
176179
return xerrors.Errorf("create turn server: %w", err)
177180
}
178181

182+
iceServers := make([]webrtc.ICEServer, 0)
183+
for _, stunServer := range stunServers {
184+
iceServers = append(iceServers, webrtc.ICEServer{
185+
URLs: []string{stunServer},
186+
})
187+
}
179188
options := &coderd.Options{
180189
AccessURL: accessURLParsed,
190+
ICEServers: iceServers,
181191
Logger: logger.Named("coderd"),
182192
Database: databasefake.New(),
183193
Pubsub: database.NewPubsubInMemory(),
@@ -411,6 +421,9 @@ func server() *cobra.Command {
411421
`Specifies the minimum supported version of TLS. Accepted values are "tls10", "tls11", "tls12" or "tls13"`)
412422
cliflag.BoolVarP(root.Flags(), &skipTunnel, "skip-tunnel", "", "CODER_DEV_SKIP_TUNNEL", false, "Skip serving dev mode through an exposed tunnel for simple setup.")
413423
_ = root.Flags().MarkHidden("skip-tunnel")
424+
cliflag.StringArrayVarP(root.Flags(), &stunServers, "stun-server", "", "CODER_STUN_SERVERS", []string{
425+
"stun:stun.l.google.com:19302",
426+
}, "Specify URLs for STUN servers to enable P2P connections.")
414427
cliflag.BoolVarP(root.Flags(), &traceDatadog, "trace-datadog", "", "CODER_TRACE_DATADOG", false, "Send tracing data to a datadog agent")
415428
cliflag.StringVarP(root.Flags(), &turnRelayAddress, "turn-relay-address", "", "CODER_TURN_RELAY_ADDRESS", "127.0.0.1",
416429
"Specifies the address to bind TURN connections.")

0 commit comments

Comments
 (0)