From 772666943c9f8fe001263b0d3e383d0c568db47b Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 6 Jan 2016 14:53:25 +0300 Subject: [PATCH] Take into account user's MTU and encryptionless settings for CPR calculations Signed-off-by: Sergey Matveev --- src/govpn/peer.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/govpn/peer.go b/src/govpn/peer.go index 2907662..a8db945 100644 --- a/src/govpn/peer.go +++ b/src/govpn/peer.go @@ -145,18 +145,24 @@ func (p *Peer) NonceExpectation(buf []byte) { p.NonceCipher.Encrypt(buf, buf) } -func cprCycleCalculate(rate int) time.Duration { - if rate == 0 { +func cprCycleCalculate(conf *PeerConf) time.Duration { + if conf.CPR == 0 { return time.Duration(0) } - return time.Second / time.Duration(rate*(1<<10)/MTUMax) + rate := conf.CPR * 1 << 10 + if conf.Encless { + rate /= EnclessEnlargeSize + conf.MTU + } else { + rate /= conf.MTU + } + return time.Second / time.Duration(rate) } func newPeer(isClient bool, addr string, conn io.Writer, conf *PeerConf, key *[SSize]byte) *Peer { now := time.Now() timeout := conf.Timeout - cprCycle := cprCycleCalculate(conf.CPR) + cprCycle := cprCycleCalculate(conf) noiseEnable := conf.Noise if conf.CPR > 0 { noiseEnable = true -- 2.44.0