From 99328ee76f0d3384d7926c4a3fdb7e48fe5bf8ee Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 3 Nov 2025 15:16:12 -0800 Subject: [PATCH] Add registered to api Former-commit-id: 9c496f7ca71966ed5de8fa15c2a59d9705cecb7d --- api/api.go | 10 ++++++++++ olm/olm.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/api/api.go b/api/api.go index 050902c..44db521 100644 --- a/api/api.go +++ b/api/api.go @@ -26,12 +26,14 @@ type PeerStatus struct { LastSeen time.Time `json:"lastSeen"` Endpoint string `json:"endpoint,omitempty"` IsRelay bool `json:"isRelay"` + PeerIP string `json:"peerAddress,omitempty"` } // StatusResponse is returned by the status endpoint type StatusResponse struct { Status string `json:"status"` Connected bool `json:"connected"` + Registered bool `json:"registered,omitempty"` TunnelIP string `json:"tunnelIP,omitempty"` Version string `json:"version,omitempty"` PeerStatuses map[int]*PeerStatus `json:"peers,omitempty"` @@ -49,6 +51,7 @@ type API struct { peerStatuses map[int]*PeerStatus connectedAt time.Time isConnected bool + isRegistered bool tunnelIP string version string } @@ -176,6 +179,12 @@ func (s *API) SetConnectionStatus(isConnected bool) { } } +func (s *API) SetRegistered(registered bool) { + s.statusMu.Lock() + defer s.statusMu.Unlock() + s.isRegistered = registered +} + // SetTunnelIP sets the tunnel IP address func (s *API) SetTunnelIP(tunnelIP string) { s.statusMu.Lock() @@ -250,6 +259,7 @@ func (s *API) handleStatus(w http.ResponseWriter, r *http.Request) { resp := StatusResponse{ Connected: s.isConnected, + Registered: s.isRegistered, TunnelIP: s.tunnelIP, Version: s.version, PeerStatuses: s.peerStatuses, diff --git a/olm/olm.go b/olm/olm.go index 3942199..4168ab3 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -405,6 +405,10 @@ func Run(ctx context.Context, config Config) { peerMonitor.Start() + if apiServer != nil { + apiServer.SetRegistered(true) + } + connected = true logger.Info("WireGuard device created.")