From 46dc47cffb18a29d94b54e1f3b2d1bcdd61cdee5 Mon Sep 17 00:00:00 2001 From: Alex Yu Date: Thu, 23 May 2019 09:54:46 +0300 Subject: [PATCH] Manager.Observe eliminated. All tests passed --- pkg/router/router.go | 2 -- pkg/setup/node.go | 5 ++--- pkg/setup/node_test.go | 5 ++--- pkg/transport/manager.go | 16 ---------------- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/pkg/router/router.go b/pkg/router/router.go index e753531b8..0c2b2d987 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -78,8 +78,6 @@ func New(config *Config) *Router { // Serve starts transport listening loop. func (r *Router) Serve(ctx context.Context) error { - // acceptCh, dialCh := r.tm.Observe() - go func() { for tr := range r.tm.AcceptedTrChan { go func(t transport.Transport) { diff --git a/pkg/setup/node.go b/pkg/setup/node.go index eac046e48..65bac0926 100644 --- a/pkg/setup/node.go +++ b/pkg/setup/node.go @@ -90,9 +90,8 @@ func (sn *Node) Serve(ctx context.Context) error { sn.Logger.Info("Connected to messaging servers") } - acceptCh, dialCh := sn.tm.Observe() go func() { - for tr := range acceptCh { + for tr := range sn.tm.AcceptedTrChan { go func(t transport.Transport) { for { if err := sn.serveTransport(t); err != nil { @@ -105,7 +104,7 @@ func (sn *Node) Serve(ctx context.Context) error { }() go func() { - for range dialCh { + for range sn.tm.DialedTrChan { } }() diff --git a/pkg/setup/node_test.go b/pkg/setup/node_test.go index 711472575..cf0062082 100644 --- a/pkg/setup/node_test.go +++ b/pkg/setup/node_test.go @@ -273,15 +273,14 @@ func newMockNode(tm *transport.Manager) *mockNode { } func (n *mockNode) serve() error { - acceptCh, dialCh := n.tm.Observe() go func() { - for tr := range dialCh { + for tr := range n.tm.DialedTrChan { go func(t transport.Transport) { n.serveTransport(t) }(tr) // nolint: errcheck } }() go func() { - for tr := range acceptCh { + for tr := range n.tm.AcceptedTrChan { go func(t transport.Transport) { n.serveTransport(t) }(tr) // nolint: errcheck } }() diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index 1270ca7e2..dc132df3d 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -68,22 +68,6 @@ func NewManager(config *ManagerConfig, factories ...Factory) (*Manager, error) { // Observe returns channel for notifications about new Transport // registration. Only single observer is supported. func (tm *Manager) Observe() (accept <-chan *ManagedTransport, dial <-chan *ManagedTransport) { - // dialCh := make(chan *ManagedTransport) - // acceptCh := make(chan *ManagedTransport) - // go func() { - // for { - // select { - // case <-tm.doneChan: - // // close(dialCh) - // // close(acceptCh) - // return - // case tr := <-tm.acceptedTrChan: - // acceptCh <- tr - // case tr := <-tm.dialedTrChan: - // dialCh <- tr - // } - // } - // }() return tm.AcceptedTrChan, tm.DialedTrChan }