From 48310ef99c193b945492c639f7b07de068c60862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Wed, 19 Jun 2024 09:59:01 +0200 Subject: [PATCH] Fix engine test --- client/internal/engine_test.go | 23 +++++++++++++++-------- client/internal/peer/handshaker.go | 15 +++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/client/internal/engine_test.go b/client/internal/engine_test.go index f5a98cb7f..172216e73 100644 --- a/client/internal/engine_test.go +++ b/client/internal/engine_test.go @@ -35,6 +35,7 @@ import ( mgmtProto "github.com/netbirdio/netbird/management/proto" "github.com/netbirdio/netbird/management/server" "github.com/netbirdio/netbird/management/server/activity" + relayClient "github.com/netbirdio/netbird/relay/client" "github.com/netbirdio/netbird/route" signal "github.com/netbirdio/netbird/signal/client" "github.com/netbirdio/netbird/signal/proto" @@ -71,13 +72,15 @@ func TestEngine_SSH(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, &EngineConfig{ + relayMgr := relayClient.NewManager(ctx, "", key.PublicKey().String()) + engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, relayMgr, &EngineConfig{ WgIfaceName: "utun101", WgAddr: "100.64.0.1/24", WgPrivateKey: key, WgPort: 33100, ServerSSHAllowed: true, - }, MobileDependency{}, peer.NewRecorder("https://mgm")) + }, + MobileDependency{}, peer.NewRecorder("https://mgm")) engine.dnsServer = &dns.MockServer{ UpdateDNSServerFunc: func(serial uint64, update nbdns.Config) error { return nil }, @@ -206,7 +209,8 @@ func TestEngine_UpdateNetworkMap(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, &EngineConfig{ + relayMgr := relayClient.NewManager(ctx, "", key.PublicKey().String()) + engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, relayMgr, &EngineConfig{ WgIfaceName: "utun102", WgAddr: "100.64.0.1/24", WgPrivateKey: key, @@ -402,8 +406,8 @@ func TestEngine_Sync(t *testing.T) { } return nil } - - engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{SyncFunc: syncFunc}, &EngineConfig{ + relayMgr := relayClient.NewManager(ctx, "", key.PublicKey().String()) + engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{SyncFunc: syncFunc}, relayMgr, &EngineConfig{ WgIfaceName: "utun103", WgAddr: "100.64.0.1/24", WgPrivateKey: key, @@ -562,7 +566,8 @@ func TestEngine_UpdateNetworkMapWithRoutes(t *testing.T) { wgIfaceName := fmt.Sprintf("utun%d", 104+n) wgAddr := fmt.Sprintf("100.66.%d.1/24", n) - engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, &EngineConfig{ + relayMgr := relayClient.NewManager(ctx, "", key.PublicKey().String()) + engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, relayMgr, &EngineConfig{ WgIfaceName: wgIfaceName, WgAddr: wgAddr, WgPrivateKey: key, @@ -732,7 +737,8 @@ func TestEngine_UpdateNetworkMapWithDNSUpdate(t *testing.T) { wgIfaceName := fmt.Sprintf("utun%d", 104+n) wgAddr := fmt.Sprintf("100.66.%d.1/24", n) - engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, &EngineConfig{ + relayMgr := relayClient.NewManager(ctx, "", key.PublicKey().String()) + engine := NewEngine(ctx, cancel, &signal.MockClient{}, &mgmt.MockClient{}, relayMgr, &EngineConfig{ WgIfaceName: wgIfaceName, WgAddr: wgAddr, WgPrivateKey: key, @@ -1008,7 +1014,8 @@ func createEngine(ctx context.Context, cancel context.CancelFunc, setupKey strin WgPort: wgPort, } - e, err := NewEngine(ctx, cancel, signalClient, mgmtClient, conf, MobileDependency{}, peer.NewRecorder("https://mgm")), nil + relayMgr := relayClient.NewManager(ctx, "", key.PublicKey().String()) + e, err := NewEngine(ctx, cancel, signalClient, mgmtClient, relayMgr, conf, MobileDependency{}, peer.NewRecorder("https://mgm")), nil e.ctx = ctx return e, err } diff --git a/client/internal/peer/handshaker.go b/client/internal/peer/handshaker.go index 2bc42686f..797bbb82e 100644 --- a/client/internal/peer/handshaker.go +++ b/client/internal/peer/handshaker.go @@ -7,7 +7,6 @@ import ( "time" log "github.com/sirupsen/logrus" - "golang.zx2c4.com/wireguard/conn" "github.com/netbirdio/netbird/version" ) @@ -68,6 +67,8 @@ type Handshaker struct { remoteOfferAnswer *OfferAnswer remoteOfferAnswerCreated time.Time + + handshakeArgs HandshakeArgs } func NewHandshaker(ctx context.Context, config ConnConfig, signaler *Signaler) *Handshaker { @@ -84,6 +85,8 @@ func (h *Handshaker) Handshake(args HandshakeArgs) (*OfferAnswer, error) { h.mu.Lock() defer h.mu.Unlock() + h.handshakeArgs = args + cachedOfferAnswer, ok := h.cachedHandshake() if ok { return cachedOfferAnswer, nil @@ -150,20 +153,16 @@ func (h *Handshaker) sendOffer(args HandshakeArgs) error { } func (h *Handshaker) sendAnswer() error { - localUFrag, localPwd, err := conn.connectorICE.GetLocalUserCredentials() - if err != nil { - return err - } - log.Debugf("sending answer to %s", h.config.Key) answer := OfferAnswer{ - IceCredentials: IceCredentials{localUFrag, localPwd}, + IceCredentials: IceCredentials{h.handshakeArgs.IceUFrag, h.handshakeArgs.IcePwd}, WgListenPort: h.config.LocalWgPort, Version: version.NetbirdVersion(), RosenpassPubKey: h.config.RosenpassPubKey, RosenpassAddr: h.config.RosenpassAddr, + RelaySrvAddress: h.handshakeArgs.RelayAddr, } - err = h.signaler.SignalAnswer(answer, h.config.Key) + err := h.signaler.SignalAnswer(answer, h.config.Key) if err != nil { return err }