Skip to content

Commit

Permalink
Rename visor back to appManager
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Jul 10, 2019
1 parent 84c2b5b commit d51b7bf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
8 changes: 4 additions & 4 deletions ci_scripts/run-pkg-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
38 changes: 19 additions & 19 deletions pkg/router/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,39 @@ type appCallbacks struct {
Forward func(conn *app.Protocol, packet *app.Packet) error
}

type visor struct {
type appManager struct {
Logger *logging.Logger

proto *app.Protocol
appConf *app.Config
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")
Expand All @@ -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)
}
24 changes: 12 additions & 12 deletions pkg/router/visor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ 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"},
nil,
}

srvCh := make(chan error)
go func() { srvCh <- visor.Serve() }()
go func() { srvCh <- am.Serve() }()

proto := app.NewProtocol(in)
go proto.Serve(nil) // nolint: errcheck
Expand Down Expand Up @@ -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"},
Expand All @@ -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
Expand All @@ -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"},
Expand All @@ -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
Expand All @@ -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"},
Expand All @@ -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
Expand Down

0 comments on commit d51b7bf

Please sign in to comment.