Skip to content

Commit

Permalink
Make generic servers using password auth work (#13)
Browse files Browse the repository at this point in the history
* Make generic ice servers with password auth work

* Make generic STUN servers without queries work
  • Loading branch information
levaitamas authored Oct 3, 2024
1 parent 2f1fa7c commit 2cf7942
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 16 deletions.
54 changes: 53 additions & 1 deletion client/ice-servers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"fmt"
"log/slog"

"github.com/nimbleape/iceperf-agent/adapters"
Expand All @@ -19,7 +20,58 @@ import (
)

func formGenericIceServers(config *config.ICEConfig) (adapters.IceServersConfig, error) {
return adapters.IceServersConfig{}, nil
iceServers := []webrtc.ICEServer{}
if config.StunEnabled {
for proto, ports := range config.StunPorts {
query := ""
if !config.StunUseRFC7094URI {
query = fmt.Sprintf("?transport=%s", proto)
}
for _, port := range ports {
stunProto := "stun"
if proto == "tls" {
stunProto = "stuns"
}
url := fmt.Sprintf("%s:%s:%d%s", stunProto, config.StunHost, port, query)

iceServers = append(iceServers,
webrtc.ICEServer{
URLs: []string{url},
Username: config.Username,
Credential: config.Password,
CredentialType: webrtc.ICECredentialTypePassword,
})

}
}
}
if config.TurnEnabled {
for proto, ports := range config.TurnPorts {
for _, port := range ports {
turnProto := "turn"
if proto == "tls" {
turnProto = "turns"
}
url := fmt.Sprintf("%s:%s:%d?transport=%s",
turnProto, config.TurnHost, port, proto)

iceServers = append(iceServers,
webrtc.ICEServer{
URLs: []string{url},
Username: config.Username,
Credential: config.Password,
CredentialType: webrtc.ICECredentialTypePassword,
})
}
}

}
c := adapters.IceServersConfig{
IceServers: iceServers,
DoThroughput: config.DoThroughput,
}

return c, nil
}

type IceServersConfig struct {
Expand Down
31 changes: 16 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ import (
)

type ICEConfig struct {
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
ApiKey string `json:"apiKey,omitempty" yaml:"api_key,omitempty"`
AccountSid string `yaml:"account_sid,omitempty"`
RequestUrl string `json:"requestUrl,omitempty" yaml:"request_url,omitempty"`
HttpUsername string `yaml:"http_username"`
HttpPassword string `yaml:"http_password"`
Enabled bool `yaml:"enabled"`
StunHost string `yaml:"stun_host,omitempty"`
TurnHost string `yaml:"turn_host,omitempty"`
TurnPorts map[string][]int `yaml:"turn_ports,omitempty"`
StunPorts map[string][]int `yaml:"stun_ports,omitempty"`
StunEnabled bool `yaml:"stun_enabled"`
TurnEnabled bool `yaml:"turn_enabled"`
DoThroughput bool `yaml:"do_throughput"`
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
ApiKey string `json:"apiKey,omitempty" yaml:"api_key,omitempty"`
AccountSid string `yaml:"account_sid,omitempty"`
RequestUrl string `json:"requestUrl,omitempty" yaml:"request_url,omitempty"`
HttpUsername string `yaml:"http_username"`
HttpPassword string `yaml:"http_password"`
Enabled bool `yaml:"enabled"`
StunUseRFC7094URI bool `yaml:"stun_use_rfc7094_uri"`
StunHost string `yaml:"stun_host,omitempty"`
TurnHost string `yaml:"turn_host,omitempty"`
TurnPorts map[string][]int `yaml:"turn_ports,omitempty"`
StunPorts map[string][]int `yaml:"stun_ports,omitempty"`
StunEnabled bool `yaml:"stun_enabled"`
TurnEnabled bool `yaml:"turn_enabled"`
DoThroughput bool `yaml:"do_throughput"`
}

type LokiConfig struct {
Expand Down

0 comments on commit 2cf7942

Please sign in to comment.