From: Sergey Matveev Date: Wed, 6 Jan 2016 11:53:25 +0000 (+0300) Subject: Take into account user's MTU and encryptionless settings for CPR calculations X-Git-Tag: 5.0^2~8 X-Git-Url: http://www.git.cypherpunks.ru/?p=govpn.git;a=commitdiff_plain;h=772666943c9f8fe001263b0d3e383d0c568db47b Take into account user's MTU and encryptionless settings for CPR calculations Signed-off-by: Sergey Matveev --- 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