Skip to content

Commit

Permalink
Resolve import cycles
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Oct 18, 2019
1 parent 9b02e69 commit 073408f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/app2/appserver/proc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os/exec"
"sync"

"github.com/skycoin/skywire/pkg/app2"
"github.com/skycoin/skywire/pkg/app2/apputil"

"github.com/pkg/errors"

Expand All @@ -32,7 +32,7 @@ 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) (app2.ProcID, error) {
func (m *ProcManager) Run(log *logging.Logger, c Config, args []string) (apputil.ProcID, error) {
if m.Exists(c.Name) {
return 0, errAppAlreadyExists
}
Expand All @@ -57,7 +57,7 @@ func (m *ProcManager) Run(log *logging.Logger, c Config, args []string) (app2.Pr
m.procs[c.Name] = p
m.mx.Unlock()

return app2.ProcID(p.cmd.Process.Pid), nil
return apputil.ProcID(p.cmd.Process.Pid), nil
}

// Exists check whether app exists in the manager instance.
Expand Down
2 changes: 1 addition & 1 deletion pkg/app2/procid.go → pkg/app2/apputil/procid.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app2
package apputil

// ProcID identifies the current instance of an app (an app process).
// The visor node is responsible for starting apps, and the started process
Expand Down
6 changes: 4 additions & 2 deletions pkg/app2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"net"
"net/rpc"

"github.com/skycoin/skywire/pkg/app2/apputil"

"github.com/pkg/errors"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/skycoin/src/util/logging"
Expand All @@ -17,7 +19,7 @@ import (
type Client struct {
log *logging.Logger
pk cipher.PubKey
pid ProcID
pid apputil.ProcID
rpc RPCClient
lm *idmanager.Manager // contains listeners associated with their IDs
cm *idmanager.Manager // contains connections associated with their IDs
Expand All @@ -29,7 +31,7 @@ type Client struct {
// - pid: The procID assigned for the process that Client is being used by.
// - sockFile: unix socket file to connect to the app server.
// - appKey: application key to authenticate within app server.
func NewClient(log *logging.Logger, localPK cipher.PubKey, pid ProcID, sockFile, appKey string) (*Client, error) {
func NewClient(log *logging.Logger, localPK cipher.PubKey, pid apputil.ProcID, sockFile, appKey string) (*Client, error) {
rpcCl, err := rpc.Dial("unix", sockFile)
if err != nil {
return nil, errors.Wrap(err, "error connecting to the app server")
Expand Down
9 changes: 5 additions & 4 deletions pkg/app2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package app2

import (
"errors"
"github.com/skycoin/skywire/pkg/app2/idmanager"
"testing"

"github.com/skycoin/skywire/pkg/app2/apputil"

"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/stretchr/testify/require"
Expand All @@ -16,7 +17,7 @@ import (
func TestClient_Dial(t *testing.T) {
l := logging.MustGetLogger("app2_client")
localPK, _ := cipher.GenerateKeyPair()
pid := ProcID(1)
pid := apputil.ProcID(1)

remotePK, _ := cipher.GenerateKeyPair()
remotePort := routing.Port(120)
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestClient_Dial(t *testing.T) {
func TestClient_Listen(t *testing.T) {
l := logging.MustGetLogger("app2_client")
localPK, _ := cipher.GenerateKeyPair()
pid := ProcID(1)
pid := apputil.ProcID(1)

port := routing.Port(1)
local := appnet.Addr{
Expand Down Expand Up @@ -220,7 +221,7 @@ func TestClient_Listen(t *testing.T) {
func TestClient_Close(t *testing.T) {
l := logging.MustGetLogger("app2_client")
localPK, _ := cipher.GenerateKeyPair()
pid := ProcID(1)
pid := apputil.ProcID(1)

var closeNoErr error
closeErr := errors.New("close error")
Expand Down
5 changes: 3 additions & 2 deletions pkg/visor/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
"syscall"
"time"

"github.com/skycoin/skywire/pkg/app2"
"github.com/skycoin/skywire/pkg/app2/apputil"

"github.com/skycoin/skywire/pkg/app2/appserver"

"github.com/skycoin/skywire/pkg/snet"
Expand Down Expand Up @@ -452,7 +453,7 @@ func (node *Node) SpawnApp(config *AppConfig, startCh chan<- struct{}) (err erro
return nil
}

func (node *Node) persistPID(name string, pid app2.ProcID) {
func (node *Node) persistPID(name string, pid apputil.ProcID) {
pidF := node.pidFile()
pidFName := pidF.Name()
if err := pidF.Close(); err != nil {
Expand Down

0 comments on commit 073408f

Please sign in to comment.