mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +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
|
||||
pingTimeout time.Duration
|
||||
doHolepunch bool
|
||||
connected bool
|
||||
)
|
||||
|
||||
stopHolepunch = make(chan struct{})
|
||||
@@ -433,18 +434,15 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
||||
go keepSendingUDPHolePunch(holePunchData.Endpoint, id, sourcePort)
|
||||
})
|
||||
|
||||
connectTimes := 0
|
||||
// Register handlers for different message types
|
||||
olm.RegisterHandler("olm/wg/connect", func(msg websocket.WSMessage) {
|
||||
logger.Debug("Received message: %v", msg.Data)
|
||||
|
||||
if connectTimes > 0 {
|
||||
if connected {
|
||||
logger.Info("Already connected. Ignoring new connection request.")
|
||||
return
|
||||
}
|
||||
|
||||
connectTimes++
|
||||
|
||||
if stopRegister != nil {
|
||||
stopRegister()
|
||||
stopRegister = nil
|
||||
@@ -606,6 +604,8 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
||||
|
||||
peerMonitor.Start()
|
||||
|
||||
connected = true
|
||||
|
||||
logger.Info("WireGuard device created.")
|
||||
})
|
||||
|
||||
@@ -828,6 +828,17 @@ func runOlmMainWithArgs(ctx context.Context, args []string) {
|
||||
})
|
||||
|
||||
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()
|
||||
|
||||
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)
|
||||
|
||||
if httpServer != nil {
|
||||
httpServer.SetConnectionStatus(true)
|
||||
}
|
||||
|
||||
logger.Info("Sent registration message")
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user