1
0
Fork 0
forked from External/grumble

Server-side crypt resync. Properly store ping stats.

This commit is contained in:
Mikkel Krautz 2011-05-13 22:26:15 +02:00
parent 0b086d6f57
commit a2c9a15386
4 changed files with 131 additions and 59 deletions

View file

@ -9,6 +9,7 @@ import (
"crypto/aes"
"crypto/rand"
"os"
"time"
)
const AESBlockSize = 16
@ -20,15 +21,16 @@ type CryptState struct {
DecryptIV [AESBlockSize]byte
decryptHistory [DecryptHistorySize]byte
Good int
Late int
Lost int
Resync int
LastGoodTime int64
RemoteGood int
RemoteLate int
RemoteLost int
RemoteResync int
Good uint32
Late uint32
Lost uint32
Resync uint32
RemoteGood uint32
RemoteLate uint32
RemoteLost uint32
RemoteResync uint32
cipher *aes.Cipher
}
@ -196,10 +198,18 @@ func (cs *CryptState) Decrypt(dst, src []byte) (err os.Error) {
}
cs.Good += 1
cs.Late += late
cs.Lost += lost
if late > 0 {
cs.Late += uint32(late)
} else {
cs.Late -= uint32(-late)
}
if lost > 0 {
cs.Lost = uint32(lost)
} else {
cs.Lost = uint32(-lost)
}
// restart timer
cs.LastGoodTime = time.Seconds()
return
}