]> Cypherpunks.ru repositories - govpn.git/commitdiff
Simple optimization for TCP buffer check
authorSergey Matveev <stargrave@stargrave.org>
Mon, 14 Sep 2015 09:16:04 +0000 (12:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 14 Sep 2015 09:16:04 +0000 (12:16 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
src/govpn/cmd/govpn-client/tcp.go
src/govpn/cmd/govpn-server/tcp.go
src/govpn/peer.go

index 49d3ae92cf02e86a9f5c2e5937997ae756b124f7..511955c4400a8a48d8e337e45a9b7b57b2d8443a 100644 (file)
@@ -136,6 +136,9 @@ TransportCycle:
                }
                prev += n
        CheckMore:
+               if prev < govpn.MinPktLength {
+                       continue
+               }
                i = bytes.Index(buf[:prev], nonceExpectation)
                if i == -1 {
                        continue
index 8aedfa9345dbb7b204a8b221f96d8381bccbfd98..d8deaa19b2a4eb6ffda801807ce26db82b56d6ce 100644 (file)
@@ -170,6 +170,9 @@ func handleTCP(conn net.Conn) {
                }
                prev += n
        CheckMore:
+               if prev < govpn.MinPktLength {
+                       continue
+               }
                i = bytes.Index(buf[:prev], nonceExpectation)
                if i == -1 {
                        continue
index f5f917ac594182b1ddfc5fa593546de083024ed8..e666b4755a55c298d51985d22d3e9fc9b4f31cb1 100644 (file)
@@ -24,6 +24,8 @@ const (
        PktSizeSize = 2
        // Heartbeat rate, relative to Timeout
        TimeoutHeartbeat = 4
+       // Minimal valid packet length: 2+
+       MinPktLength = 2 + 16 + 8
 )
 
 func newNonceCipher(key *[32]byte) *xtea.Cipher {