/*
GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2016 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
import (
"bytes"
- "encoding/binary"
"log"
"net"
"sync/atomic"
}
conn, err := net.DialTCP("tcp", nil, remote)
if err != nil {
- log.Fatalln("Can not connect to remote address:", err)
+ log.Fatalln("Can not connect to address:", err)
}
+ log.Println("Connected to TCP:" + *remoteAddr)
handleTCP(conn, timeouted, rehandshaking, termination)
}
func handleTCP(conn *net.TCPConn, timeouted, rehandshaking, termination chan struct{}) {
hs := govpn.HandshakeStart(*remoteAddr, conn, conf)
- buf := make([]byte, govpn.MTU)
+ buf := make([]byte, 2*(govpn.EncLessEnlargeSize+govpn.MTU)+govpn.MTU)
var n int
var err error
var prev int
break HandshakeCycle
default:
}
- if prev == govpn.MTU {
+ if prev == len(buf) {
+ log.Println("Timeouted waiting for the packet")
+ timeouted <- struct{}{}
break HandshakeCycle
}
conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
n, err = conn.Read(buf[prev:])
if err != nil {
- // Either EOFed or timeouted
+ log.Println("Connection timeouted")
+ timeouted <- struct{}{}
break HandshakeCycle
}
prev += n
- peerId := govpn.IDsCache.Find(buf[:prev])
+ peerId := idsCache.Find(buf[:prev])
if peerId == nil {
continue
}
}
nonceExpectation := make([]byte, govpn.NonceSize)
- binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
- peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+ peer.NonceExpectation(nonceExpectation)
prev = 0
var i int
TransportCycle:
break TransportCycle
default:
}
- if prev == govpn.MTU {
+ if prev == len(buf) {
+ log.Println("Timeouted waiting for the packet")
timeouted <- struct{}{}
break TransportCycle
}
conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
n, err = conn.Read(buf[prev:])
if err != nil {
- // Either EOFed or timeouted
+ log.Println("Connection timeouted")
timeouted <- struct{}{}
break TransportCycle
}
continue
}
if !peer.PktProcess(buf[:i+govpn.NonceSize], tap, false) {
+ log.Println("Unauthenticated packet, dropping connection")
timeouted <- struct{}{}
break TransportCycle
}
rehandshaking <- struct{}{}
break TransportCycle
}
- binary.BigEndian.PutUint64(nonceExpectation, peer.NonceExpect)
- peer.NonceCipher.Encrypt(nonceExpectation, nonceExpectation)
+ peer.NonceExpectation(nonceExpectation)
copy(buf, buf[i+govpn.NonceSize:prev])
prev = prev - i - govpn.NonceSize
goto CheckMore
terminator <- struct{}{}
}
peer.Zero()
+ conn.Close()
}