From d51b7bff5b13284255163cd4cbc0b2f814804324 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 10 Jul 2019 12:46:27 +0300 Subject: [PATCH] Rename visor back to appManager --- ci_scripts/run-pkg-tests.sh | 8 ++++---- pkg/router/router.go | 4 ++-- pkg/router/visor.go | 38 ++++++++++++++++++------------------- pkg/router/visor_test.go | 24 +++++++++++------------ 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/ci_scripts/run-pkg-tests.sh b/ci_scripts/run-pkg-tests.sh index 559259f462..96d4c88006 100644 --- a/ci_scripts/run-pkg-tests.sh +++ b/ci_scripts/run-pkg-tests.sh @@ -28,10 +28,10 @@ go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/node -run TestStartStopApp >> ./logs/pkg/TestStartStopApp.log go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/node -run TestRPC >> ./logs/pkg/TestRPC.log -go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestVisorInit >> ./logs/pkg/TestVisorInit.log -go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestVisorSetupLoop >> ./logs/pkg/TestVisorSetupLoop.log -go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestVisorCloseLoop >> ./logs/pkg/TestVisorCloseLoop.log -go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestVisorForward >> ./logs/pkg/TestVisorForward.log +go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestAppManagerInit >> ./logs/pkg/TestAppManagerInit.log +go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestAppManagerSetupLoop >> ./logs/pkg/TestAppManagerSetupLoop.log +go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestAppManagerCloseLoop >> ./logs/pkg/TestAppManagerCloseLoop.log +go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestAppManagerForward >> ./logs/pkg/TestAppManagerForward.log go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestManagedRoutingTableCleanup >> ./logs/pkg/TestManagedRoutingTableCleanup.log go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestPortManager >> ./logs/pkg/TestPortManager.log go clean -testcache &> /dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/pkg/router -run TestRouteManagerGetRule >> ./logs/pkg/TestRouteManagerGetRule.log diff --git a/pkg/router/router.go b/pkg/router/router.go index dcbb20f262..464a3628e7 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -141,8 +141,8 @@ func (r *Router) ServeApp(conn net.Conn, port uint16, appConf *app.Config) error CloseLoop: r.closeLoop, Forward: r.forwardAppPacket, } - visor := &visor{r.Logger, appProto, appConf, callbacks} - err := visor.Serve() + am := &appManager{r.Logger, appProto, appConf, callbacks} + err := am.Serve() for _, port := range r.pm.AppPorts(appProto) { for _, addr := range r.pm.Close(port) { diff --git a/pkg/router/visor.go b/pkg/router/visor.go index fa41f265f6..49565f85c4 100644 --- a/pkg/router/visor.go +++ b/pkg/router/visor.go @@ -17,7 +17,7 @@ type appCallbacks struct { Forward func(conn *app.Protocol, packet *app.Packet) error } -type visor struct { +type appManager struct { Logger *logging.Logger proto *app.Protocol @@ -25,31 +25,31 @@ type visor struct { callbacks *appCallbacks } -func (v *visor) Serve() error { - return v.proto.Serve(func(frame app.Frame, payload []byte) (res interface{}, err error) { - v.Logger.Infof("Got new App request with type %s: %s", frame, string(payload)) +func (am *appManager) Serve() error { + return am.proto.Serve(func(frame app.Frame, payload []byte) (res interface{}, err error) { + am.Logger.Infof("Got new App request with type %s: %s", frame, string(payload)) switch frame { case app.FrameInit: - err = v.initApp(payload) + err = am.initApp(payload) case app.FrameCreateLoop: - res, err = v.setupLoop(payload) + res, err = am.setupLoop(payload) case app.FrameClose: - err = v.handleCloseLoop(payload) + err = am.handleCloseLoop(payload) case app.FrameSend: - err = v.forwardAppPacket(payload) + err = am.forwardAppPacket(payload) default: err = errors.New("unexpected frame") } if err != nil { - v.Logger.Infof("App request with type %s failed: %s", frame, err) + am.Logger.Infof("App request with type %s failed: %s", frame, err) } return res, err }) } -func (v *visor) initApp(payload []byte) error { +func (am *appManager) initApp(payload []byte) error { config := &app.Config{} if err := json.Unmarshal(payload, config); err != nil { return errors.New("invalid Init payload") @@ -59,41 +59,41 @@ func (v *visor) initApp(payload []byte) error { return errors.New("unsupported protocol version") } - if v.appConf.AppName != config.AppName { + if am.appConf.AppName != config.AppName { return errors.New("unexpected app") } - if v.appConf.AppVersion != config.AppVersion { + if am.appConf.AppVersion != config.AppVersion { return errors.New("unexpected app version") } - v.Logger.Infof("Handshaked new connection with the app %s.v%s", config.AppName, config.AppVersion) + am.Logger.Infof("Handshaked new connection with the app %s.v%s", config.AppName, config.AppVersion) return nil } -func (v *visor) setupLoop(payload []byte) (*app.Addr, error) { +func (am *appManager) setupLoop(payload []byte) (*app.Addr, error) { raddr := &app.Addr{} if err := json.Unmarshal(payload, raddr); err != nil { return nil, err } - return v.callbacks.CreateLoop(v.proto, raddr) + return am.callbacks.CreateLoop(am.proto, raddr) } -func (v *visor) handleCloseLoop(payload []byte) error { +func (am *appManager) handleCloseLoop(payload []byte) error { addr := &app.LoopAddr{} if err := json.Unmarshal(payload, addr); err != nil { return err } - return v.callbacks.CloseLoop(v.proto, addr) + return am.callbacks.CloseLoop(am.proto, addr) } -func (v *visor) forwardAppPacket(payload []byte) error { +func (am *appManager) forwardAppPacket(payload []byte) error { packet := &app.Packet{} if err := json.Unmarshal(payload, packet); err != nil { return err } - return v.callbacks.Forward(v.proto, packet) + return am.callbacks.Forward(am.proto, packet) } diff --git a/pkg/router/visor_test.go b/pkg/router/visor_test.go index 1ba6240393..041866db2a 100644 --- a/pkg/router/visor_test.go +++ b/pkg/router/visor_test.go @@ -12,9 +12,9 @@ import ( "github.com/skycoin/skywire/pkg/app" ) -func TestVisorInit(t *testing.T) { +func TestAppManagerInit(t *testing.T) { in, out := net.Pipe() - visor := &visor{ + am := &appManager{ logging.MustGetLogger("routesetup"), app.NewProtocol(out), &app.Config{AppName: "foo", AppVersion: "0.0.1"}, @@ -22,7 +22,7 @@ func TestVisorInit(t *testing.T) { } srvCh := make(chan error) - go func() { srvCh <- visor.Serve() }() + go func() { srvCh <- am.Serve() }() proto := app.NewProtocol(in) go proto.Serve(nil) // nolint: errcheck @@ -51,9 +51,9 @@ func TestVisorInit(t *testing.T) { require.NoError(t, <-srvCh) } -func TestVisorSetupLoop(t *testing.T) { +func TestAppManagerSetupLoop(t *testing.T) { in, out := net.Pipe() - visor := &visor{ + am := &appManager{ logging.MustGetLogger("routesetup"), app.NewProtocol(out), &app.Config{AppName: "foo", AppVersion: "0.0.1"}, @@ -65,7 +65,7 @@ func TestVisorSetupLoop(t *testing.T) { } srvCh := make(chan error) - go func() { srvCh <- visor.Serve() }() + go func() { srvCh <- am.Serve() }() proto := app.NewProtocol(in) go proto.Serve(nil) // nolint: errcheck @@ -81,10 +81,10 @@ func TestVisorSetupLoop(t *testing.T) { require.NoError(t, <-srvCh) } -func TestVisorCloseLoop(t *testing.T) { +func TestAppManagerCloseLoop(t *testing.T) { in, out := net.Pipe() var inAddr *app.LoopAddr - visor := &visor{ + am := &appManager{ logging.MustGetLogger("routesetup"), app.NewProtocol(out), &app.Config{AppName: "foo", AppVersion: "0.0.1"}, @@ -97,7 +97,7 @@ func TestVisorCloseLoop(t *testing.T) { } srvCh := make(chan error) - go func() { srvCh <- visor.Serve() }() + go func() { srvCh <- am.Serve() }() proto := app.NewProtocol(in) go proto.Serve(nil) // nolint: errcheck @@ -112,10 +112,10 @@ func TestVisorCloseLoop(t *testing.T) { require.NoError(t, <-srvCh) } -func TestVisorForward(t *testing.T) { +func TestAppManagerForward(t *testing.T) { in, out := net.Pipe() var inPacket *app.Packet - visor := &visor{ + am := &appManager{ logging.MustGetLogger("routesetup"), app.NewProtocol(out), &app.Config{AppName: "foo", AppVersion: "0.0.1"}, @@ -128,7 +128,7 @@ func TestVisorForward(t *testing.T) { } srvCh := make(chan error) - go func() { srvCh <- visor.Serve() }() + go func() { srvCh <- am.Serve() }() proto := app.NewProtocol(in) go proto.Serve(nil) // nolint: errcheck