2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2017 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 RWTimeout = 10 * time.Second
32 // KnownPeers map of all connected GoVPN peers
33 type KnownPeers map[string]**Peer
35 // StatsProcessor is assumed to be run in background. It accepts
36 // connection on statsPort, reads anything one send to them and show
37 // information about known peers in serialized JSON format. peers
38 // argument is a reference to the map with references to the peers as
39 // values. Map is used here because of ease of adding and removing
41 func StatsProcessor(statsPort net.Listener, peers *KnownPeers) {
45 buf := make([]byte, 2<<8)
47 conn, err = statsPort.Accept()
49 log.Println("Error during accepting connection", err.Error())
52 conn.SetDeadline(time.Now().Add(RWTimeout))
54 conn.Write([]byte("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n"))
56 for _, peer := range *peers {
57 peersList = append(peersList, *peer)
59 data, err = json.Marshal(peersList)