Skip to content

Commit

Permalink
Merge branch 'mainnet' into bug/apps-create-multiple-transports-248
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuryshev committed Apr 5, 2019
2 parents 50698a0 + 179c008 commit a71ab9b
Show file tree
Hide file tree
Showing 18 changed files with 449 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ pkg/node/foo/
/skywire-cli
/therealssh-cli
/node
PK
/users.db
56 changes: 21 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $ make install # compiles and installs all binaries
**Generate default json config**

```bash
skywire-cli gen-config
$ skywire-cli node gen-config
```

### Run `skywire-node`
Expand All @@ -88,37 +88,23 @@ The `skywire-cli` tool is used to control the `skywire-node`. Refer to the help
```bash
$ skywire-cli -h

# Command Line Interface for skywire
#
# Usage:
# skywire-cli [command]
#
# Available Commands:
# add-rule adds a new routing rule
# add-transport adds a new transport
# apps lists apps running on the node
# find-routes lists available routes between two nodes via route finder service
# find-transport finds and lists transport(s) of given transport ID or edge public key from transport discovery
# gen-config Generate default config file
# help Help about any command
# list-rules lists the local node's routing rules
# list-transports lists the available transports with optional filter flags
# messaging manage operations with messaging services
# pk get public key of node
# rm-rule removes a routing rule via route ID key
# rm-transport removes transport with given id
# rule returns a routing rule via route ID key
# set-app-autostart sets the autostart flag for an app of given name
# start-app starts an app of given name
# stop-app stops an app of given name
# transport returns summary of given transport by id
# transport-types lists transport types used by the local node
#
# Flags:
# -h, --help help for skywire-cli
# --rpc string RPC server address (default "localhost:3435")
#
# Use "skywire-cli [command] --help" for more information about a command.
# Command Line Interface for skywire
#
# Usage:
# skywire-cli [command]
#
# Available Commands:
# help Help about any command
# mdisc Contains sub-commands that interact with a remote Messaging Discovery
# node Contains sub-commands that interact with the local Skywire (App) Node
# rtfind Queries the Route Finder for available routes between two nodes
# tpdisc Queries the Transport Discovery to find transport(s) of given transport ID or edge public key
#
# Flags:
# -h, --help help for skywire-cli
#
# Use "skywire-cli [command] --help" for more information about a command.

```

### Apps
Expand All @@ -138,10 +124,10 @@ Transports can be established via the `skywire-cli`.

```bash
# Establish transport to `0276ad1c5e77d7945ad6343a3c36a8014f463653b3375b6e02ebeaa3a21d89e881`.
$ skywire-cli add-transport 0276ad1c5e77d7945ad6343a3c36a8014f463653b3375b6e02ebeaa3a21d89e881
$ skywire-cli node add-tp 0276ad1c5e77d7945ad6343a3c36a8014f463653b3375b6e02ebeaa3a21d89e881

# List established transports.
$ skywire-cli transports list
$ skywire-cli node ls-tp
```

## App programming API
Expand Down Expand Up @@ -309,7 +295,7 @@ $ GO111MODULE=on GOOS=linux go build -o /tmp/SKYNODE/apps/therealproxy.v1.0 ./cm
$ GO111MODULE=on GOOS=linux go build -o /tmp/SKYNODE/apps/therealssh.v1.0 ./cmd/apps/therealssh
$ GO111MODULE=on GOOS=linux go build -o /tmp/SKYNODE/apps/therealssh-client.v1.0 ./cmd/apps/therealssh-client
# 4. Create skywire-config.json for node
$ skywire-cli gen-config -o /tmp/SKYNODE/skywire-config.json
$ skywire-cli node gen-config -o /tmp/SKYNODE/skywire-config.json
# 2019/03/15 16:43:49 Done!
$ tree /tmp/SKYNODE
# /tmp/SKYNODE
Expand Down
8 changes: 0 additions & 8 deletions cmd/skywire-cli/README.org

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package mdisc

import (
"context"
Expand All @@ -9,62 +9,63 @@ import (

"github.com/spf13/cobra"

"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/messaging-discovery/client"
)

var mdAddr string

func init() {
rootCmd.AddCommand(messagingCmd)
RootCmd.PersistentFlags().StringVar(&mdAddr, "addr", "https://messaging.discovery.skywire.skycoin.net", "address of messaging discovery server")
}

var mdAddr string

var messagingCmd = &cobra.Command{
Use: "messaging",
Short: "manage operations with messaging services",
// RootCmd is the command that contains sub-commands which interacts with messaging services.
var RootCmd = &cobra.Command{
Use: "mdisc",
Short: "Contains sub-commands that interact with a remote Messaging Discovery",
}

func init() {
messagingCmd.PersistentFlags().StringVar(&mdAddr, "addr", "https://messaging.discovery.skywire.skycoin.net", "address of messaging discovery server")

messagingCmd.AddCommand(
mEntryCmd,
mAvailableServersCmd)
RootCmd.AddCommand(
entryCmd,
availableServersCmd,
)
}

var mEntryCmd = &cobra.Command{
var entryCmd = &cobra.Command{
Use: "entry <node-public-key>",
Short: "fetch entry from messaging-discovery",
Short: "fetches an entry from messaging-discovery",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
pk := parsePK("node-public-key", args[0])
pk := internal.ParsePK("node-public-key", args[0])
entry, err := client.NewHTTP(mdAddr).Entry(ctx, pk)
catch(err)
internal.Catch(err)
fmt.Println(entry)
},
}

var mAvailableServersCmd = &cobra.Command{
var availableServersCmd = &cobra.Command{
Use: "available-servers",
Short: "fetch available servers from messaging-discovery",
Run: func(_ *cobra.Command, _ []string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
entries, err := client.NewHTTP(mdAddr).AvailableServers(ctx)
catch(err)
internal.Catch(err)
printAvailableServers(entries)
},
}

func printAvailableServers(entries []*client.Entry) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err := fmt.Fprintln(w, "version\tregistered\tpublic-key\taddress\tport\tconns")
catch(err)
internal.Catch(err)
for _, entry := range entries {
_, err := fmt.Fprintf(w, "%s\t%d\t%s\t%s\t%s\t%d\n",
entry.Version, entry.Timestamp, entry.Static, entry.Server.Address, entry.Server.Port, entry.Server.AvailableConnections)
catch(err)
internal.Catch(err)
}
catch(w.Flush())
internal.Catch(w.Flush())
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package node

import (
"fmt"
Expand All @@ -8,64 +8,65 @@ import (

"github.com/spf13/cobra"

"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/node"
)

func init() {
rootCmd.AddCommand(
appsCmd,
RootCmd.AddCommand(
lsAppsCmd,
startAppCmd,
stopAppCmd,
setAppAutostartCmd,
)
}

var appsCmd = &cobra.Command{
Use: "apps",
Short: "lists apps running on the node",
var lsAppsCmd = &cobra.Command{
Use: "ls-apps",
Short: "Lists apps running on the local node",
Run: func(_ *cobra.Command, _ []string) {
states, err := rpcClient().Apps()
catch(err)
internal.Catch(err)

w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', tabwriter.TabIndent)
_, err = fmt.Fprintln(w, "app\tports\tauto_start\tstatus")
catch(err)
internal.Catch(err)

for _, state := range states {
status := "stopped"
if state.Status == node.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)
catch(err)
internal.Catch(err)
}
catch(w.Flush())
internal.Catch(w.Flush())
},
}

var startAppCmd = &cobra.Command{
Use: "start-app <name>",
Short: "starts an app of given name",
Short: "Starts an app of given name",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
catch(rpcClient().StartApp(args[0]))
internal.Catch(rpcClient().StartApp(args[0]))
fmt.Println("OK")
},
}

var stopAppCmd = &cobra.Command{
Use: "stop-app <name>",
Short: "stops an app of given name",
Short: "Stops an app of given name",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
catch(rpcClient().StopApp(args[0]))
internal.Catch(rpcClient().StopApp(args[0]))
fmt.Println("OK")
},
}

var setAppAutostartCmd = &cobra.Command{
Use: "set-app-autostart <name> (on|off)",
Short: "sets the autostart flag for an app of given name",
Short: "Sets the autostart flag for an app of given name",
Args: cobra.MinimumNArgs(2),
Run: func(_ *cobra.Command, args []string) {
var autostart bool
Expand All @@ -75,9 +76,9 @@ var setAppAutostartCmd = &cobra.Command{
case "off":
autostart = false
default:
catch(fmt.Errorf("invalid args[1] value: %s", args[1]))
internal.Catch(fmt.Errorf("invalid args[1] value: %s", args[1]))
}
catch(rpcClient().SetAutoStart(args[0], autostart))
internal.Catch(rpcClient().SetAutoStart(args[0], autostart))
fmt.Println("OK")
},
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package node

import (
"encoding/base64"
Expand All @@ -12,22 +12,25 @@ import (
"github.com/skycoin/skywire/pkg/node"
)

func init() {
RootCmd.AddCommand(genConfigCmd)
}

var (
output string
replace bool
configLocType = pathutil.WorkingDirLoc
)

func init() {
rootCmd.AddCommand(genConfigCmd)
genConfigCmd.Flags().StringVarP(&output, "output", "o", "", "path of output config file. Uses default of 'type' flag if unspecified.")
genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, "whether to allow rewrite of a file that already exists.")
genConfigCmd.Flags().VarP(&configLocType, "type", "m", fmt.Sprintf("config generation mode. Valid values: %v", pathutil.AllConfigLocationTypes()))
}

var genConfigCmd = &cobra.Command{
Use: "gen-config",
Short: "Generate default config file",
Short: "Generates a config file",
PreRun: func(_ *cobra.Command, _ []string) {
if output == "" {
output = pathutil.NodeDefaults().Get(configLocType)
Expand Down Expand Up @@ -59,7 +62,6 @@ func homeConfig() *node.Config {
c.AppsPath = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/apps")
c.Transport.LogStore.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/transport_logs")
c.Routing.Table.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/routing.db")

return c
}

Expand All @@ -68,7 +70,6 @@ func localConfig() *node.Config {
c.AppsPath = "/usr/local/skycoin/skywire/apps"
c.Transport.LogStore.Location = "/usr/local/skycoin/skywire/transport_logs"
c.Routing.Table.Location = "/usr/local/skycoin/skywire/routing.db"

return c
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package commands
package node

import (
"fmt"
Expand All @@ -7,12 +7,12 @@ import (
)

func init() {
rootCmd.AddCommand(pkCmd)
RootCmd.AddCommand(pkCmd)
}

var pkCmd = &cobra.Command{
Use: "pk",
Short: "get public key of node",
Short: "Obtains the public key of the node",
Run: func(_ *cobra.Command, _ []string) {

client := rpcClient()
Expand Down
32 changes: 32 additions & 0 deletions cmd/skywire-cli/commands/node/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package node

import (
"net/rpc"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/pkg/node"
)

var log = logging.MustGetLogger("skywire-cli")

var rpcAddr string

func init() {
RootCmd.PersistentFlags().StringVarP(&rpcAddr, "rpc", "", "localhost:3435", "RPC server address")
}

// RootCmd contains commands that interact with the skywire-node
var RootCmd = &cobra.Command{
Use: "node",
Short: "Contains sub-commands that interact with the local Skywire (App) Node",
}

func rpcClient() node.RPCClient {
client, err := rpc.Dial("tcp", rpcAddr)
if err != nil {
log.Fatal("RPC connection failed:", err)
}
return node.NewRPCClient(client, node.RPCPrefix)
}
Loading

0 comments on commit a71ab9b

Please sign in to comment.