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 1, 2019
2 parents 5729dc5 + 13ddad2 commit 8c4ce43
Show file tree
Hide file tree
Showing 28 changed files with 2,473 additions and 327 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
.idea/

/skywire.json
/skywire-config.json
/manager-config.json
/apps/
/skywire/
/local/
Expand Down
88 changes: 44 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ $ make install # compiles and installs all binaries
**Generate default json config**

```bash
skywire-cli config
skywire-cli gen-config
```

### Run `skywire-node`

`skywire-node` hosts apps, proxies app's requests to remote nodes and exposes communication API that apps can use to implement communication protocols. App binaries are spawned by the node, communication between node and app is performed via unix pipes provided on app startup.

```bash
# Run skywire-node. It takes one argument; the path of a configuration file (`skywire.json` if unspecified).
$ skywire-node skywire.json
# Run skywire-node. It takes one argument; the path of a configuration file (`skywire-config.json` if unspecified).
$ skywire-node skywire-config.json
```

### Run `skywire-node` in docker container
Expand All @@ -88,42 +88,42 @@ 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
# config Generate default config file
# 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
# 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
# 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:
# 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.
```

### Apps

After `skywire-node` is up and running with default environment, default apps are run with the configuration specified in `skywire.json`. Refer to the following for usage of the default apps:
After `skywire-node` is up and running with default environment, default apps are run with the configuration specified in `skywire-config.json`. Refer to the following for usage of the default apps:

- [Chat](/cmd/apps/chat)
- [Hello World](/cmd/apps/helloworld)
Expand Down Expand Up @@ -193,7 +193,7 @@ This will:

#### Structure of `./node`

```bash
```
./node
├── apps # node `apps` compiled with DOCKER_OPTS
│   ├── chat.v1.0 #
Expand All @@ -203,14 +203,14 @@ This will:
│   ├── therealssh-client.v1.0 #
│   └── therealssh.v1.0 #
├── local # **Created inside docker**
│   ├── chat # according to "local_path" in skywire.json
│   ├── chat # according to "local_path" in skywire-config.json
│   ├── therealproxy #
│   └── therealssh #
├── PK # contains public key of node
├── skywire # db & logs. **Created inside docker**
│   ├── routing.db #
│   └── transport_logs #
├── skywire.json # config of node
├── skywire-config.json # config of node
└── skywire-node # `skywire-node binary` compiled with DOCKER_OPTS
```

Expand Down Expand Up @@ -275,7 +275,7 @@ Default value: "GO111MODULE=on GOOS=linux"
#### 1. Get Public Key of docker-node

```bash
$ cat ./node/skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' '
$ cat ./node/skywire-config.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' '
# 029be6fa68c13e9222553035cc1636d98fb36a888aa569d9ce8aa58caa2c651b45
```

Expand Down Expand Up @@ -308,8 +308,8 @@ $ GO111MODULE=on GOOS=linux go build -o /tmp/SKYNODE/apps/helloworld.v1.0 ./cmd/
$ GO111MODULE=on GOOS=linux go build -o /tmp/SKYNODE/apps/therealproxy.v1.0 ./cmd/apps/therealproxy
$ 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.json for node
$ skywire-cli config /tmp/SKYNODE/skywire.json
# 4. Create skywire-config.json for node
$ skywire-cli gen-config -o /tmp/SKYNODE/skywire-config.json
# 2019/03/15 16:43:49 Done!
$ tree /tmp/SKYNODE
# /tmp/SKYNODE
Expand All @@ -319,7 +319,7 @@ $ tree /tmp/SKYNODE
# │   ├── therealproxy.v1.0
# │   ├── therealssh-client.v1.0
# │   └── therealssh.v1.0
# ├── skywire.json
# ├── skywire-config.json
# └── skywire-node
# So far so good. We prepared docker volume. Now we can:
$ docker run -it -v /tmp/SKYNODE:/sky --network=SKYNET --name=SKYNODE skywire-runner bash -c "cd /sky && ./skywire-node"
Expand Down Expand Up @@ -353,9 +353,9 @@ Instead of skywire-runner you can use:

```bash
export SW_NODE_A=127.0.0.1
export SW_NODE_A_PK=$(cat ./skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ')
export SW_NODE_A_PK=$(cat ./skywire-config.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ')
export SW_NODE_B=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' SKY01)
export SW_NODE_B_PK=$(cat ./node/skywire.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ')
export SW_NODE_B_PK=$(cat ./node/skywire-config.json|grep static_public_key |cut -d ':' -f2 |tr -d '"'','' ')
```

#### 6. "Hello-Mike-Hello-Joe" test
Expand Down
10 changes: 10 additions & 0 deletions cmd/manager-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

Manager node exposes node management operations via web API.

**Generate config file:**

```bash

```

**Run with mock data:**

```bash
# Generate config file.
$ manager-node gen-config

# Run.
$ manager-node --mock
```

Expand Down
54 changes: 54 additions & 0 deletions cmd/manager-node/commands/gen-config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package commands

import (
"fmt"
"path/filepath"

"github.com/skycoin/skywire/internal/pathutil"

"github.com/spf13/cobra"

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

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: "generates a configuration file",
PreRun: func(_ *cobra.Command, _ []string) {
if output == "" {
output = pathutil.ManagerDefaults().Get(configLocType)
log.Infof("no 'output,o' flag is empty, using default path: %s", output)
}
var err error
if output, err = filepath.Abs(output); err != nil {
log.WithError(err).Fatalln("invalid output provided")
}
},
Run: func(_ *cobra.Command, _ []string) {
var conf manager.Config
switch configLocType {
case pathutil.WorkingDirLoc:
conf = manager.GenerateWorkDirConfig()
case pathutil.HomeLoc:
conf = manager.GenerateHomeConfig()
case pathutil.LocalLoc:
conf = manager.GenerateLocalConfig()
default:
log.Fatalln("invalid config type:", configLocType)
}
pathutil.WriteJSONConfig(conf, output, replace)
},
}
57 changes: 29 additions & 28 deletions cmd/manager-node/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,52 @@ import (
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/pkg/cipher"
"github.com/skycoin/skywire/internal/pathutil"
"github.com/skycoin/skywire/pkg/manager"
)

const configEnv = "SW_MANAGER_CONFIG"

var (
pk cipher.PubKey
sk cipher.SecKey
rpcAddr string
httpAddr string
log = logging.MustGetLogger("manager-node")

mock bool
mockNodes int
mockMaxTps int
mockMaxRoutes int

log = logging.MustGetLogger("manager-node")
)

func init() {
rootCmd.PersistentFlags().Var(&pk, "pk", "manager node's public key")
rootCmd.PersistentFlags().Var(&sk, "sk", "manager node's secret key")
rootCmd.PersistentFlags().StringVar(&httpAddr, "http-addr", ":8080", "address to serve HTTP RESTful API and Web interface")

rootCmd.Flags().StringVar(&rpcAddr, "rpc-addr", ":7080", "address to serve RPC client interface")
rootCmd.Flags().BoolVar(&mock, "mock", false, "whether to run manager node with mock data")
rootCmd.Flags().IntVar(&mockNodes, "mock-nodes", 5, "number of app nodes to have in mock mode")
rootCmd.Flags().IntVar(&mockMaxTps, "mock-max-tps", 10, "max number of transports per mock app node")
rootCmd.Flags().IntVar(&mockMaxRoutes, "mock-max-routes", 10, "max number of routes per node")
}

var rootCmd = &cobra.Command{
Use: "manager-node",
Use: "manager-node [config-path]",
Short: "Manages Skywire App Nodes",
PreRun: func(_ *cobra.Command, _ []string) {
if pk.Null() && sk.Null() {
pk, sk = cipher.GenerateKeyPair()
log.Println("No keys are set. Randomly generating...")
Run: func(_ *cobra.Command, args []string) {
configPath := pathutil.FindConfigPath(args, 0, configEnv, pathutil.ManagerDefaults())

var config manager.Config
config.FillDefaults()
if err := config.Parse(configPath); err != nil {
log.WithError(err).Fatalln("failed to parse config file")
}
cPK, err := sk.PubKey()
fmt.Println(config)

var (
httpAddr = config.Interfaces.HTTPAddr
rpcAddr = config.Interfaces.RPCAddr
)

m, err := manager.NewNode(config)
if err != nil {
log.Fatalln("Key pair check failed:", err)
}
if cPK != pk {
log.Fatalln("SK and PK provided do not match.")
log.Fatalln("Failed to start manager:", err)
}
log.Println("PK:", pk)
log.Println("SK:", sk)
},
Run: func(_ *cobra.Command, _ []string) {
m := manager.NewNode(pk, sk)

log.Infof("serving RPC on '%s'", rpcAddr)
go func() {
l, err := net.Listen("tcp", rpcAddr)
if err != nil {
Expand All @@ -67,8 +64,9 @@ var rootCmd = &cobra.Command{
log.Fatalln("Failed to serve RPC:", err)
}
}()

if mock {
err := m.AddMockData(&manager.MockConfig{
err := m.AddMockData(manager.MockConfig{
Nodes: mockNodes,
MaxTpsPerNode: mockMaxTps,
MaxRoutesPerNode: mockMaxRoutes,
Expand All @@ -77,9 +75,12 @@ var rootCmd = &cobra.Command{
log.Fatalln("Failed to add mock data:", err)
}
}

log.Infof("serving HTTP on '%s'", httpAddr)
if err := http.ListenAndServe(httpAddr, m); err != nil {
log.Fatalln("Manager exited with error:", err)
}

log.Println("Good bye!")
},
}
Expand Down
Loading

0 comments on commit 8c4ce43

Please sign in to comment.