+/*
+GoVPN -- simple secure free software virtual private network daemon
+Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
package govpn
import (
PktSizeSize = 2
// Heartbeat rate, relative to Timeout
TimeoutHeartbeat = 4
- // Minimal valid packet length: 2+
+ // Minimal valid packet length
MinPktLength = 2 + 16 + 8
)
p.BusyR.Unlock()
}
+func (p *Peer) NonceExpectation(buf []byte) {
+ binary.BigEndian.PutUint64(buf, p.NonceExpect)
+ p.NonceCipher.Encrypt(buf, buf)
+}
+
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)
- noiseEnable := conf.NoiseEnable
+ noiseEnable := conf.Noise
if conf.CPR > 0 {
noiseEnable = true
timeout = cprCycle
}
func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool {
+ if len(data) < MinPktLength {
+ return false
+ }
p.BusyR.Lock()
for i := 0; i < SSize; i++ {
p.bufR[i] = byte(0)
p.BusyR.Unlock()
return true
}
+ if int(p.pktSizeR) > len(data) - MinPktLength {
+ return false
+ }
p.BytesPayloadIn += int64(p.pktSizeR)
tap.Write(p.bufR[S20BS+PktSizeSize : S20BS+PktSizeSize+p.pktSizeR])
p.BusyR.Unlock()