/* GoVPN -- simple secure free software virtual private network daemon Copyright (C) 2014-2015 Sergey Matveev 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 . */ package main import ( "io" "log" "net" "time" "govpn" ) func startUDP() (io.Writer, chan []byte, chan struct{}) { remote, err := net.ResolveUDPAddr("udp", *remoteAddr) if err != nil { log.Fatalln("Can not resolve remote address:", err) } c, err := net.DialUDP("udp", nil, remote) conn := io.Writer(c) if err != nil { log.Fatalln("Can not listen on UDP:", err) } sink := make(chan []byte) ready := make(chan struct{}) go func() { buf := make([]byte, govpn.MTU) var n int var err error for { <-ready c.SetReadDeadline(time.Now().Add(time.Second)) n, err = c.Read(buf) if err != nil { sink <- nil continue } sink <- buf[:n] } }() ready <- struct{}{} return conn, sink, ready }