Fix PingRecord race condition (#149)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/sourcegraph/conc"
|
||||
@@ -49,6 +50,7 @@ type VirtualTun struct {
|
||||
Conf *DeviceConfig
|
||||
// PingRecord stores the last time an IP was pinged
|
||||
PingRecord map[string]uint64
|
||||
PingRecordLock *sync.Mutex
|
||||
}
|
||||
|
||||
// RoutineSpawner spawns a routine (e.g. socks5, tcp static routes) after the configuration is parsed
|
||||
@@ -475,7 +477,9 @@ func (d VirtualTun) pingIPs() {
|
||||
}
|
||||
}
|
||||
|
||||
d.PingRecordLock.Lock()
|
||||
d.PingRecord[addr.String()] = uint64(time.Now().Unix())
|
||||
d.PingRecordLock.Unlock()
|
||||
|
||||
defer socket.Close()
|
||||
}()
|
||||
|
||||
@@ -3,6 +3,7 @@ package wireproxy
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"net/netip"
|
||||
|
||||
@@ -86,5 +87,6 @@ func StartWireguard(conf *DeviceConfig, logLevel int) (*VirtualTun, error) {
|
||||
Conf: conf,
|
||||
SystemDNS: len(setting.DNS) == 0,
|
||||
PingRecord: make(map[string]uint64),
|
||||
PingRecordLock: new(sync.Mutex),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user