From 1de6722c34397866d1afb783ab159402b4719f4e Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 10 Jul 2019 12:57:55 +0300 Subject: [PATCH] Rename /pkg/node to /pkg/visor --- .gitignore | 6 ++--- cmd/skywire-cli/commands/node/app.go | 4 ++-- cmd/skywire-cli/commands/node/gen-config.go | 20 ++++++++-------- cmd/skywire-cli/commands/node/root.go | 6 ++--- cmd/skywire-cli/commands/node/routes.go | 6 ++--- cmd/skywire-cli/commands/node/transports.go | 6 ++--- cmd/skywire-networking-node/commands/root.go | 14 +++++------ pkg/hypervisor/hypervisor.go | 24 +++++++++---------- pkg/{node => visor}/config.go | 2 +- pkg/{node => visor}/config_test.go | 2 +- pkg/{node => visor}/rpc.go | 2 +- pkg/{node => visor}/rpc_client.go | 2 +- pkg/{node => visor}/rpc_test.go | 2 +- pkg/{node/node.go => visor/visor.go} | 4 ++-- .../node_test.go => visor/visor_test.go} | 2 +- 15 files changed, 51 insertions(+), 51 deletions(-) rename pkg/{node => visor}/config.go (99%) rename pkg/{node => visor}/config_test.go (99%) rename pkg/{node => visor}/rpc.go (99%) rename pkg/{node => visor}/rpc_client.go (99%) rename pkg/{node => visor}/rpc_test.go (99%) rename pkg/{node/node.go => visor/visor.go} (99%) rename pkg/{node/node_test.go => visor/visor_test.go} (99%) diff --git a/.gitignore b/.gitignore index 3136318d82..33e6de3b70 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,9 @@ /skywire/ /local* -pkg/node/apps/ -pkg/node/bar/ -pkg/node/foo/ +pkg/visor/apps/ +pkg/visor/bar/ +pkg/visor/foo/ /node /users.db diff --git a/cmd/skywire-cli/commands/node/app.go b/cmd/skywire-cli/commands/node/app.go index 23d3092341..00f267fd02 100644 --- a/cmd/skywire-cli/commands/node/app.go +++ b/cmd/skywire-cli/commands/node/app.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/node" + "github.com/skycoin/skywire/pkg/visor" ) func init() { @@ -34,7 +34,7 @@ var lsAppsCmd = &cobra.Command{ for _, state := range states { status := "stopped" - if state.Status == node.AppStatusRunning { + if state.Status == visor.AppStatusRunning { status = "running" } _, err = fmt.Fprintf(w, "%s\t%s\t%t\t%s\n", state.Name, strconv.Itoa(int(state.Port)), state.AutoStart, status) diff --git a/cmd/skywire-cli/commands/node/gen-config.go b/cmd/skywire-cli/commands/node/gen-config.go index e49230a5bf..78b715373b 100644 --- a/cmd/skywire-cli/commands/node/gen-config.go +++ b/cmd/skywire-cli/commands/node/gen-config.go @@ -9,8 +9,8 @@ import ( "github.com/skycoin/dmsg/cipher" "github.com/spf13/cobra" - "github.com/skycoin/skywire/pkg/node" "github.com/skycoin/skywire/pkg/util/pathutil" + "github.com/skycoin/skywire/pkg/visor" ) func init() { @@ -43,7 +43,7 @@ var genConfigCmd = &cobra.Command{ } }, Run: func(_ *cobra.Command, _ []string) { - var conf *node.Config + var conf *visor.Config switch configLocType { case pathutil.WorkingDirLoc: conf = defaultConfig() @@ -58,7 +58,7 @@ var genConfigCmd = &cobra.Command{ }, } -func homeConfig() *node.Config { +func homeConfig() *visor.Config { c := defaultConfig() c.AppsPath = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/apps") c.Transport.LogStore.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/transport_logs") @@ -66,7 +66,7 @@ func homeConfig() *node.Config { return c } -func localConfig() *node.Config { +func localConfig() *visor.Config { c := defaultConfig() c.AppsPath = "/usr/local/skycoin/skywire/apps" c.Transport.LogStore.Location = "/usr/local/skycoin/skywire/transport_logs" @@ -74,8 +74,8 @@ func localConfig() *node.Config { return c } -func defaultConfig() *node.Config { - conf := &node.Config{} +func defaultConfig() *visor.Config { + conf := &visor.Config{} conf.Version = "1.0" pk, sk := cipher.GenerateKeyPair() @@ -86,7 +86,7 @@ func defaultConfig() *node.Config { conf.Messaging.ServerCount = 1 passcode := base64.StdEncoding.EncodeToString(cipher.RandByte(8)) - conf.Apps = []node.AppConfig{ + conf.Apps = []visor.AppConfig{ {App: "skychat", Version: "1.0", Port: 1, AutoStart: true, Args: []string{}}, {App: "SSH", Version: "1.0", Port: 2, AutoStart: true, Args: []string{}}, {App: "socksproxy", Version: "1.0", Port: 3, AutoStart: true, Args: []string{"-passcode", passcode}}, @@ -103,16 +103,16 @@ func defaultConfig() *node.Config { conf.Routing.SetupNodes = []cipher.PubKey{sPK} conf.Routing.Table.Type = "boltdb" conf.Routing.Table.Location = "./skywire/routing.db" - conf.Routing.RouteFinderTimeout = node.Duration(10 * time.Second) + conf.Routing.RouteFinderTimeout = visor.Duration(10 * time.Second) - conf.Hypervisors = []node.HypervisorConfig{} + conf.Hypervisors = []visor.HypervisorConfig{} conf.AppsPath = "./apps" conf.LocalPath = "./local" conf.LogLevel = "info" - conf.ShutdownTimeout = node.Duration(10 * time.Second) + conf.ShutdownTimeout = visor.Duration(10 * time.Second) conf.Interfaces.RPCAddress = "localhost:3435" diff --git a/cmd/skywire-cli/commands/node/root.go b/cmd/skywire-cli/commands/node/root.go index a2147a1fc9..ef1780451a 100644 --- a/cmd/skywire-cli/commands/node/root.go +++ b/cmd/skywire-cli/commands/node/root.go @@ -6,7 +6,7 @@ import ( "github.com/skycoin/skycoin/src/util/logging" "github.com/spf13/cobra" - "github.com/skycoin/skywire/pkg/node" + "github.com/skycoin/skywire/pkg/visor" ) var log = logging.MustGetLogger("skywire-cli") @@ -23,10 +23,10 @@ var RootCmd = &cobra.Command{ Short: "Contains sub-commands that interact with the local Skywire Networking Node", } -func rpcClient() node.RPCClient { +func rpcClient() visor.RPCClient { client, err := rpc.Dial("tcp", rpcAddr) if err != nil { log.Fatal("RPC connection failed:", err) } - return node.NewRPCClient(client, node.RPCPrefix) + return visor.NewRPCClient(client, visor.RPCPrefix) } diff --git a/cmd/skywire-cli/commands/node/routes.go b/cmd/skywire-cli/commands/node/routes.go index b80c3ab49c..995bbf622c 100644 --- a/cmd/skywire-cli/commands/node/routes.go +++ b/cmd/skywire-cli/commands/node/routes.go @@ -12,9 +12,9 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/node" "github.com/skycoin/skywire/pkg/router" "github.com/skycoin/skywire/pkg/routing" + "github.com/skycoin/skywire/pkg/visor" ) func init() { @@ -48,7 +48,7 @@ var ruleCmd = &cobra.Command{ rule, err := rpcClient().RoutingRule(routing.RouteID(id)) internal.Catch(err) - printRoutingRules(&node.RoutingEntry{Key: rule.RouteID(), Value: rule}) + printRoutingRules(&visor.RoutingEntry{Key: rule.RouteID(), Value: rule}) }, } @@ -114,7 +114,7 @@ var addRuleCmd = &cobra.Command{ }, } -func printRoutingRules(rules ...*node.RoutingEntry) { +func printRoutingRules(rules ...*visor.RoutingEntry) { printAppRule := func(w io.Writer, id routing.RouteID, s *routing.RuleSummary) { _, err := fmt.Fprintf(w, "%d\t%s\t%d\t%d\t%s\t%d\t%s\t%s\t%s\n", id, s.Type, s.AppFields.LocalPort, s.AppFields.RemotePort, s.AppFields.RemotePK, s.AppFields.RespRID, "-", "-", s.ExpireAt) diff --git a/cmd/skywire-cli/commands/node/transports.go b/cmd/skywire-cli/commands/node/transports.go index d0a111dcc0..43b198ba80 100644 --- a/cmd/skywire-cli/commands/node/transports.go +++ b/cmd/skywire-cli/commands/node/transports.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/skycoin/skywire/cmd/skywire-cli/internal" - "github.com/skycoin/skywire/pkg/node" + "github.com/skycoin/skywire/pkg/visor" ) func init() { @@ -106,7 +106,7 @@ var rmTpCmd = &cobra.Command{ }, } -func printTransports(tps ...*node.TransportSummary) { +func printTransports(tps ...*visor.TransportSummary) { sortTransports(tps...) w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent) _, err := fmt.Fprintln(w, "type\tid\tremote\tmode") @@ -123,7 +123,7 @@ func printTransports(tps ...*node.TransportSummary) { internal.Catch(w.Flush()) } -func sortTransports(tps ...*node.TransportSummary) { +func sortTransports(tps ...*visor.TransportSummary) { sort.Slice(tps, func(i, j int) bool { return tps[i].ID.String() < tps[j].ID.String() }) diff --git a/cmd/skywire-networking-node/commands/root.go b/cmd/skywire-networking-node/commands/root.go index dbca8600df..da278981fd 100644 --- a/cmd/skywire-networking-node/commands/root.go +++ b/cmd/skywire-networking-node/commands/root.go @@ -21,12 +21,12 @@ import ( "github.com/skycoin/skycoin/src/util/logging" "github.com/spf13/cobra" - "github.com/skycoin/skywire/pkg/node" "github.com/skycoin/skywire/pkg/util/pathutil" + "github.com/skycoin/skywire/pkg/visor" ) const configEnv = "SW_CONFIG" -const defaultShutdownTimeout = node.Duration(10 * time.Second) +const defaultShutdownTimeout = visor.Duration(10 * time.Second) type runCfg struct { syslogAddr string @@ -39,8 +39,8 @@ type runCfg struct { profileStop func() logger *logging.Logger masterLogger *logging.MasterLogger - conf node.Config - node *node.Node + conf visor.Config + node *visor.Node } var cfg *runCfg @@ -58,7 +58,7 @@ var rootCmd = &cobra.Command{ waitOsSignals(). stopNode() }, - Version: node.Version, + Version: visor.Version, } func init() { @@ -134,7 +134,7 @@ func (cfg *runCfg) readConfig() *runCfg { rdr = bufio.NewReader(os.Stdin) } - cfg.conf = node.Config{} + cfg.conf = visor.Config{} if err := json.NewDecoder(rdr).Decode(&cfg.conf); err != nil { cfg.logger.Fatalf("Failed to decode %s: %s", rdr, err) } @@ -142,7 +142,7 @@ func (cfg *runCfg) readConfig() *runCfg { } func (cfg *runCfg) runNode() *runCfg { - node, err := node.NewNode(&cfg.conf, cfg.masterLogger) + node, err := visor.NewNode(&cfg.conf, cfg.masterLogger) if err != nil { cfg.logger.Fatal("Failed to initialize node: ", err) } diff --git a/pkg/hypervisor/hypervisor.go b/pkg/hypervisor/hypervisor.go index e386f26c7a..5fa6ac75b0 100644 --- a/pkg/hypervisor/hypervisor.go +++ b/pkg/hypervisor/hypervisor.go @@ -21,8 +21,8 @@ import ( "github.com/skycoin/skycoin/src/util/logging" "github.com/skycoin/skywire/pkg/httputil" - "github.com/skycoin/skywire/pkg/node" "github.com/skycoin/skywire/pkg/routing" + "github.com/skycoin/skywire/pkg/visor" ) var ( @@ -31,7 +31,7 @@ var ( type appNodeConn struct { Addr *noise.Addr - Client node.RPCClient + Client visor.RPCClient } // Node manages AppNodes. @@ -69,7 +69,7 @@ func (m *Node) ServeRPC(lis net.Listener) error { m.mu.RLock() m.nodes[addr.PK] = appNodeConn{ Addr: addr, - Client: node.NewRPCClient(rpc.NewClient(conn), node.RPCPrefix), + Client: visor.NewRPCClient(rpc.NewClient(conn), visor.RPCPrefix), } m.mu.RUnlock() } @@ -92,7 +92,7 @@ type MockConfig struct { func (m *Node) AddMockData(config MockConfig) error { r := rand.New(rand.NewSource(time.Now().UnixNano())) for i := 0; i < config.Nodes; i++ { - pk, client := node.NewMockRPCClient(r, config.MaxTpsPerNode, config.MaxRoutesPerNode) + pk, client := visor.NewMockRPCClient(r, config.MaxTpsPerNode, config.MaxRoutesPerNode) m.mu.Lock() m.nodes[pk] = appNodeConn{ Addr: &noise.Addr{ @@ -149,7 +149,7 @@ func (m *Node) ServeHTTP(w http.ResponseWriter, req *http.Request) { type summaryResp struct { TCPAddr string `json:"tcp_addr"` - *node.Summary + *visor.Summary } // provides summary of all nodes. @@ -161,7 +161,7 @@ func (m *Node) getNodes() http.HandlerFunc { summary, err := c.Client.Summary() if err != nil { log.Printf("failed to obtain summary from AppNode with pk %s. Error: %v", pk, err) - summary = &node.Summary{PubKey: pk} + summary = &visor.Summary{PubKey: pk} } summaries = append(summaries, summaryResp{ TCPAddr: c.Addr.Addr.String(), @@ -428,7 +428,7 @@ type loopResp struct { FwdRule routing.RuleForwardFields `json:"resp"` } -func makeLoopResp(info node.LoopInfo) loopResp { +func makeLoopResp(info visor.LoopInfo) loopResp { if len(info.FwdRule) == 0 || len(info.AppRule) == 0 { return loopResp{} } @@ -457,7 +457,7 @@ func (m *Node) getLoops() http.HandlerFunc { <<< Helper functions >>> */ -func (m *Node) client(pk cipher.PubKey) (*noise.Addr, node.RPCClient, bool) { +func (m *Node) client(pk cipher.PubKey) (*noise.Addr, visor.RPCClient, bool) { m.mu.RLock() conn, ok := m.nodes[pk] m.mu.RUnlock() @@ -468,13 +468,13 @@ type httpCtx struct { // Node PK cipher.PubKey Addr *noise.Addr - RPC node.RPCClient + RPC visor.RPCClient // App - App *node.AppState + App *visor.AppState // Transport - Tp *node.TransportSummary + Tp *visor.TransportSummary // Route RtKey routing.RouteID @@ -545,7 +545,7 @@ func (m *Node) tpCtx(w http.ResponseWriter, r *http.Request) (*httpCtx, bool) { } tp, err := ctx.RPC.Transport(tid) if err != nil { - if err.Error() == node.ErrNotFound.Error() { + if err.Error() == visor.ErrNotFound.Error() { httputil.WriteJSON(w, r, http.StatusNotFound, fmt.Errorf("transport of ID %s is not found", tid)) return nil, false diff --git a/pkg/node/config.go b/pkg/visor/config.go similarity index 99% rename from pkg/node/config.go rename to pkg/visor/config.go index 3f8daf8942..6e1f4044b4 100644 --- a/pkg/node/config.go +++ b/pkg/visor/config.go @@ -1,4 +1,4 @@ -package node +package visor import ( "encoding/json" diff --git a/pkg/node/config_test.go b/pkg/visor/config_test.go similarity index 99% rename from pkg/node/config_test.go rename to pkg/visor/config_test.go index abc7a6a746..a76ebcdeb9 100644 --- a/pkg/node/config_test.go +++ b/pkg/visor/config_test.go @@ -1,4 +1,4 @@ -package node +package visor import ( "encoding/json" diff --git a/pkg/node/rpc.go b/pkg/visor/rpc.go similarity index 99% rename from pkg/node/rpc.go rename to pkg/visor/rpc.go index 1465103f87..2b4711f583 100644 --- a/pkg/node/rpc.go +++ b/pkg/visor/rpc.go @@ -1,4 +1,4 @@ -package node +package visor import ( "context" diff --git a/pkg/node/rpc_client.go b/pkg/visor/rpc_client.go similarity index 99% rename from pkg/node/rpc_client.go rename to pkg/visor/rpc_client.go index 638d857226..56ff83b948 100644 --- a/pkg/node/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -1,4 +1,4 @@ -package node +package visor import ( "encoding/binary" diff --git a/pkg/node/rpc_test.go b/pkg/visor/rpc_test.go similarity index 99% rename from pkg/node/rpc_test.go rename to pkg/visor/rpc_test.go index b8ec54c11d..2deec3176f 100644 --- a/pkg/node/rpc_test.go +++ b/pkg/visor/rpc_test.go @@ -1,4 +1,4 @@ -package node +package visor import ( "context" diff --git a/pkg/node/node.go b/pkg/visor/visor.go similarity index 99% rename from pkg/node/node.go rename to pkg/visor/visor.go index 26f1dff199..c1eb638141 100644 --- a/pkg/node/node.go +++ b/pkg/visor/visor.go @@ -1,5 +1,5 @@ -// Package node implements skywire networking node. -package node +// Package visor implements skywire networking node. +package visor import ( "bufio" diff --git a/pkg/node/node_test.go b/pkg/visor/visor_test.go similarity index 99% rename from pkg/node/node_test.go rename to pkg/visor/visor_test.go index 59768e3e52..e9f7498190 100644 --- a/pkg/node/node_test.go +++ b/pkg/visor/visor_test.go @@ -1,4 +1,4 @@ -package node +package visor import ( "context"