Skip to content

Commit

Permalink
we still need the protocol parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed May 11, 2022
1 parent 93a893e commit 774a9a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 6 additions & 11 deletions internal/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type InfoOpts struct {
TurnServer string
UseTLS bool
Protocol string
Timeout time.Duration
Log *logrus.Logger
}
Expand All @@ -24,6 +25,9 @@ func (opts InfoOpts) Validate() error {
if !strings.Contains(opts.TurnServer, ":") {
return fmt.Errorf("turnserver needs a port")
}
if opts.Protocol != "tcp" && opts.Protocol != "udp" {
return fmt.Errorf("protocol needs to be either tcp or udp")
}
if opts.Log == nil {
return fmt.Errorf("please supply a valid logger")
}
Expand Down Expand Up @@ -64,7 +68,7 @@ func Info(opts InfoOpts) error {
}

func testStun(opts InfoOpts) ([]internal.Attribute, error) {
conn, err := internal.Connect("udp", opts.TurnServer, opts.UseTLS, opts.Timeout)
conn, err := internal.Connect(opts.Protocol, opts.TurnServer, opts.UseTLS, opts.Timeout)
if err != nil {
return nil, err
}
Expand All @@ -83,16 +87,7 @@ func testStun(opts InfoOpts) ([]internal.Attribute, error) {
}

func testTurn(opts InfoOpts, proto internal.RequestedTransport) ([]internal.Attribute, error) {
var protoString string
switch proto {
case internal.RequestedTransportTCP:
protoString = "tcp"
case internal.RequestedTransportUDP:
protoString = "udp"
default:
protoString = "udp"
}
conn, err := internal.Connect(protoString, opts.TurnServer, opts.UseTLS, opts.Timeout)
conn, err := internal.Connect(opts.Protocol, opts.TurnServer, opts.UseTLS, opts.Timeout)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func main() {
&cli.BoolFlag{Name: "debug", Aliases: []string{"d"}, Value: false, Usage: "enable debug output"},
&cli.StringFlag{Name: "turnserver", Aliases: []string{"s"}, Required: true, Usage: "turn server to connect to in the format host:port"},
&cli.BoolFlag{Name: "tls", Value: false, Usage: "Use TLS for connecting (false in most tests)"},
&cli.StringFlag{Name: "protocol", Value: "udp", Usage: "protocol to use when connecting to the TURN server. Supported values: tcp and udp"},
&cli.DurationFlag{Name: "timeout", Value: 1 * time.Second, Usage: "connect timeout to turn server"},
},
Before: func(ctx *cli.Context) error {
Expand All @@ -65,10 +66,12 @@ func main() {
Action: func(c *cli.Context) error {
turnServer := c.String("turnserver")
useTLS := c.Bool("tls")
protocol := c.String("protocol")
timeout := c.Duration("timeout")
return cmd.Info(cmd.InfoOpts{
TurnServer: turnServer,
UseTLS: useTLS,
Protocol: protocol,
Log: log,
Timeout: timeout,
})
Expand Down

0 comments on commit 774a9a0

Please sign in to comment.