Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update dbus and status defaults #83

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}
}
Loading