mirror of
https://github.com/whyvl/wireproxy.git
synced 2025-04-29 19:01:42 +02:00
Fix PingRecord race condition (#149)
This commit is contained in:
parent
3098c397e7
commit
d710683181
2 changed files with 12 additions and 6 deletions
|
@ -21,6 +21,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sourcegraph/conc"
|
"github.com/sourcegraph/conc"
|
||||||
|
@ -48,7 +49,8 @@ type VirtualTun struct {
|
||||||
SystemDNS bool
|
SystemDNS bool
|
||||||
Conf *DeviceConfig
|
Conf *DeviceConfig
|
||||||
// PingRecord stores the last time an IP was pinged
|
// PingRecord stores the last time an IP was pinged
|
||||||
PingRecord map[string]uint64
|
PingRecord map[string]uint64
|
||||||
|
PingRecordLock *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// RoutineSpawner spawns a routine (e.g. socks5, tcp static routes) after the configuration is parsed
|
// 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.PingRecord[addr.String()] = uint64(time.Now().Unix())
|
||||||
|
d.PingRecordLock.Unlock()
|
||||||
|
|
||||||
defer socket.Close()
|
defer socket.Close()
|
||||||
}()
|
}()
|
||||||
|
|
12
wireguard.go
12
wireguard.go
|
@ -3,6 +3,7 @@ package wireproxy
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
|
||||||
|
@ -81,10 +82,11 @@ func StartWireguard(conf *DeviceConfig, logLevel int) (*VirtualTun, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &VirtualTun{
|
return &VirtualTun{
|
||||||
Tnet: tnet,
|
Tnet: tnet,
|
||||||
Dev: dev,
|
Dev: dev,
|
||||||
Conf: conf,
|
Conf: conf,
|
||||||
SystemDNS: len(setting.DNS) == 0,
|
SystemDNS: len(setting.DNS) == 0,
|
||||||
PingRecord: make(map[string]uint64),
|
PingRecord: make(map[string]uint64),
|
||||||
|
PingRecordLock: new(sync.Mutex),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue