Skip to content

Commit

Permalink
Merge pull request #83 from telekom-mms/feature/update-dbus-and-statu…
Browse files Browse the repository at this point in the history
…s-defaults

Feature/update dbus and status defaults
  • Loading branch information
hwipl authored May 13, 2024
2 parents 9198016 + f7547c4 commit cef4fde
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 2 additions & 0 deletions internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,10 @@ func (d *Daemon) Start() error {
}

// set initial status
d.setStatusTrustedNetwork(false)
d.setStatusConnectionState(vpnstatus.ConnectionStateDisconnected)
d.setStatusServers(d.profile.GetVPNServerHostNames())
d.setStatusConnectedAt(0)

go d.start()
return nil
Expand Down
33 changes: 15 additions & 18 deletions internal/dbusapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,22 @@ func (s *Service) start() {
defer close(s.closed)
defer func() { _ = s.conn.Close() }()

// helper for setting initial property values
setInitialProps := func() {
s.props.SetMust(Interface, PropertyTrustedNetwork, TrustedNetworkUnknown)
s.props.SetMust(Interface, PropertyConnectionState, ConnectionStateUnknown)
s.props.SetMust(Interface, PropertyIP, IPInvalid)
s.props.SetMust(Interface, PropertyDevice, DeviceInvalid)
s.props.SetMust(Interface, PropertyServer, ServerInvalid)
s.props.SetMust(Interface, PropertyConnectedAt, ConnectedAtInvalid)
s.props.SetMust(Interface, PropertyServers, ServersInvalid)
s.props.SetMust(Interface, PropertyOCRunning, OCRunningUnknown)
s.props.SetMust(Interface, PropertyVPNConfig, VPNConfigInvalid)
}

// set properties values to emit properties changed signal and make
// sure existing clients get updated values after restart
s.props.SetMust(Interface, PropertyTrustedNetwork, TrustedNetworkNotTrusted)
s.props.SetMust(Interface, PropertyConnectionState, ConnectionStateDisconnected)
s.props.SetMust(Interface, PropertyIP, IPInvalid)
s.props.SetMust(Interface, PropertyDevice, DeviceInvalid)
s.props.SetMust(Interface, PropertyServer, ServerInvalid)
s.props.SetMust(Interface, PropertyConnectedAt, ConnectedAtInvalid)
s.props.SetMust(Interface, PropertyServers, ServersInvalid)
s.props.SetMust(Interface, PropertyOCRunning, OCRunningNotRunning)
s.props.SetMust(Interface, PropertyVPNConfig, VPNConfigInvalid)
setInitialProps()

// main loop
for {
Expand All @@ -244,15 +249,7 @@ func (s *Service) start() {
log.Debug("D-Bus service stopping")
// set properties values to unknown/invalid to emit
// properties changed signal and inform clients
s.props.SetMust(Interface, PropertyTrustedNetwork, TrustedNetworkUnknown)
s.props.SetMust(Interface, PropertyConnectionState, ConnectionStateUnknown)
s.props.SetMust(Interface, PropertyIP, IPInvalid)
s.props.SetMust(Interface, PropertyDevice, DeviceInvalid)
s.props.SetMust(Interface, PropertyServer, ServerInvalid)
s.props.SetMust(Interface, PropertyConnectedAt, ConnectedAtInvalid)
s.props.SetMust(Interface, PropertyServers, ServersInvalid)
s.props.SetMust(Interface, PropertyOCRunning, OCRunningUnknown)
s.props.SetMust(Interface, PropertyVPNConfig, VPNConfigInvalid)
setInitialProps()
return
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/vpnstatus/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@ func NewFromJSON(b []byte) (*Status, error) {

// New returns a new Status.
func New() *Status {
return &Status{}
return &Status{
ConnectedAt: -1,
}
}

0 comments on commit cef4fde

Please sign in to comment.