]> Cypherpunks.ru repositories - govpn.git/commitdiff
Take into account user's MTU and encryptionless settings for CPR calculations
authorSergey Matveev <stargrave@stargrave.org>
Wed, 6 Jan 2016 11:53:25 +0000 (14:53 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 6 Jan 2016 11:53:25 +0000 (14:53 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
src/govpn/peer.go

index 2907662c4e168b7f96861e97f200cb5958c1df58..a8db9459569e8d7376fc92112652c011e24859f6 100644 (file)
@@ -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