mirror of
https://github.com/fosrl/olm.git
synced 2026-08-13 05:24:11 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f54e27b22 |
+12
-27
@@ -810,14 +810,11 @@ func (pm *PeerManager) RemoveAlias(siteId int, aliasName string) error {
|
|||||||
newAliases = append(newAliases, a)
|
newAliases = append(newAliases, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
if aliasToRemove == nil {
|
if aliasToRemove != nil {
|
||||||
// Alias already gone (e.g. duplicate/stale remove message) - nothing to do
|
address := net.ParseIP(aliasToRemove.AliasAddress)
|
||||||
return nil
|
if address != nil {
|
||||||
}
|
pm.dnsProxy.RemoveDNSRecordForSite(aliasName, address, siteId)
|
||||||
|
}
|
||||||
address := net.ParseIP(aliasToRemove.AliasAddress)
|
|
||||||
if address != nil {
|
|
||||||
pm.dnsProxy.RemoveDNSRecordForSite(aliasName, address, siteId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peer.Aliases = newAliases
|
peer.Aliases = newAliases
|
||||||
@@ -902,14 +899,7 @@ endpoint=%s:%d`, util.FixKey(peer.PublicKey), formattedEndpoint, relayPort)
|
|||||||
// at the public endpoint (set synchronously in AddPeer), so this just settles the peer onto
|
// at the public endpoint (set synchronously in AddPeer), so this just settles the peer onto
|
||||||
// its steady-state connection within ~1-2 seconds.
|
// its steady-state connection within ~1-2 seconds.
|
||||||
func (pm *PeerManager) performRapidInitialTest(siteId int, endpoint string, localEndpoints []string) {
|
func (pm *PeerManager) performRapidInitialTest(siteId int, endpoint string, localEndpoints []string) {
|
||||||
// Snapshot the monitor once under lock and use only the local copy from here on -
|
if pm.peerMonitor == nil {
|
||||||
// pm.peerMonitor can be concurrently nil'd out by Close()/Stop() (e.g. the tunnel
|
|
||||||
// tears down right after a peer was added), and re-reading the field later in this
|
|
||||||
// goroutine would race with that.
|
|
||||||
pm.mu.RLock()
|
|
||||||
peerMonitor := pm.peerMonitor
|
|
||||||
pm.mu.RUnlock()
|
|
||||||
if peerMonitor == nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -921,14 +911,14 @@ func (pm *PeerManager) performRapidInitialTest(siteId int, endpoint string, loca
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
localWinner = peerMonitor.RapidTestLocalEndpoints(siteId, localEndpoints)
|
localWinner = pm.peerMonitor.RapidTestLocalEndpoints(siteId, localEndpoints)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
holepunchViable = peerMonitor.RapidTestPeer(siteId, endpoint)
|
holepunchViable = pm.peerMonitor.RapidTestPeer(siteId, endpoint)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@@ -942,7 +932,7 @@ func (pm *PeerManager) performRapidInitialTest(siteId int, endpoint string, loca
|
|||||||
if !holepunchViable {
|
if !holepunchViable {
|
||||||
// Holepunch failed rapid test, request relay immediately
|
// Holepunch failed rapid test, request relay immediately
|
||||||
logger.Info("Rapid test failed for site %d, requesting relay", siteId)
|
logger.Info("Rapid test failed for site %d, requesting relay", siteId)
|
||||||
if err := peerMonitor.RequestRelay(siteId); err != nil {
|
if err := pm.peerMonitor.RequestRelay(siteId); err != nil {
|
||||||
logger.Error("Failed to request relay for site %d: %v", siteId, err)
|
logger.Error("Failed to request relay for site %d: %v", siteId, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -969,14 +959,9 @@ func (pm *PeerManager) Stop() {
|
|||||||
// Close stops the peer monitor and cleans up resources
|
// Close stops the peer monitor and cleans up resources
|
||||||
func (pm *PeerManager) Close() {
|
func (pm *PeerManager) Close() {
|
||||||
pm.stopRouteOptimizer()
|
pm.stopRouteOptimizer()
|
||||||
|
if pm.peerMonitor != nil {
|
||||||
pm.mu.Lock()
|
pm.peerMonitor.Close()
|
||||||
peerMonitor := pm.peerMonitor
|
pm.peerMonitor = nil
|
||||||
pm.peerMonitor = nil
|
|
||||||
pm.mu.Unlock()
|
|
||||||
|
|
||||||
if peerMonitor != nil {
|
|
||||||
peerMonitor.Close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -225,10 +225,6 @@ func (c *Client) Connect() error {
|
|||||||
|
|
||||||
// Close closes the WebSocket connection gracefully
|
// Close closes the WebSocket connection gracefully
|
||||||
func (c *Client) Close() error {
|
func (c *Client) Close() error {
|
||||||
if c == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signal shutdown to all goroutines first
|
// Signal shutdown to all goroutines first
|
||||||
select {
|
select {
|
||||||
case <-c.done:
|
case <-c.done:
|
||||||
@@ -257,10 +253,6 @@ func (c *Client) Close() error {
|
|||||||
|
|
||||||
// Disconnect cleanly closes the websocket connection and suspends message intervals, but allows reconnecting later.
|
// Disconnect cleanly closes the websocket connection and suspends message intervals, but allows reconnecting later.
|
||||||
func (c *Client) Disconnect() error {
|
func (c *Client) Disconnect() error {
|
||||||
if c == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
c.isDisconnected = true
|
c.isDisconnected = true
|
||||||
c.setConnected(false)
|
c.setConnected(false)
|
||||||
|
|
||||||
@@ -283,9 +275,6 @@ func (c *Client) Disconnect() error {
|
|||||||
|
|
||||||
// SendMessage sends a message through the WebSocket connection
|
// SendMessage sends a message through the WebSocket connection
|
||||||
func (c *Client) SendMessage(messageType string, data interface{}) error {
|
func (c *Client) SendMessage(messageType string, data interface{}) error {
|
||||||
if c == nil {
|
|
||||||
return fmt.Errorf("client is nil")
|
|
||||||
}
|
|
||||||
if c.isDisconnected || c.conn == nil {
|
if c.isDisconnected || c.conn == nil {
|
||||||
return fmt.Errorf("not connected")
|
return fmt.Errorf("not connected")
|
||||||
}
|
}
|
||||||
@@ -306,10 +295,6 @@ func (c *Client) SendMessage(messageType string, data interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SendMessageInterval(messageType string, data interface{}, interval time.Duration, maxAttempts int) (stop func(), update func(newData interface{})) {
|
func (c *Client) SendMessageInterval(messageType string, data interface{}, interval time.Duration, maxAttempts int) (stop func(), update func(newData interface{})) {
|
||||||
if c == nil {
|
|
||||||
return func() {}, func(interface{}) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
stopChan := make(chan struct{})
|
stopChan := make(chan struct{})
|
||||||
updateChan := make(chan interface{})
|
updateChan := make(chan interface{})
|
||||||
var dataMux sync.Mutex
|
var dataMux sync.Mutex
|
||||||
@@ -794,10 +779,6 @@ func (c *Client) pingMonitor() {
|
|||||||
// This should be called after the client is registered and connected.
|
// This should be called after the client is registered and connected.
|
||||||
// It is safe to call multiple times - only the first call will start the monitor.
|
// It is safe to call multiple times - only the first call will start the monitor.
|
||||||
func (c *Client) StartPingMonitor() {
|
func (c *Client) StartPingMonitor() {
|
||||||
if c == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.pingStartedMux.Lock()
|
c.pingStartedMux.Lock()
|
||||||
defer c.pingStartedMux.Unlock()
|
defer c.pingStartedMux.Unlock()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user