Skip to content

Commit

Permalink
Merge pull request #145 from telekom-mms/feature/signal-reconnect-via…
Browse files Browse the repository at this point in the history
…-dbus-api

Signal reconnect events via D-Bus API
  • Loading branch information
hwipl authored Feb 4, 2025
2 parents 611c956 + e8da97a commit 0258b0b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,45 @@ func (d *Daemon) updateVPNConfigDown() {
log.Info("Daemon unconfigured VPN connection")
}

// handleVPNAttemptReconnect handles a "attempt reconnect" event received from vpncscript.
func (d *Daemon) handleVPNAttemptReconnect() {
// check if vpn is flagged as running
if !d.status.OCRunning.Running() {
log.WithField("error", "vpn not running").
Error("Daemon got invalid attempt reconnect event")
return
}

// check if we are connected or connecting
if d.status.ConnectionState != vpnstatus.ConnectionStateConnected &&
d.status.ConnectionState != vpnstatus.ConnectionStateConnecting {
log.WithField("error", "vpn not connected and not connecting").
Error("Daemon got invalid attempt reconnect event")
return
}

d.setStatusConnectionState(vpnstatus.ConnectionStateConnecting)
}

// handleVPNReconnect handles a "reconnect" event received from vpncscript.
func (d *Daemon) handleVPNReconnect() {
// check if vpn is flagged as running
if !d.status.OCRunning.Running() {
log.WithField("error", "vpn not running").
Error("Daemon got invalid reconnect event")
return
}

// check if we are connecting
if d.status.ConnectionState != vpnstatus.ConnectionStateConnecting {
log.WithField("error", "vpn not connecting").
Error("Daemon got invalid reconnect event")
return
}

d.setStatusConnectionState(vpnstatus.ConnectionStateConnected)
}

// updateVPNConfig updates the VPN config with config update in client request.
func (d *Daemon) updateVPNConfig(request *api.Request) {
// parse config
Expand All @@ -466,6 +505,10 @@ func (d *Daemon) updateVPNConfig(request *api.Request) {
d.updateVPNConfigUp(configUpdate.Config)
case "disconnect":
d.updateVPNConfigDown()
case "attempt-reconnect":
d.handleVPNAttemptReconnect()
case "reconnect":
d.handleVPNReconnect()
}
}

Expand Down

0 comments on commit 0258b0b

Please sign in to comment.