mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 18:22:37 +02:00
Fix relay instance address indication
This commit is contained in:
parent
83b83ccfd2
commit
cb77ff4661
@ -111,6 +111,7 @@ type Client struct {
|
|||||||
readLoopMutex sync.Mutex
|
readLoopMutex sync.Mutex
|
||||||
wgReadLoop sync.WaitGroup
|
wgReadLoop sync.WaitGroup
|
||||||
instanceURL string
|
instanceURL string
|
||||||
|
muInstanceURL sync.Mutex
|
||||||
|
|
||||||
onDisconnectListener func()
|
onDisconnectListener func()
|
||||||
listenerMutex sync.Mutex
|
listenerMutex sync.Mutex
|
||||||
@ -190,8 +191,8 @@ func (c *Client) OpenConn(dstPeerID string) (net.Conn, error) {
|
|||||||
|
|
||||||
// ServerInstanceURL returns the address of the relay server. It could change after the close and reopen the connection.
|
// ServerInstanceURL returns the address of the relay server. It could change after the close and reopen the connection.
|
||||||
func (c *Client) ServerInstanceURL() (string, error) {
|
func (c *Client) ServerInstanceURL() (string, error) {
|
||||||
c.mu.Lock()
|
c.muInstanceURL.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.muInstanceURL.Unlock()
|
||||||
if c.instanceURL == "" {
|
if c.instanceURL == "" {
|
||||||
return "", fmt.Errorf("relay connection is not established")
|
return "", fmt.Errorf("relay connection is not established")
|
||||||
}
|
}
|
||||||
@ -272,7 +273,9 @@ func (c *Client) handShake() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
c.muInstanceURL.Lock()
|
||||||
c.instanceURL = ia
|
c.instanceURL = ia
|
||||||
|
c.muInstanceURL.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,6 +313,11 @@ func (c *Client) readLoop(relayConn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hc.Stop()
|
hc.Stop()
|
||||||
|
|
||||||
|
c.muInstanceURL.Lock()
|
||||||
|
c.instanceURL = ""
|
||||||
|
c.muInstanceURL.Unlock()
|
||||||
|
|
||||||
c.notifyDisconnected()
|
c.notifyDisconnected()
|
||||||
c.wgReadLoop.Done()
|
c.wgReadLoop.Done()
|
||||||
_ = c.close(false)
|
_ = c.close(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user