mirror of
https://github.com/fosrl/olm.git
synced 2026-02-23 05:16:45 +00:00
Add registered to api
This commit is contained in:
10
api/api.go
10
api/api.go
@@ -26,12 +26,14 @@ type PeerStatus struct {
|
|||||||
LastSeen time.Time `json:"lastSeen"`
|
LastSeen time.Time `json:"lastSeen"`
|
||||||
Endpoint string `json:"endpoint,omitempty"`
|
Endpoint string `json:"endpoint,omitempty"`
|
||||||
IsRelay bool `json:"isRelay"`
|
IsRelay bool `json:"isRelay"`
|
||||||
|
PeerIP string `json:"peerAddress,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusResponse is returned by the status endpoint
|
// StatusResponse is returned by the status endpoint
|
||||||
type StatusResponse struct {
|
type StatusResponse struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Connected bool `json:"connected"`
|
Connected bool `json:"connected"`
|
||||||
|
Registered bool `json:"registered,omitempty"`
|
||||||
TunnelIP string `json:"tunnelIP,omitempty"`
|
TunnelIP string `json:"tunnelIP,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
PeerStatuses map[int]*PeerStatus `json:"peers,omitempty"`
|
PeerStatuses map[int]*PeerStatus `json:"peers,omitempty"`
|
||||||
@@ -49,6 +51,7 @@ type API struct {
|
|||||||
peerStatuses map[int]*PeerStatus
|
peerStatuses map[int]*PeerStatus
|
||||||
connectedAt time.Time
|
connectedAt time.Time
|
||||||
isConnected bool
|
isConnected bool
|
||||||
|
isRegistered bool
|
||||||
tunnelIP string
|
tunnelIP string
|
||||||
version 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
|
// SetTunnelIP sets the tunnel IP address
|
||||||
func (s *API) SetTunnelIP(tunnelIP string) {
|
func (s *API) SetTunnelIP(tunnelIP string) {
|
||||||
s.statusMu.Lock()
|
s.statusMu.Lock()
|
||||||
@@ -250,6 +259,7 @@ func (s *API) handleStatus(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
resp := StatusResponse{
|
resp := StatusResponse{
|
||||||
Connected: s.isConnected,
|
Connected: s.isConnected,
|
||||||
|
Registered: s.isRegistered,
|
||||||
TunnelIP: s.tunnelIP,
|
TunnelIP: s.tunnelIP,
|
||||||
Version: s.version,
|
Version: s.version,
|
||||||
PeerStatuses: s.peerStatuses,
|
PeerStatuses: s.peerStatuses,
|
||||||
|
|||||||
@@ -405,6 +405,10 @@ func Run(ctx context.Context, config Config) {
|
|||||||
|
|
||||||
peerMonitor.Start()
|
peerMonitor.Start()
|
||||||
|
|
||||||
|
if apiServer != nil {
|
||||||
|
apiServer.SetRegistered(true)
|
||||||
|
}
|
||||||
|
|
||||||
connected = true
|
connected = true
|
||||||
|
|
||||||
logger.Info("WireGuard device created.")
|
logger.Info("WireGuard device created.")
|
||||||
|
|||||||
Reference in New Issue
Block a user