Repository: pion/turn
Pull request #62 (2019-06-29 07:46:38)

Fix missing default binding lifetime
For details, see #61

I did:
* Added (brought back) default channel binding lifetime
* Added a test to check if the default value is correctly used
* Added comments (for godoc) to ServerConfig struct

codecov-io: # [Codecov](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=h1) Report
> Merging [#62](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=desc) into [master](https://codecov.io/gh/pion/turn/commit/e0f51c0718e614f7bfeeab6a2fb12cc3dce312cd?src=pr&el=desc) will **increase** coverage by `0.25%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pion/turn/pull/62/graphs/tree.svg?width=650&token=1UomjQ7lwC&height=150&src=pr)](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #62      +/-   ##
==========================================
+ Coverage   32.09%   32.35%   +0.25%     
==========================================
  Files          14       14              
  Lines         782      785       +3     
==========================================
+ Hits          251      254       +3     
  Misses        496      496              
  Partials       35       35
```


| [Impacted Files](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [server.go](https://codecov.io/gh/pion/turn/pull/62/diff?src=pr&el=tree#diff-c2VydmVyLmdv) | `45.78% <100%> (+0.86%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=footer). Last update [e0f51c0...2ee20df](https://codecov.io/gh/pion/turn/pull/62?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/server.go b/server.go
index 8862887..1e7c1e4 100644
--- a/server.go
+++ b/server.go
@@ -28,12 +28,18 @@ type AuthHandler func(username string, srcAddr net.Addr) (password string, ok bo
 
 // ServerConfig is a bag of config parameters for Server.
 type ServerConfig struct {
-	Realm              string
-	AuthHandler        AuthHandler
+	// Realm sets the realm for this server
+	Realm string
+	// AuthHandler is the handler called on each incoming auth requests.
+	AuthHandler AuthHandler
+	// ChannelBindTimeout sets the lifetime of channel binding. Defaults to 10 minutes.
 	ChannelBindTimeout time.Duration
-	ListeningPort      int
-	LoggerFactory      logging.LoggerFactory
-	Net                *vnet.Net
+	// ListeningPort sets the listening port number. Defaults to 3478.
+	ListeningPort int
+	// LoggerFactory must be set for logging from this server.
+	LoggerFactory logging.LoggerFactory
+	// Net is used by pion developers. Do not use in your application.
+	Net *vnet.Net
 }
 
 type listener struct {
@@ -76,13 +82,18 @@ func NewServer(config *ServerConfig) *Server {
 		listenPort = 3478
 	}
 
+	channelBindTimeout := config.ChannelBindTimeout
+	if channelBindTimeout == 0 {
+		channelBindTimeout = turn.DefaultLifetime
+	}
+
 	return &Server{
 		listenPort:         listenPort,
 		realm:              config.Realm,
 		authHandler:        config.AuthHandler,
 		manager:            manager,
 		reservationManager: &allocation.ReservationManager{},
-		channelBindTimeout: config.ChannelBindTimeout,
+		channelBindTimeout: channelBindTimeout,
 		log:                log,
 		net:                config.Net,
 	}


Test patch:
diff --git a/server_test.go b/server_test.go
index 471ee02..2366008 100644
--- a/server_test.go
+++ b/server_test.go
@@ -5,6 +5,7 @@ import (
 	"testing"
 	"time"
 
+	"github.com/gortc/turn"
 	"github.com/pion/logging"
 	"github.com/stretchr/testify/assert"
 )
@@ -28,6 +29,8 @@ func TestServer(t *testing.T) {
 			LoggerFactory: loggerFactory,
 		})
 
+		assert.Equal(t, turn.DefaultLifetime, server.channelBindTimeout, "should match")
+
 		err := server.AddListeningIPAddr("127.0.0.1")
 		assert.NoError(t, err, "should succeed")