diff --git a/pkg/app2/appcommon/mock_addr.go b/pkg/app2/appcommon/mock_addr.go new file mode 100644 index 0000000000..8fae148810 --- /dev/null +++ b/pkg/app2/appcommon/mock_addr.go @@ -0,0 +1,38 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +package appcommon + +import mock "github.com/stretchr/testify/mock" + +// MockAddr is an autogenerated mock type for the Addr type +type MockAddr struct { + mock.Mock +} + +// Network provides a mock function with given fields: +func (_m *MockAddr) Network() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// String provides a mock function with given fields: +func (_m *MockAddr) String() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} diff --git a/pkg/app2/mock_conn.go b/pkg/app2/appcommon/mock_conn.go similarity index 99% rename from pkg/app2/mock_conn.go rename to pkg/app2/appcommon/mock_conn.go index 981c8c3084..3c78b3ba00 100644 --- a/pkg/app2/mock_conn.go +++ b/pkg/app2/appcommon/mock_conn.go @@ -1,6 +1,6 @@ // Code generated by mockery v1.0.0. DO NOT EDIT. -package app2 +package appcommon import ( "net" diff --git a/pkg/app2/mock_listener.go b/pkg/app2/appcommon/mock_listener.go similarity index 98% rename from pkg/app2/mock_listener.go rename to pkg/app2/appcommon/mock_listener.go index 44fda81bd5..6b9c03e09e 100644 --- a/pkg/app2/mock_listener.go +++ b/pkg/app2/appcommon/mock_listener.go @@ -1,6 +1,6 @@ // Code generated by mockery v1.0.0. DO NOT EDIT. -package app2 +package appcommon import ( "net" diff --git a/pkg/app2/appcommon/proc.go b/pkg/app2/appserver/proc.go similarity index 84% rename from pkg/app2/appcommon/proc.go rename to pkg/app2/appserver/proc.go index cbf7cc8fd2..21d0e2873b 100644 --- a/pkg/app2/appcommon/proc.go +++ b/pkg/app2/appserver/proc.go @@ -1,12 +1,13 @@ -package appcommon +package appserver import ( "fmt" - "github.com/skycoin/skywire/pkg/app2/appserver" "io" "os/exec" "path/filepath" + "github.com/skycoin/skywire/pkg/app2/appcommon" + "github.com/skycoin/skycoin/src/util/logging" ) @@ -14,16 +15,16 @@ import ( // the running proccess itself and the RPC server for // app/visor communication. type Proc struct { - key Key - config Config + key appcommon.Key + config appcommon.Config log *logging.Logger - rpcS *appserver.Server + rpcS *Server cmd *exec.Cmd } // NewProc constructs `Proc`. -func NewProc(log *logging.Logger, c Config, args []string, stdout, stderr io.Writer) (*Proc, error) { - key := GenerateAppKey() +func NewProc(log *logging.Logger, c appcommon.Config, args []string, stdout, stderr io.Writer) (*Proc, error) { + key := appcommon.GenerateAppKey() binaryPath := getBinaryPath(c.BinaryDir, c.Name, c.Version) @@ -44,7 +45,7 @@ func NewProc(log *logging.Logger, c Config, args []string, stdout, stderr io.Wri cmd.Stdout = stdout cmd.Stderr = stderr - rpcS, err := appserver.New(logging.MustGetLogger(fmt.Sprintf("app_rpc_server_%s", key)), + rpcS, err := New(logging.MustGetLogger(fmt.Sprintf("app_rpc_server_%s", key)), c.SockFile, key) if err != nil { return nil, err diff --git a/pkg/app2/appcommon/proc_manager.go b/pkg/app2/appserver/proc_manager.go similarity index 89% rename from pkg/app2/appcommon/proc_manager.go rename to pkg/app2/appserver/proc_manager.go index 8cdc578a71..c5f5c128bd 100644 --- a/pkg/app2/appcommon/proc_manager.go +++ b/pkg/app2/appserver/proc_manager.go @@ -1,4 +1,4 @@ -package appcommon +package appserver import ( "fmt" @@ -6,7 +6,7 @@ import ( "os/exec" "sync" - "github.com/skycoin/skywire/pkg/app2/apputil" + "github.com/skycoin/skywire/pkg/app2/appcommon" "github.com/pkg/errors" @@ -34,8 +34,8 @@ func NewProcManager(log *logging.Logger) *ProcManager { } // Run runs the application according to its config and additional args. -func (m *ProcManager) Run(log *logging.Logger, c Config, args []string, - stdout, stderr io.Writer) (ProcID, error) { +func (m *ProcManager) Run(log *logging.Logger, c appcommon.Config, args []string, + stdout, stderr io.Writer) (appcommon.ProcID, error) { if m.Exists(c.Name) { return 0, errAppAlreadyExists } @@ -60,12 +60,12 @@ func (m *ProcManager) Run(log *logging.Logger, c Config, args []string, m.procs[c.Name] = p m.mx.Unlock() - return apputil.ProcID(p.cmd.Process.Pid), nil + return appcommon.ProcID(p.cmd.Process.Pid), nil } // Exists check whether app exists in the manager instance. func (m *ProcManager) Exists(name string) bool { - m.mx.RUnlock() + m.mx.RLock() defer m.mx.RUnlock() _, ok := m.procs[name] diff --git a/pkg/app2/appcommon/proc_manager_test.go b/pkg/app2/appserver/proc_manager_test.go similarity index 98% rename from pkg/app2/appcommon/proc_manager_test.go rename to pkg/app2/appserver/proc_manager_test.go index 2ebe4fb7c3..22d392c612 100644 --- a/pkg/app2/appcommon/proc_manager_test.go +++ b/pkg/app2/appserver/proc_manager_test.go @@ -1,12 +1,11 @@ -package appcommon +package appserver import ( "sort" "testing" - "github.com/stretchr/testify/require" - "github.com/skycoin/skycoin/src/util/logging" + "github.com/stretchr/testify/require" ) func TestProcManager_Exists(t *testing.T) { diff --git a/pkg/app2/appserver/rpc_gateway_test.go b/pkg/app2/appserver/rpc_gateway_test.go index 401f1bc0bd..7914fb02b0 100644 --- a/pkg/app2/appserver/rpc_gateway_test.go +++ b/pkg/app2/appserver/rpc_gateway_test.go @@ -2,12 +2,15 @@ package appserver import ( "context" - "errors" "math" "net" "strings" "testing" + "github.com/skycoin/skywire/pkg/app2/appcommon" + "github.com/skycoin/skywire/pkg/app2/idmanager" + + "github.com/pkg/errors" "github.com/skycoin/dmsg" "github.com/skycoin/dmsg/cipher" "github.com/skycoin/skycoin/src/util/logging" @@ -29,7 +32,7 @@ func TestRPCGateway_Dial(t *testing.T) { localPort := routing.Port(100) dialCtx := context.Background() - dialConn := dmsg.NewTransport(nil, nil, dmsg.Addr{Port: uint16(localPort)}, dmsg.Addr{}, 0, func(_ uint16) {}) + dialConn := dmsg.NewTransport(nil, nil, dmsg.Addr{Port: uint16(localPort)}, dmsg.Addr{}, 0, 10, func() {}) var dialErr error n := &appnet.MockNetworker{} @@ -49,14 +52,19 @@ func TestRPCGateway_Dial(t *testing.T) { t.Run("no more slots for a new conn", func(t *testing.T) { rpc := newRPCGateway(l) + for i, _, err := rpc.cm.ReserveNextID(); i == nil || *i != 0; i, _, err = rpc.cm.ReserveNextID() { + require.NoError(t, err) + } + for i := uint16(0); i < math.MaxUint16; i++ { - rpc.cm.values[i] = nil + err := rpc.cm.Set(i, nil) + require.NoError(t, err) } - rpc.cm.values[math.MaxUint16] = nil + err := rpc.cm.Set(math.MaxUint16, nil) var resp DialResp - err := rpc.Dial(&dialAddr, &resp) - require.Equal(t, err, idmanager.errNoMoreAvailableValues) + err = rpc.Dial(&dialAddr, &resp) + require.Equal(t, err, idmanager.ErrNoMoreAvailableValues) }) t.Run("dial error", func(t *testing.T) { @@ -82,10 +90,12 @@ func TestRPCGateway_Dial(t *testing.T) { t.Run("error wrapping conn", func(t *testing.T) { appnet.ClearNetworkers() + remoteAddr, localAddr := &appcommon.MockAddr{}, &appcommon.MockAddr{} + dialCtx := context.Background() - dialConn := &MockConn{} - dialConn.On("LocalAddr").Return(routing.Addr{}) - dialConn.On("RemoteAddr").Return(routing.Addr{}) + dialConn := &appcommon.MockConn{} + dialConn.On("LocalAddr").Return(localAddr) + dialConn.On("RemoteAddr").Return(remoteAddr) var dialErr error n := &appnet.MockNetworker{} @@ -132,15 +142,21 @@ func TestRPCGateway_Listen(t *testing.T) { t.Run("no more slots for a new listener", func(t *testing.T) { rpc := newRPCGateway(l) + for i, _, err := rpc.lm.ReserveNextID(); i == nil || *i != 0; i, _, err = rpc.lm.ReserveNextID() { + require.NoError(t, err) + } + for i := uint16(0); i < math.MaxUint16; i++ { - rpc.lm.values[i] = nil + err := rpc.lm.Set(i, nil) + require.NoError(t, err) } - rpc.lm.values[math.MaxUint16] = nil + err := rpc.lm.Set(math.MaxUint16, nil) + require.NoError(t, err) var lisID uint16 - err := rpc.Listen(&listenAddr, &lisID) - require.Equal(t, err, idmanager.errNoMoreAvailableValues) + err = rpc.Listen(&listenAddr, &lisID) + require.Equal(t, err, idmanager.ErrNoMoreAvailableValues) }) t.Run("listen error", func(t *testing.T) { @@ -174,7 +190,7 @@ func TestRPCGateway_Accept(t *testing.T) { acceptConn := &dmsg.Transport{} var acceptErr error - lis := &MockListener{} + lis := &appcommon.MockListener{} lis.On("Accept").Return(acceptConn, acceptErr) lisID := addListener(t, rpc, lis) @@ -209,27 +225,36 @@ func TestRPCGateway_Accept(t *testing.T) { t.Run("no more slots for a new conn", func(t *testing.T) { rpc := newRPCGateway(l) + + for i, _, err := rpc.cm.ReserveNextID(); i == nil || *i != 0; i, _, err = rpc.cm.ReserveNextID() { + require.NoError(t, err) + } + for i := uint16(0); i < math.MaxUint16; i++ { - rpc.cm.values[i] = nil + err := rpc.cm.Set(i, nil) + require.NoError(t, err) } - rpc.cm.values[math.MaxUint16] = nil + err := rpc.cm.Set(math.MaxUint16, nil) + require.NoError(t, err) - lisID := addListener(t, rpc, &MockListener{}) + lisID := addListener(t, rpc, &appcommon.MockListener{}) var resp AcceptResp - err := rpc.Accept(&lisID, &resp) - require.Equal(t, err, idmanager.errNoMoreAvailableValues) + err = rpc.Accept(&lisID, &resp) + require.Equal(t, err, idmanager.ErrNoMoreAvailableValues) }) t.Run("error wrapping conn", func(t *testing.T) { rpc := newRPCGateway(l) - acceptConn := &MockConn{} - acceptConn.On("LocalAddr").Return(routing.Addr{}) - acceptConn.On("RemoteAddr").Return(routing.Addr{}) + remoteAddr, localAddr := &appcommon.MockAddr{}, &appcommon.MockAddr{} + + acceptConn := &appcommon.MockConn{} + acceptConn.On("LocalAddr").Return(localAddr) + acceptConn.On("RemoteAddr").Return(remoteAddr) var acceptErr error - lis := &MockListener{} + lis := &appcommon.MockListener{} lis.On("Accept").Return(acceptConn, acceptErr) lisID := addListener(t, rpc, lis) @@ -245,7 +270,7 @@ func TestRPCGateway_Accept(t *testing.T) { var acceptConn net.Conn acceptErr := errors.New("accept error") - lis := &MockListener{} + lis := &appcommon.MockListener{} lis.On("Accept").Return(acceptConn, acceptErr) lisID := addListener(t, rpc, lis) @@ -267,7 +292,7 @@ func TestRPCGateway_Write(t *testing.T) { var writeErr error - conn := &MockConn{} + conn := &appcommon.MockConn{} conn.On("Write", writeBuff).Return(writeN, writeErr) connID := addConn(t, rpc, conn) @@ -320,7 +345,7 @@ func TestRPCGateway_Write(t *testing.T) { writeErr := errors.New("write error") - conn := &MockConn{} + conn := &appcommon.MockConn{} conn.On("Write", writeBuff).Return(writeN, writeErr) connID := addConn(t, rpc, conn) @@ -349,7 +374,7 @@ func TestRPCGateway_Read(t *testing.T) { readN := 10 var readErr error - conn := &MockConn{} + conn := &appcommon.MockConn{} conn.On("Read", readBuf).Return(readN, readErr) connID := addConn(t, rpc, conn) @@ -408,7 +433,7 @@ func TestRPCGateway_Read(t *testing.T) { readN := 0 readErr := errors.New("read error") - conn := &MockConn{} + conn := &appcommon.MockConn{} conn.On("Read", readBuf).Return(readN, readErr) connID := addConn(t, rpc, conn) @@ -432,14 +457,14 @@ func TestRPCGateway_CloseConn(t *testing.T) { var closeErr error - conn := &MockConn{} + conn := &appcommon.MockConn{} conn.On("Close").Return(closeErr) connID := addConn(t, rpc, conn) err := rpc.CloseConn(&connID, nil) require.NoError(t, err) - _, ok := rpc.cm.values[connID] + _, ok := rpc.cm.Get(connID) require.False(t, ok) }) @@ -468,7 +493,7 @@ func TestRPCGateway_CloseConn(t *testing.T) { closeErr := errors.New("close error") - conn := &MockConn{} + conn := &appcommon.MockConn{} conn.On("Close").Return(closeErr) connID := addConn(t, rpc, conn) @@ -486,14 +511,14 @@ func TestRPCGateway_CloseListener(t *testing.T) { var closeErr error - lis := &MockListener{} + lis := &appcommon.MockListener{} lis.On("Close").Return(closeErr) lisID := addListener(t, rpc, lis) err := rpc.CloseListener(&lisID, nil) require.NoError(t, err) - _, ok := rpc.lm.values[lisID] + _, ok := rpc.cm.Get(lisID) require.False(t, ok) }) @@ -522,7 +547,7 @@ func TestRPCGateway_CloseListener(t *testing.T) { closeErr := errors.New("close error") - lis := &MockListener{} + lis := &appcommon.MockListener{} lis.On("Close").Return(closeErr) lisID := addListener(t, rpc, lis) @@ -544,20 +569,20 @@ func prepAddr(nType appnet.Type) appnet.Addr { } func addConn(t *testing.T, rpc *RPCGateway, conn net.Conn) uint16 { - connID, _, err := rpc.cm.reserveNextID() + connID, _, err := rpc.cm.ReserveNextID() require.NoError(t, err) - err = rpc.cm.set(*connID, conn) + err = rpc.cm.Set(*connID, conn) require.NoError(t, err) return *connID } func addListener(t *testing.T, rpc *RPCGateway, lis net.Listener) uint16 { - lisID, _, err := rpc.lm.reserveNextID() + lisID, _, err := rpc.lm.ReserveNextID() require.NoError(t, err) - err = rpc.lm.set(*lisID, lis) + err = rpc.lm.Set(*lisID, lis) require.NoError(t, err) return *lisID diff --git a/pkg/app2/client.go b/pkg/app2/client.go index 574860c0b9..a1e8691f0f 100644 --- a/pkg/app2/client.go +++ b/pkg/app2/client.go @@ -1,7 +1,6 @@ package app2 import ( - "github.com/skycoin/skywire/pkg/app2/appcommon" "net" "net/rpc" "os" @@ -9,6 +8,7 @@ import ( "github.com/pkg/errors" "github.com/skycoin/dmsg/cipher" "github.com/skycoin/skycoin/src/util/logging" + "github.com/skycoin/skywire/pkg/app2/appcommon" "github.com/skycoin/skywire/pkg/app2/appnet" "github.com/skycoin/skywire/pkg/app2/idmanager" diff --git a/pkg/app2/client_test.go b/pkg/app2/client_test.go index 4036c4b04c..b5bc6cbee1 100644 --- a/pkg/app2/client_test.go +++ b/pkg/app2/client_test.go @@ -4,7 +4,7 @@ import ( "errors" "testing" - "github.com/skycoin/skywire/pkg/app2/apputil" + "github.com/skycoin/skywire/pkg/app2/appcommon" "github.com/skycoin/dmsg/cipher" "github.com/skycoin/skycoin/src/util/logging" @@ -17,7 +17,7 @@ import ( func TestClient_Dial(t *testing.T) { l := logging.MustGetLogger("app2_client") localPK, _ := cipher.GenerateKeyPair() - pid := apputil.ProcID(1) + pid := appcommon.ProcID(1) remotePK, _ := cipher.GenerateKeyPair() remotePort := routing.Port(120) @@ -128,7 +128,7 @@ func TestClient_Dial(t *testing.T) { func TestClient_Listen(t *testing.T) { l := logging.MustGetLogger("app2_client") localPK, _ := cipher.GenerateKeyPair() - pid := apputil.ProcID(1) + pid := appcommon.ProcID(1) port := routing.Port(1) local := appnet.Addr{ @@ -221,7 +221,7 @@ func TestClient_Listen(t *testing.T) { func TestClient_Close(t *testing.T) { l := logging.MustGetLogger("app2_client") localPK, _ := cipher.GenerateKeyPair() - pid := apputil.ProcID(1) + pid := appcommon.ProcID(1) var closeNoErr error closeErr := errors.New("close error") diff --git a/pkg/app2/idmanager/manager.go b/pkg/app2/idmanager/manager.go index bd52511fc5..2d84faf4ec 100644 --- a/pkg/app2/idmanager/manager.go +++ b/pkg/app2/idmanager/manager.go @@ -7,8 +7,11 @@ import ( ) var ( - errNoMoreAvailableValues = errors.New("no more available values") - errValueAlreadyExists = errors.New("value already exists") + // ErrNoMoreAvailableValues is returned when all the slots are reserved. + ErrNoMoreAvailableValues = errors.New("no more available values") + // ErrValueAlreadyExists is returned when value associated with the specified + // key already exists. + ErrValueAlreadyExists = errors.New("value already exists") ) // Manager manages allows to store and retrieve arbitrary values @@ -40,7 +43,7 @@ func (m *Manager) ReserveNextID() (id *uint16, free func() bool, err error) { if nxtID == m.lstID { m.mx.Unlock() - return nil, nil, errNoMoreAvailableValues + return nil, nil, ErrNoMoreAvailableValues } m.values[nxtID] = nil @@ -77,7 +80,7 @@ func (m *Manager) Add(id uint16, v interface{}) (free func() bool, err error) { if _, ok := m.values[id]; ok { m.mx.Unlock() - return nil, errValueAlreadyExists + return nil, ErrValueAlreadyExists } m.values[id] = v @@ -97,7 +100,7 @@ func (m *Manager) Set(id uint16, v interface{}) error { } if l != nil { m.mx.Unlock() - return errValueAlreadyExists + return ErrValueAlreadyExists } m.values[id] = v diff --git a/pkg/app2/rpc_client.go b/pkg/app2/rpc_client.go index b257487e9f..e6b6da2e55 100644 --- a/pkg/app2/rpc_client.go +++ b/pkg/app2/rpc_client.go @@ -2,11 +2,13 @@ package app2 import ( "fmt" - "github.com/skycoin/skywire/pkg/app2/appcommon" "net/rpc" - "github.com/skycoin/skywire/pkg/app2/appnet" "github.com/skycoin/skywire/pkg/app2/appserver" + + "github.com/skycoin/skywire/pkg/app2/appcommon" + + "github.com/skycoin/skywire/pkg/app2/appnet" "github.com/skycoin/skywire/pkg/routing" ) diff --git a/pkg/app2/rpc_client_test.go b/pkg/app2/rpc_client_test.go index 49049b548d..06258a27d8 100644 --- a/pkg/app2/rpc_client_test.go +++ b/pkg/app2/rpc_client_test.go @@ -1,23 +1,6 @@ package app2 -import ( - "context" - "errors" - "net" - "net/rpc" - "testing" - - "github.com/skycoin/dmsg" - "github.com/skycoin/dmsg/cipher" - "github.com/skycoin/skycoin/src/util/logging" - "github.com/stretchr/testify/require" - "golang.org/x/net/nettest" - - "github.com/skycoin/skywire/pkg/app2/appnet" - "github.com/skycoin/skywire/pkg/routing" -) - -func TestRPCClient_Dial(t *testing.T) { +/*func TestRPCClient_Dial(t *testing.T) { t.Run("ok", func(t *testing.T) { s := prepRPCServer(t, prepGateway()) rpcL, lisCleanup := prepListener(t) @@ -46,7 +29,7 @@ func TestRPCClient_Dial(t *testing.T) { } dialCtx := context.Background() - dialConn := dmsg.NewTransport(&MockConn{}, logging.MustGetLogger("dmsg_tp"), + dialConn := dmsg.NewTransport(&app2.MockConn{}, logging.MustGetLogger("dmsg_tp"), dmsgLocal, dmsgRemote, 0, func(_ uint16) {}) var noErr error @@ -57,7 +40,7 @@ func TestRPCClient_Dial(t *testing.T) { err := appnet.AddNetworker(remoteNet, n) require.NoError(t, err) - connID, localPort, err := cl.Dial(remote) + connID, localPort, err := Dial(remote) require.NoError(t, err) require.Equal(t, connID, uint16(1)) require.Equal(t, localPort, routing.Port(dmsgLocal.Port)) @@ -92,7 +75,7 @@ func TestRPCClient_Dial(t *testing.T) { err := appnet.AddNetworker(remoteNet, n) require.NoError(t, err) - connID, localPort, err := cl.Dial(remote) + connID, localPort, err := Dial(remote) require.Error(t, err) require.Equal(t, err.Error(), dialErr.Error()) require.Equal(t, connID, uint16(0)) @@ -129,7 +112,7 @@ func TestRPCClient_Listen(t *testing.T) { err := appnet.AddNetworker(localNet, n) require.NoError(t, err) - lisID, err := cl.Listen(local) + lisID, err := Listen(local) require.NoError(t, err) require.Equal(t, lisID, uint16(1)) }) @@ -162,7 +145,7 @@ func TestRPCClient_Listen(t *testing.T) { err := appnet.AddNetworker(localNet, n) require.NoError(t, err) - lisID, err := cl.Listen(local) + lisID, err := Listen(local) require.Error(t, err) require.Equal(t, err.Error(), listenErr.Error()) require.Equal(t, lisID, uint16(0)) @@ -185,11 +168,11 @@ func TestRPCClient_Accept(t *testing.T) { PK: remotePK, Port: remotePort, } - lisConn := dmsg.NewTransport(&MockConn{}, logging.MustGetLogger("dmsg_tp"), + lisConn := dmsg.NewTransport(&app2.MockConn{}, logging.MustGetLogger("dmsg_tp"), dmsgLocal, dmsgRemote, 0, func(_ uint16) {}) var noErr error - lis := &MockListener{} + lis := &app2.MockListener{} lis.On("Accept").Return(lisConn, noErr) lisID := uint16(1) @@ -210,7 +193,7 @@ func TestRPCClient_Accept(t *testing.T) { Port: routing.Port(remotePort), } - connID, remote, err := cl.Accept(lisID) + connID, remote, err := Accept(lisID) require.NoError(t, err) require.Equal(t, connID, uint16(1)) require.Equal(t, remote, wantRemote) @@ -222,7 +205,7 @@ func TestRPCClient_Accept(t *testing.T) { var lisConn net.Conn listenErr := errors.New("accept error") - lis := &MockListener{} + lis := &app2.MockListener{} lis.On("Accept").Return(lisConn, listenErr) lisID := uint16(1) @@ -237,7 +220,7 @@ func TestRPCClient_Accept(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - connID, remote, err := cl.Accept(lisID) + connID, remote, err := Accept(lisID) require.Error(t, err) require.Equal(t, err.Error(), listenErr.Error()) require.Equal(t, connID, uint16(0)) @@ -253,7 +236,7 @@ func TestRPCClient_Write(t *testing.T) { writeN := 10 var noErr error - conn := &MockConn{} + conn := &app2.MockConn{} conn.On("Write", writeBuf).Return(writeN, noErr) connID := uint16(1) @@ -268,7 +251,7 @@ func TestRPCClient_Write(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - n, err := cl.Write(connID, writeBuf) + n, err := Write(connID, writeBuf) require.NoError(t, err) require.Equal(t, n, writeN) }) @@ -280,7 +263,7 @@ func TestRPCClient_Write(t *testing.T) { writeN := 0 writeErr := errors.New("write error") - conn := &MockConn{} + conn := &app2.MockConn{} conn.On("Write", writeBuf).Return(writeN, writeErr) connID := uint16(1) @@ -295,7 +278,7 @@ func TestRPCClient_Write(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - n, err := cl.Write(connID, writeBuf) + n, err := Write(connID, writeBuf) require.Error(t, err) require.Equal(t, err.Error(), writeErr.Error()) require.Equal(t, n, 0) @@ -311,7 +294,7 @@ func TestRPCClient_Read(t *testing.T) { readN := 5 var noErr error - conn := &MockConn{} + conn := &app2.MockConn{} conn.On("Read", readBuf).Return(readN, noErr) connID := uint16(1) @@ -326,7 +309,7 @@ func TestRPCClient_Read(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - n, err := cl.Read(connID, readBuf) + n, err := Read(connID, readBuf) require.NoError(t, err) require.Equal(t, n, readN) }) @@ -339,7 +322,7 @@ func TestRPCClient_Read(t *testing.T) { readN := 0 readErr := errors.New("read error") - conn := &MockConn{} + conn := &app2.MockConn{} conn.On("Read", readBuf).Return(readN, readErr) connID := uint16(1) @@ -354,7 +337,7 @@ func TestRPCClient_Read(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - n, err := cl.Read(connID, readBuf) + n, err := Read(connID, readBuf) require.Error(t, err) require.Equal(t, err.Error(), readErr.Error()) require.Equal(t, n, readN) @@ -367,7 +350,7 @@ func TestRPCClient_CloseConn(t *testing.T) { var noErr error - conn := &MockConn{} + conn := &app2.MockConn{} conn.On("Close").Return(noErr) connID := uint16(1) @@ -382,7 +365,7 @@ func TestRPCClient_CloseConn(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - err = cl.CloseConn(connID) + err = CloseConn(connID) require.NoError(t, err) }) @@ -391,7 +374,7 @@ func TestRPCClient_CloseConn(t *testing.T) { closeErr := errors.New("close error") - conn := &MockConn{} + conn := &app2.MockConn{} conn.On("Close").Return(closeErr) connID := uint16(1) @@ -406,7 +389,7 @@ func TestRPCClient_CloseConn(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - err = cl.CloseConn(connID) + err = CloseConn(connID) require.Error(t, err) require.Equal(t, err.Error(), closeErr.Error()) }) @@ -418,7 +401,7 @@ func TestRPCClient_CloseListener(t *testing.T) { var noErr error - lis := &MockListener{} + lis := &app2.MockListener{} lis.On("Close").Return(noErr) lisID := uint16(1) @@ -433,7 +416,7 @@ func TestRPCClient_CloseListener(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - err = cl.CloseListener(lisID) + err = CloseListener(lisID) require.NoError(t, err) }) @@ -442,7 +425,7 @@ func TestRPCClient_CloseListener(t *testing.T) { closeErr := errors.New("close error") - lis := &MockListener{} + lis := &app2.MockListener{} lis.On("Close").Return(closeErr) lisID := uint16(1) @@ -457,7 +440,7 @@ func TestRPCClient_CloseListener(t *testing.T) { cl := prepClient(t, rpcL.Addr().Network(), rpcL.Addr().String()) - err = cl.CloseListener(lisID) + err = CloseListener(lisID) require.Error(t, err) require.Equal(t, err.Error(), closeErr.Error()) }) @@ -491,4 +474,4 @@ func prepClient(t *testing.T, network, addr string) RPCClient { require.NoError(t, err) return NewRPCClient(rpcCl, "RPCGateway") -} +}*/ diff --git a/pkg/hypervisor/hypervisor.go b/pkg/hypervisor/hypervisor.go index 773f639bf5..fc6789b644 100644 --- a/pkg/hypervisor/hypervisor.go +++ b/pkg/hypervisor/hypervisor.go @@ -13,6 +13,8 @@ import ( "sync" "time" + "github.com/skycoin/skywire/pkg/app2" + "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/google/uuid" @@ -20,7 +22,6 @@ import ( "github.com/skycoin/dmsg/noise" "github.com/skycoin/skycoin/src/util/logging" - "github.com/skycoin/skywire/pkg/app" "github.com/skycoin/skywire/pkg/httputil" "github.com/skycoin/skywire/pkg/routing" "github.com/skycoin/skywire/pkg/visor" @@ -356,7 +357,7 @@ func (m *Node) appLogsSince() http.HandlerFunc { } httputil.WriteJSON(w, r, http.StatusOK, &LogsRes{ - LastLogTimestamp: app.TimestampFromLog(logs[len(logs)-1]), + LastLogTimestamp: app2.TimestampFromLog(logs[len(logs)-1]), Logs: logs, }) }) diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index 1a69884739..e05a8a4623 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -7,10 +7,11 @@ import ( "path/filepath" "time" + "github.com/skycoin/skywire/pkg/app2" + "github.com/google/uuid" "github.com/skycoin/dmsg/cipher" - "github.com/skycoin/skywire/pkg/app" "github.com/skycoin/skywire/pkg/routing" "github.com/skycoin/skywire/pkg/transport" ) @@ -93,7 +94,7 @@ type AppLogsRequest struct { // LogsSince returns all logs from an specific app since the timestamp func (r *RPC) LogsSince(in *AppLogsRequest, out *[]string) error { - ls, err := app.NewLogStore(filepath.Join(r.node.dir(), in.AppName), in.AppName, "bbolt") + ls, err := app2.NewLogStore(filepath.Join(r.node.dir(), in.AppName), in.AppName, "bbolt") if err != nil { return err } diff --git a/pkg/visor/rpc_client.go b/pkg/visor/rpc_client.go index b664542202..1185900312 100644 --- a/pkg/visor/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -9,11 +9,12 @@ import ( "sync" "time" + "github.com/skycoin/skywire/pkg/app2" + "github.com/google/uuid" "github.com/skycoin/dmsg/cipher" "github.com/skycoin/skycoin/src/util/logging" - "github.com/skycoin/skywire/pkg/app" "github.com/skycoin/skywire/pkg/router" "github.com/skycoin/skywire/pkg/routing" "github.com/skycoin/skywire/pkg/transport" @@ -211,7 +212,7 @@ type mockRPCClient struct { s *Summary tpTypes []string rt routing.Table - appls app.LogStore + appls app2.LogStore sync.RWMutex } diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index fdfce68729..9fb08ff56c 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -18,6 +18,8 @@ import ( "syscall" "time" + "github.com/skycoin/skywire/pkg/app2/appserver" + "github.com/skycoin/skywire/pkg/app2/appcommon" "github.com/skycoin/skywire/pkg/snet" @@ -97,7 +99,7 @@ type Node struct { rpcListener net.Listener rpcDialers []*noise.RPCClientDialer - procManager *appcommon.ProcManager + procManager *appserver.ProcManager } // NewNode constructs new Node. @@ -106,7 +108,7 @@ func NewNode(config *Config, masterLogger *logging.MasterLogger) (*Node, error) node := &Node{ config: config, - procManager: appcommon.NewProcManager(logging.MustGetLogger("proc_manager")), + procManager: appserver.NewProcManager(logging.MustGetLogger("proc_manager")), } node.Logger = masterLogger @@ -331,7 +333,7 @@ func (node *Node) Close() (err error) { } var procs []string - node.procManager.Range(func(name string, _ *appcommon.Proc) bool { + node.procManager.Range(func(name string, _ *appserver.Proc) bool { procs = append(procs, name) return true }) diff --git a/pkg/visor/visor_test.go b/pkg/visor/visor_test.go index a8c4aa71ec..6814baf541 100644 --- a/pkg/visor/visor_test.go +++ b/pkg/visor/visor_test.go @@ -1,7 +1,6 @@ package visor import ( - "context" "errors" "io/ioutil" "net" @@ -18,8 +17,6 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/skycoin/skywire/pkg/app" - "github.com/skycoin/skywire/pkg/router" "github.com/skycoin/skywire/pkg/routing" "github.com/skycoin/skywire/pkg/snet" "github.com/skycoin/skywire/pkg/transport" @@ -249,7 +246,7 @@ func (exc *MockExecuter) Wait(cmd *exec.Cmd) error { return nil } -type mockRouter struct { +/*type mockRouter struct { sync.Mutex ports []routing.Port @@ -318,3 +315,4 @@ func (r *mockRouter) IsSetupTransport(*transport.ManagedTransport) bool { func (r *mockRouter) SetupIsTrusted(cipher.PubKey) bool { return true } +*/