mirror of
https://github.com/fosrl/olm.git
synced 2026-03-04 09:46:46 +00:00
Dont kick off the process again on the ws
This commit is contained in:
23
main.go
23
main.go
@@ -180,6 +180,7 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
|||||||
pingInterval time.Duration
|
pingInterval time.Duration
|
||||||
pingTimeout time.Duration
|
pingTimeout time.Duration
|
||||||
doHolepunch bool
|
doHolepunch bool
|
||||||
|
connected bool
|
||||||
)
|
)
|
||||||
|
|
||||||
stopHolepunch = make(chan struct{})
|
stopHolepunch = make(chan struct{})
|
||||||
@@ -433,18 +434,15 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
|||||||
go keepSendingUDPHolePunch(holePunchData.Endpoint, id, sourcePort)
|
go keepSendingUDPHolePunch(holePunchData.Endpoint, id, sourcePort)
|
||||||
})
|
})
|
||||||
|
|
||||||
connectTimes := 0
|
|
||||||
// Register handlers for different message types
|
// Register handlers for different message types
|
||||||
olm.RegisterHandler("olm/wg/connect", func(msg websocket.WSMessage) {
|
olm.RegisterHandler("olm/wg/connect", func(msg websocket.WSMessage) {
|
||||||
logger.Debug("Received message: %v", msg.Data)
|
logger.Debug("Received message: %v", msg.Data)
|
||||||
|
|
||||||
if connectTimes > 0 {
|
if connected {
|
||||||
logger.Info("Already connected. Ignoring new connection request.")
|
logger.Info("Already connected. Ignoring new connection request.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
connectTimes++
|
|
||||||
|
|
||||||
if stopRegister != nil {
|
if stopRegister != nil {
|
||||||
stopRegister()
|
stopRegister()
|
||||||
stopRegister = nil
|
stopRegister = nil
|
||||||
@@ -606,6 +604,8 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
|||||||
|
|
||||||
peerMonitor.Start()
|
peerMonitor.Start()
|
||||||
|
|
||||||
|
connected = true
|
||||||
|
|
||||||
logger.Info("WireGuard device created.")
|
logger.Info("WireGuard device created.")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -828,6 +828,17 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
olm.OnConnect(func() error {
|
olm.OnConnect(func() error {
|
||||||
|
logger.Info("Websocket Connected")
|
||||||
|
|
||||||
|
if httpServer != nil {
|
||||||
|
httpServer.SetConnectionStatus(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if connected {
|
||||||
|
logger.Debug("Already connected, skipping registration")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
publicKey := privateKey.PublicKey()
|
publicKey := privateKey.PublicKey()
|
||||||
|
|
||||||
logger.Debug("Sending registration message to server with public key: %s and relay: %v", publicKey, !doHolepunch)
|
logger.Debug("Sending registration message to server with public key: %s and relay: %v", publicKey, !doHolepunch)
|
||||||
@@ -839,10 +850,6 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
|||||||
|
|
||||||
go keepSendingPing(olm)
|
go keepSendingPing(olm)
|
||||||
|
|
||||||
if httpServer != nil {
|
|
||||||
httpServer.SetConnectionStatus(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Info("Sent registration message")
|
logger.Info("Sent registration message")
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user