2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2015 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/>.
29 type UDPSender struct {
34 func (c UDPSender) Write(data []byte) (int, error) {
35 return c.conn.WriteToUDP(data, c.addr)
38 func (c UDPSender) Reorderable() bool {
42 func startUDP(sink chan Pkt) {
43 bind, err := net.ResolveUDPAddr("udp", *bindAddr)
44 ready := make(chan struct{})
46 log.Fatalln("Can not resolve bind address:", err)
48 lconn, err := net.ListenUDP("udp", bind)
50 log.Fatalln("Can not listen on UDP:", err)
52 log.Println("Listening on UDP", *bindAddr)
54 buf := make([]byte, govpn.MTU)
56 var raddr *net.UDPAddr
60 lconn.SetReadDeadline(time.Now().Add(time.Second))
61 n, raddr, err = lconn.ReadFromUDP(buf)
63 sink <- Pkt{ready: ready}
68 UDPSender{lconn, raddr},