]> Cypherpunks.ru repositories - govpn.git/commitdiff
Timeout is duration, not integer. Simplify code
authorSergey Matveev <stargrave@stargrave.org>
Fri, 1 May 2015 21:34:18 +0000 (00:34 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 1 May 2015 21:34:18 +0000 (00:34 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
cmd/govpn-client/main.go
cmd/govpn-server/main.go
common.go
transport.go

index 495c22c73685e7bee678cdb70a0d235c7cf4e2f1..f6ca4b35b44a34cb9b219c50f975b4a7bcd228cf 100644 (file)
@@ -25,6 +25,7 @@ import (
        "net"
        "os"
        "os/signal"
+       "time"
 
        "govpn"
 )
@@ -50,7 +51,7 @@ func main() {
        log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
 
        govpn.MTU = *mtu
-       govpn.Timeout = timeout
+       govpn.Timeout = time.Second * time.Duration(timeout)
        govpn.Noncediff = *nonceDiff
        govpn.NoiseEnable = *noisy
 
index 032de005acfd7673bec81eda2b0474022f4ef752..16462b7072907eec28c31ee14496e69bfe2bed50 100644 (file)
@@ -84,7 +84,7 @@ func main() {
        log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
 
        govpn.MTU = *mtu
-       govpn.Timeout = *timeoutP
+       govpn.Timeout = timeout
        govpn.Noncediff = *nonceDiff
        govpn.NoiseEnable = *noisy
        govpn.PeersInit(*peersPath)
index 5be6db0257f8bfc2417dd8c3bff16567dfe898b6..e5ff496fac91da78690202993a476cc8c3961c65 100644 (file)
--- a/common.go
+++ b/common.go
@@ -25,11 +25,12 @@ import (
        "os"
        "os/exec"
        "runtime"
+       "time"
 )
 
 var (
        MTU         int
-       Timeout     int
+       Timeout     time.Duration
        Noncediff   int
        Version     string
        NoiseEnable bool = false
index d0230e1d8987b9688bdd29af1f1d906d84b076c6..eb02494ce9d7f2f36572e392082fd9938a80c651 100644 (file)
@@ -39,6 +39,8 @@ const (
        MaxBytesPerKey int64 = 1 << 32
        // Size of packet's size mark in bytes
        PktSizeSize = 2
+       // Heartbeat rate, relative to Timeout
+       TimeoutHeartbeat = 4
 )
 
 type UDPPkt struct {
@@ -91,15 +93,14 @@ func (p *Peer) Zero() {
 var (
        Emptiness       = make([]byte, 1<<14)
        taps            = make(map[string]*TAP)
-       heartbeatPeriod *time.Duration
+       heartbeatPeriod time.Duration
 )
 
 func heartbeatPeriodGet() time.Duration {
-       if heartbeatPeriod == nil {
-               period := time.Second * time.Duration(Timeout/4)
-               heartbeatPeriod = &period
+       if heartbeatPeriod == time.Duration(0) {
+               heartbeatPeriod = Timeout / TimeoutHeartbeat
        }
-       return *heartbeatPeriod
+       return heartbeatPeriod
 }
 
 // Create TAP listening goroutine.