mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-20 21:08:45 +01:00
Configurable relay address with env variable
This commit is contained in:
parent
64f949abbb
commit
a7760bf0a7
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
@ -245,10 +246,13 @@ func (c *ConnectClient) run(
|
|||||||
|
|
||||||
c.statusRecorder.MarkSignalConnected()
|
c.statusRecorder.MarkSignalConnected()
|
||||||
|
|
||||||
relayManager := relayClient.NewManager(engineCtx, loginResp.GetWiretrusteeConfig().GetRelayAddress(), myPrivateKey.PublicKey().String())
|
relayAddress := relayAddress(loginResp)
|
||||||
if err = relayManager.Serve(); err != nil {
|
relayManager := relayClient.NewManager(engineCtx, relayAddress, myPrivateKey.PublicKey().String())
|
||||||
log.Error(err)
|
if relayAddress != "" {
|
||||||
return wrapErr(err)
|
if err = relayManager.Serve(); err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return wrapErr(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
peerConfig := loginResp.GetPeerConfig()
|
peerConfig := loginResp.GetPeerConfig()
|
||||||
@ -304,6 +308,17 @@ func (c *ConnectClient) run(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func relayAddress(resp *mgmProto.LoginResponse) string {
|
||||||
|
if envRelay := os.Getenv("NB_RELAY_ADDRESS"); envRelay != "" {
|
||||||
|
return envRelay
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.GetWiretrusteeConfig().GetRelayAddress() != "" {
|
||||||
|
return resp.GetWiretrusteeConfig().GetRelayAddress()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ConnectClient) Engine() *Engine {
|
func (c *ConnectClient) Engine() *Engine {
|
||||||
var e *Engine
|
var e *Engine
|
||||||
c.engineMutex.Lock()
|
c.engineMutex.Lock()
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
relayCleanupInterval = 60 * time.Second
|
relayCleanupInterval = 60 * time.Second
|
||||||
|
|
||||||
|
errRelayClientNotConnected = fmt.Errorf("relay client not connected")
|
||||||
)
|
)
|
||||||
|
|
||||||
// RelayTrack hold the relay clients for the foregin relay servers.
|
// RelayTrack hold the relay clients for the foregin relay servers.
|
||||||
@ -80,7 +82,7 @@ func (m *Manager) Serve() error {
|
|||||||
// connection to the relay server.
|
// connection to the relay server.
|
||||||
func (m *Manager) OpenConn(serverAddress, peerKey string) (net.Conn, error) {
|
func (m *Manager) OpenConn(serverAddress, peerKey string) (net.Conn, error) {
|
||||||
if m.relayClient == nil {
|
if m.relayClient == nil {
|
||||||
return nil, fmt.Errorf("relay client not connected")
|
return nil, errRelayClientNotConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
foreign, err := m.isForeignServer(serverAddress)
|
foreign, err := m.isForeignServer(serverAddress)
|
||||||
@ -101,7 +103,7 @@ func (m *Manager) OpenConn(serverAddress, peerKey string) (net.Conn, error) {
|
|||||||
// This address will be sent to the target peer to choose the common relay server for the communication.
|
// This address will be sent to the target peer to choose the common relay server for the communication.
|
||||||
func (m *Manager) RelayAddress() (net.Addr, error) {
|
func (m *Manager) RelayAddress() (net.Addr, error) {
|
||||||
if m.relayClient == nil {
|
if m.relayClient == nil {
|
||||||
return nil, fmt.Errorf("relay client not connected")
|
return nil, errRelayClientNotConnected
|
||||||
}
|
}
|
||||||
return m.relayClient.RelayRemoteAddress()
|
return m.relayClient.RelayRemoteAddress()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user