2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 "cypherpunks.ru/govpn"
30 func startUDP(timeouted, rehandshaking, termination chan struct{}) {
31 remote, err := net.ResolveUDPAddr("udp", *remoteAddr)
33 log.Fatalln("Can not resolve remote address:", err)
35 conn, err := net.DialUDP("udp", nil, remote)
37 log.Fatalln("Can not listen on UDP:", err)
39 govpn.Printf(`[connected remote="%s"]`, *remoteAddr)
41 hs := govpn.HandshakeStart(*remoteAddr, conn, conf)
42 buf := make([]byte, *mtu*2)
46 var terminator chan struct{}
55 conn.SetReadDeadline(time.Now().Add(time.Second))
56 n, err = conn.Read(buf)
57 if timeouts == timeout {
58 govpn.Printf(`[connection-timeouted remote="%s"]`, *remoteAddr)
59 timeouted <- struct{}{}
67 if peer.PktProcess(buf[:n], tap, true) {
70 govpn.Printf(`[packet-unauthenticated remote="%s"]`, *remoteAddr)
73 if atomic.LoadUint64(&peer.BytesIn)+atomic.LoadUint64(&peer.BytesOut) > govpn.MaxBytesPerKey {
74 govpn.Printf(`[rehandshake-required remote="%s"]`, *remoteAddr)
75 rehandshaking <- struct{}{}
80 if idsCache.Find(buf[:n]) == nil {
81 govpn.Printf(`[identity-invalid remote="%s"]`, *remoteAddr)
85 peer = hs.Client(buf[:n])
89 govpn.Printf(`[handshake-completed remote="%s"]`, *remoteAddr)
90 knownPeers = govpn.KnownPeers(map[string]**govpn.Peer{*remoteAddr: &peer})
92 go govpn.ScriptCall(*upPath, *ifaceName, *remoteAddr)
96 terminator = make(chan struct{})
97 go govpn.PeerTapProcessor(peer, tap, terminator)
99 if terminator != nil {
100 terminator <- struct{}{}