mirror of
https://github.com/fosrl/olm.git
synced 2026-03-02 00:36:44 +00:00
Fix concurrancy problem and add +1 back
This commit is contained in:
2
main.go
2
main.go
@@ -406,7 +406,7 @@ func main() {
|
|||||||
// take the first part of the allowedIp and the port from the endpoint and put them together
|
// take the first part of the allowedIp and the port from the endpoint and put them together
|
||||||
monitorAddress := strings.Split(site.ServerIP, "/")[0]
|
monitorAddress := strings.Split(site.ServerIP, "/")[0]
|
||||||
|
|
||||||
monitorPeer := fmt.Sprintf("%s:%d", monitorAddress, site.ServerPort)
|
monitorPeer := fmt.Sprintf("%s:%d", monitorAddress, site.ServerPort+1) // +1 for the monitor port
|
||||||
|
|
||||||
wgConfig := &peermonitor.WireGuardConfig{
|
wgConfig := &peermonitor.WireGuardConfig{
|
||||||
SiteID: site.SiteId,
|
SiteID: site.SiteId,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type Client struct {
|
|||||||
handlers map[string]MessageHandler
|
handlers map[string]MessageHandler
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
handlersMux sync.RWMutex
|
handlersMux sync.RWMutex
|
||||||
|
writeMux sync.Mutex
|
||||||
|
|
||||||
reconnectInterval time.Duration
|
reconnectInterval time.Duration
|
||||||
isConnected bool
|
isConnected bool
|
||||||
@@ -110,6 +111,8 @@ func (c *Client) SendMessage(messageType string, data interface{}) error {
|
|||||||
Data: data,
|
Data: data,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.writeMux.Lock()
|
||||||
|
defer c.writeMux.Unlock()
|
||||||
return c.conn.WriteJSON(msg)
|
return c.conn.WriteJSON(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,7 +337,10 @@ func (c *Client) pingMonitor() {
|
|||||||
case <-c.done:
|
case <-c.done:
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
if err := c.conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(10*time.Second)); err != nil {
|
c.writeMux.Lock()
|
||||||
|
err := c.conn.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(10*time.Second))
|
||||||
|
c.writeMux.Unlock()
|
||||||
|
if err != nil {
|
||||||
logger.Error("Ping failed: %v", err)
|
logger.Error("Ping failed: %v", err)
|
||||||
c.reconnect()
|
c.reconnect()
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user