diff --git a/pkg/node/node.go b/pkg/node/node.go index a6319810c4..1d5066b2b2 100644 --- a/pkg/node/node.go +++ b/pkg/node/node.go @@ -140,11 +140,12 @@ func NewNode(config *Config, masterLogger *logging.MasterLogger) (*Node, error) LogStore: logStore, DefaultNodes: config.TrustedNodes, } - node.tm, err = transport.NewManager(tmConfig, config.Routing.SetupNodes, node.messenger) + node.tm, err = transport.NewManager(tmConfig, node.messenger) if err != nil { return nil, fmt.Errorf("transport manager: %s", err) } node.tm.Logger = node.Logger.PackageLogger("trmanager") + node.tm.SetSetupNodes(config.Routing.SetupNodes) node.rt, err = config.RoutingTable() if err != nil { diff --git a/pkg/node/node_test.go b/pkg/node/node_test.go index 69d05303f6..59768e3e52 100644 --- a/pkg/node/node_test.go +++ b/pkg/node/node_test.go @@ -92,7 +92,7 @@ func TestNodeStartClose(t *testing.T) { var err error tmConf := &transport.ManagerConfig{PubKey: cipher.PubKey{}, DiscoveryClient: transport.NewDiscoveryMock()} - node.tm, err = transport.NewManager(tmConf, nil, node.messenger) + node.tm, err = transport.NewManager(tmConf, node.messenger) require.NoError(t, err) errCh := make(chan error) diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index fb4baa3729..0fa8baabc4 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -55,13 +55,13 @@ func TestRouterForwarding(t *testing.T) { f3.SetType("mock2") f4.SetType("mock2") - m1, err := transport.NewManager(c1, nil, f1) + m1, err := transport.NewManager(c1, f1) require.NoError(t, err) - m2, err := transport.NewManager(c2, nil, f2, f3) + m2, err := transport.NewManager(c2, f2, f3) require.NoError(t, err) - m3, err := transport.NewManager(c3, nil, f4) + m3, err := transport.NewManager(c3, f4) require.NoError(t, err) rt := routing.InMemoryRoutingTable() @@ -116,7 +116,7 @@ func TestRouterAppInit(t *testing.T) { pk1, sk1 := cipher.GenerateKeyPair() c1 := &transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore} - m1, err := transport.NewManager(c1, nil) + m1, err := transport.NewManager(c1) require.NoError(t, err) conf := &Config{ @@ -154,10 +154,10 @@ func TestRouterApp(t *testing.T) { c2 := &transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore} f1, f2 := transport.NewMockFactoryPair(pk1, pk2) - m1, err := transport.NewManager(c1, nil, f1) + m1, err := transport.NewManager(c1, f1) require.NoError(t, err) - m2, err := transport.NewManager(c2, nil, f2) + m2, err := transport.NewManager(c2, f2) require.NoError(t, err) go m2.Serve(context.TODO()) // nolint @@ -228,7 +228,7 @@ func TestRouterLocalApp(t *testing.T) { logStore := transport.InMemoryTransportLogStore() pk, sk := cipher.GenerateKeyPair() - m, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk, SecKey: sk, DiscoveryClient: client, LogStore: logStore}, nil) + m, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk, SecKey: sk, DiscoveryClient: client, LogStore: logStore}) require.NoError(t, err) conf := &Config{ @@ -285,10 +285,10 @@ func TestRouterSetup(t *testing.T) { c2 := &transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore} f1, f2 := transport.NewMockFactoryPair(pk1, pk2) - m1, err := transport.NewManager(c1, nil, f1) + m1, err := transport.NewManager(c1, f1) require.NoError(t, err) - m2, err := transport.NewManager(c2, nil, f2) + m2, err := transport.NewManager(c2, f2) require.NoError(t, err) rt := routing.InMemoryRoutingTable() @@ -433,10 +433,10 @@ func TestRouterSetupLoop(t *testing.T) { f1.SetType(dmsg.Type) f2.SetType(dmsg.Type) - m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, nil, f1) + m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, f1) require.NoError(t, err) - m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, nil, f2) + m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, f2) require.NoError(t, err) go m2.Serve(context.TODO()) // nolint: errcheck @@ -538,10 +538,10 @@ func TestRouterCloseLoop(t *testing.T) { f1, f2 := transport.NewMockFactoryPair(pk1, pk2) f1.SetType(dmsg.Type) - m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, nil, f1) + m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, f1) require.NoError(t, err) - m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, nil, f2) + m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, f2) require.NoError(t, err) go m2.Serve(context.TODO()) // nolint: errcheck @@ -632,10 +632,10 @@ func TestRouterCloseLoopOnAppClose(t *testing.T) { f1, f2 := transport.NewMockFactoryPair(pk1, pk2) f1.SetType(dmsg.Type) - m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, nil, f1) + m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, f1) require.NoError(t, err) - m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, nil, f2) + m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, f2) require.NoError(t, err) go m2.Serve(context.TODO()) // nolint: errcheck @@ -716,7 +716,7 @@ func TestRouterRouteExpiration(t *testing.T) { logStore := transport.InMemoryTransportLogStore() pk, sk := cipher.GenerateKeyPair() - m, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk, SecKey: sk, DiscoveryClient: client, LogStore: logStore}, nil) + m, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk, SecKey: sk, DiscoveryClient: client, LogStore: logStore}) require.NoError(t, err) rt := routing.InMemoryRoutingTable() diff --git a/pkg/transport/handshake_test.go b/pkg/transport/handshake_test.go index 4c8ebf6482..2d2cf6f000 100644 --- a/pkg/transport/handshake_test.go +++ b/pkg/transport/handshake_test.go @@ -35,8 +35,8 @@ func newHsMockEnv() *hsMockEnv { tr1 := NewMockTransport(in, pk1, pk2) tr2 := NewMockTransport(out, pk2, pk1) - m1, err1 := NewManager(&ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client}, nil) - m2, err2 := NewManager(&ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client}, nil) + m1, err1 := NewManager(&ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client}) + m2, err2 := NewManager(&ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client}) return &hsMockEnv{ client: client, diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index 09114d32c9..a40dbb37bb 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -43,7 +43,7 @@ type Manager struct { // NewManager creates a Manager with the provided configuration and transport factories. // 'factories' should be ordered by preference. -func NewManager(config *ManagerConfig, setupNodes []cipher.PubKey, factories ...Factory) (*Manager, error) { +func NewManager(config *ManagerConfig, factories ...Factory) (*Manager, error) { entries, _ := config.DiscoveryClient.GetTransportsByEdge(context.Background(), config.PubKey) // nolint mEntries := make(map[Entry]struct{}) @@ -64,10 +64,25 @@ func NewManager(config *ManagerConfig, setupNodes []cipher.PubKey, factories ... entries: mEntries, TrChan: make(chan *ManagedTransport, 9), // TODO: eliminate or justify buffering here doneChan: make(chan struct{}), - setupNodes: setupNodes, }, nil } +// SetupNodes returns setup node list contained within the TransportManager. +func (tm *Manager) SetupNodes() []cipher.PubKey { + tm.mu.RLock() + defer tm.mu.RUnlock() + + return tm.setupNodes +} + +// SetSetupNodes sets setup node list contained within the TransportManager. +func (tm *Manager) SetSetupNodes(nodes []cipher.PubKey) { + tm.mu.Lock() + defer tm.mu.Unlock() + + tm.setupNodes = nodes +} + // Factories returns all the factory types contained within the TransportManager. func (tm *Manager) Factories() []string { fTypes, i := make([]string, len(tm.factories)), 0 diff --git a/pkg/transport/manager_test.go b/pkg/transport/manager_test.go index 85a0a07c4f..4f0b30f729 100644 --- a/pkg/transport/manager_test.go +++ b/pkg/transport/manager_test.go @@ -43,7 +43,7 @@ func TestTransportManager(t *testing.T) { c2 := &ManagerConfig{pk2, sk2, client, logStore, nil} f1, f2 := NewMockFactoryPair(pk1, pk2) - m1, err := NewManager(c1, nil, f1) + m1, err := NewManager(c1, f1) require.NoError(t, err) assert.Equal(t, []string{"mock"}, m1.Factories()) @@ -53,7 +53,7 @@ func TestTransportManager(t *testing.T) { errCh <- m1.Serve(context.TODO()) }() - m2, err := NewManager(c2, nil, f2) + m2, err := NewManager(c2, f2) require.NoError(t, err) var mu sync.Mutex @@ -138,7 +138,7 @@ func TestTransportManagerReEstablishTransports(t *testing.T) { c2 := &ManagerConfig{pk2, sk2, client, logStore, nil} f1, f2 := NewMockFactoryPair(pk1, pk2) - m1, err := NewManager(c1, nil, f1) + m1, err := NewManager(c1, f1) require.NoError(t, err) assert.Equal(t, []string{"mock"}, m1.Factories()) @@ -147,7 +147,7 @@ func TestTransportManagerReEstablishTransports(t *testing.T) { m1errCh := make(chan error, 1) go func() { m1errCh <- m1.Serve(context.TODO()) }() - m2, err := NewManager(c2, nil, f2) + m2, err := NewManager(c2, f2) require.NoError(t, err) tr2, err := m2.CreateTransport(context.TODO(), pk1, "mock", true) @@ -167,7 +167,7 @@ func TestTransportManagerReEstablishTransports(t *testing.T) { require.NoError(t, err) assert.False(t, dEntry2.IsUp) - m2, err = NewManager(c2, nil, f2) + m2, err = NewManager(c2, f2) require.NoError(t, err) m2.reconnectTransports(context.TODO()) @@ -200,7 +200,7 @@ func TestTransportManagerLogs(t *testing.T) { c2 := &ManagerConfig{pk2, sk2, client, logStore2, nil} f1, f2 := NewMockFactoryPair(pk1, pk2) - m1, err := NewManager(c1, nil, f1) + m1, err := NewManager(c1, f1) require.NoError(t, err) assert.Equal(t, []string{"mock"}, m1.Factories()) @@ -210,7 +210,7 @@ func TestTransportManagerLogs(t *testing.T) { errCh <- m1.Serve(context.TODO()) }() - m2, err := NewManager(c2, nil, f2) + m2, err := NewManager(c2, f2) require.NoError(t, err) tr2, err := m2.CreateTransport(context.TODO(), pk1, "mock", true) diff --git a/pkg/transport/mock.go b/pkg/transport/mock.go index 60b32d19eb..f612a8c635 100644 --- a/pkg/transport/mock.go +++ b/pkg/transport/mock.go @@ -172,10 +172,10 @@ func MockTransportManagersPair() (pk1, pk2 cipher.PubKey, m1, m2 *Manager, errCh f1, f2 := NewMockFactoryPair(pk1, pk2) - if m1, err = NewManager(c1, nil, f1); err != nil { + if m1, err = NewManager(c1, f1); err != nil { return } - if m2, err = NewManager(c2, nil, f2); err != nil { + if m2, err = NewManager(c2, f2); err != nil { return }