diff --git a/api/api.go b/api/api.go index eb1c6a6..787f958 100644 --- a/api/api.go +++ b/api/api.go @@ -38,6 +38,7 @@ type SwitchOrgRequest struct { // PeerStatus represents the status of a peer connection type PeerStatus struct { SiteID int `json:"siteId"` + Name string `json:"name"` Connected bool `json:"connected"` RTT time.Duration `json:"rtt"` LastSeen time.Time `json:"lastSeen"` @@ -170,6 +171,26 @@ func (s *API) Stop() error { return nil } +func (s *API) AddPeerStatus(siteID int, siteName string, connected bool, rtt time.Duration, endpoint string, isRelay bool) { + s.statusMu.Lock() + defer s.statusMu.Unlock() + + status, exists := s.peerStatuses[siteID] + if !exists { + status = &PeerStatus{ + SiteID: siteID, + } + s.peerStatuses[siteID] = status + } + + status.Name = siteName + status.Connected = connected + status.RTT = rtt + status.LastSeen = time.Now() + status.Endpoint = endpoint + status.IsRelay = isRelay +} + // UpdatePeerStatus updates the status of a peer including endpoint and relay info func (s *API) UpdatePeerStatus(siteID int, connected bool, rtt time.Duration, endpoint string, isRelay bool) { s.statusMu.Lock() diff --git a/olm/olm.go b/olm/olm.go index cc75194..c911c3e 100644 --- a/olm/olm.go +++ b/olm/olm.go @@ -417,7 +417,7 @@ func StartTunnel(config TunnelConfig) { siteEndpoint = site.Endpoint } - apiServer.UpdatePeerStatus(site.SiteId, false, 0, siteEndpoint, false) + apiServer.AddPeerStatus(site.SiteId, site.Name, false, 0, siteEndpoint, false) if err := peerManager.AddPeer(site); err != nil { logger.Error("Failed to add peer: %v", err) diff --git a/peers/manager.go b/peers/manager.go index 310c99f..59af2ce 100644 --- a/peers/manager.go +++ b/peers/manager.go @@ -150,6 +150,8 @@ func (pm *PeerManager) AddPeer(siteConfig SiteConfig) error { pm.peers[siteConfig.SiteId] = siteConfig + pm.APIServer.AddPeerStatus(siteConfig.SiteId, siteConfig.Name, false, 0, siteConfig.Endpoint, false) + // Perform rapid initial holepunch test (outside of lock to avoid blocking) // This quickly determines if holepunch is viable and triggers relay if not go pm.performRapidInitialTest(siteConfig.SiteId, siteConfig.Endpoint) diff --git a/peers/types.go b/peers/types.go index b2867b3..dab49e1 100644 --- a/peers/types.go +++ b/peers/types.go @@ -9,6 +9,7 @@ type PeerAction struct { // UpdatePeerData represents the data needed to update a peer type SiteConfig struct { SiteId int `json:"siteId"` + Name string `json:"name,omitempty"` Endpoint string `json:"endpoint,omitempty"` RelayEndpoint string `json:"relayEndpoint,omitempty"` PublicKey string `json:"publicKey,omitempty"`