NoiseEnable bool
CPR int
CPRCycle time.Duration `json:"-"`
- EncLess bool
+ Encless bool
MTU int
// Cryptography related
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
}
bufSize := S20BS + 2*conf.MTU
- if conf.EncLess {
- bufSize += EncLessEnlargeSize
+ if conf.Encless {
+ bufSize += EnclessEnlargeSize
noiseEnable = true
}
peer := Peer{
NoiseEnable: noiseEnable,
CPR: conf.CPR,
CPRCycle: cprCycle,
- EncLess: conf.EncLess,
+ Encless: conf.Encless,
MTU: conf.MTU,
Key: key,
p.BytesPayloadOut += int64(len(data))
}
- if p.NoiseEnable && !p.EncLess {
+ if p.NoiseEnable && !p.Encless {
p.frameT = p.bufT[S20BS : S20BS+p.MTU-TagSize]
- } else if p.EncLess {
+ } else if p.Encless {
p.frameT = p.bufT[S20BS : S20BS+p.MTU]
} else {
p.frameT = p.bufT[S20BS : S20BS+len(data)+1+NonceSize]
p.frameT[len(p.frameT)-NonceSize:],
)
var out []byte
- if p.EncLess {
+ if p.Encless {
var err error
- out, err = EncLessEncode(
+ out, err = EnclessEncode(
p.Key,
p.frameT[len(p.frameT)-NonceSize:],
p.frameT[:len(p.frameT)-NonceSize],
}
var out []byte
p.BusyR.Lock()
- if p.EncLess {
+ if p.Encless {
var err error
- out, err = EncLessDecode(
+ out, err = EnclessDecode(
p.Key,
data[len(data)-NonceSize:],
data[:len(data)-NonceSize],