]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/cypherpunks.ru/govpn/stats.go
Forbid any later GNU GPL versions autousage
[govpn.git] / src / cypherpunks.ru / govpn / stats.go
index 1d956742607071447999665b39bd53a4db1dd2e2..f227d631d4eef79d0bad4cccdce0fb69bcc91dae 100644 (file)
@@ -1,11 +1,10 @@
 /*
 GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2019 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
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, version 3 of the License.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,6 +21,7 @@ import (
        "encoding/json"
        "log"
        "net"
+       "sync"
        "time"
 )
 
@@ -29,15 +29,13 @@ const (
        RWTimeout = 10 * time.Second
 )
 
-type KnownPeers map[string]**Peer
-
 // StatsProcessor is assumed to be run in background. It accepts
 // connection on statsPort, reads anything one send to them and show
 // information about known peers in serialized JSON format. peers
 // argument is a reference to the map with references to the peers as
 // values. Map is used here because of ease of adding and removing
 // elements in it.
-func StatsProcessor(statsPort net.Listener, peers *KnownPeers) {
+func StatsProcessor(statsPort net.Listener, peers *sync.Map) {
        var conn net.Conn
        var err error
        var data []byte
@@ -52,9 +50,10 @@ func StatsProcessor(statsPort net.Listener, peers *KnownPeers) {
                conn.Read(buf)
                conn.Write([]byte("HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n"))
                var peersList []*Peer
-               for _, peer := range *peers {
-                       peersList = append(peersList, *peer)
-               }
+               peers.Range(func(_, peerI interface{}) bool {
+                       peersList = append(peersList, *peerI.(**Peer))
+                       return true
+               })
                data, err = json.Marshal(peersList)
                if err != nil {
                        panic(err)