mirror of
https://github.com/fosrl/olm.git
synced 2026-02-08 05:56:41 +00:00
Add site name
This commit is contained in:
21
api/api.go
21
api/api.go
@@ -38,6 +38,7 @@ type SwitchOrgRequest struct {
|
|||||||
// PeerStatus represents the status of a peer connection
|
// PeerStatus represents the status of a peer connection
|
||||||
type PeerStatus struct {
|
type PeerStatus struct {
|
||||||
SiteID int `json:"siteId"`
|
SiteID int `json:"siteId"`
|
||||||
|
Name string `json:"name"`
|
||||||
Connected bool `json:"connected"`
|
Connected bool `json:"connected"`
|
||||||
RTT time.Duration `json:"rtt"`
|
RTT time.Duration `json:"rtt"`
|
||||||
LastSeen time.Time `json:"lastSeen"`
|
LastSeen time.Time `json:"lastSeen"`
|
||||||
@@ -170,6 +171,26 @@ func (s *API) Stop() error {
|
|||||||
return nil
|
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
|
// 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) {
|
func (s *API) UpdatePeerStatus(siteID int, connected bool, rtt time.Duration, endpoint string, isRelay bool) {
|
||||||
s.statusMu.Lock()
|
s.statusMu.Lock()
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ func StartTunnel(config TunnelConfig) {
|
|||||||
siteEndpoint = site.Endpoint
|
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 {
|
if err := peerManager.AddPeer(site); err != nil {
|
||||||
logger.Error("Failed to add peer: %v", err)
|
logger.Error("Failed to add peer: %v", err)
|
||||||
|
|||||||
@@ -150,6 +150,8 @@ func (pm *PeerManager) AddPeer(siteConfig SiteConfig) error {
|
|||||||
|
|
||||||
pm.peers[siteConfig.SiteId] = siteConfig
|
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)
|
// Perform rapid initial holepunch test (outside of lock to avoid blocking)
|
||||||
// This quickly determines if holepunch is viable and triggers relay if not
|
// This quickly determines if holepunch is viable and triggers relay if not
|
||||||
go pm.performRapidInitialTest(siteConfig.SiteId, siteConfig.Endpoint)
|
go pm.performRapidInitialTest(siteConfig.SiteId, siteConfig.Endpoint)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ type PeerAction struct {
|
|||||||
// UpdatePeerData represents the data needed to update a peer
|
// UpdatePeerData represents the data needed to update a peer
|
||||||
type SiteConfig struct {
|
type SiteConfig struct {
|
||||||
SiteId int `json:"siteId"`
|
SiteId int `json:"siteId"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
Endpoint string `json:"endpoint,omitempty"`
|
Endpoint string `json:"endpoint,omitempty"`
|
||||||
RelayEndpoint string `json:"relayEndpoint,omitempty"`
|
RelayEndpoint string `json:"relayEndpoint,omitempty"`
|
||||||
PublicKey string `json:"publicKey,omitempty"`
|
PublicKey string `json:"publicKey,omitempty"`
|
||||||
|
|||||||
Reference in New Issue
Block a user