Skip to content

Commit

Permalink
Merge branch 'mainnet' into bug/fix-create-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ivcosla committed Apr 18, 2019
2 parents 80ce3ad + b005d12 commit b312750
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,24 @@ vendorcheck: ## Run vendorcheck
# the problem is indirect dependency to github.com/sirupsen/logrus
#GO111MODULE=off vendorcheck ./cmd/therealssh-cli/...

test: ## Run tests for net
test: ## Run tests
-go clean -testcache &>/dev/null
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./internal/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/...

#${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/app/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/cipher/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/manager/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/messaging-discovery/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/node/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/route-finder/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/router/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/routing/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/setup/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/transport/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/transport-discovery/...
${OPTS} go test -tags no_ci -cover -timeout=5m ./pkg/messaging/...


install-linters: ## Install linters
- VERSION=1.13.2 ./ci_scripts/install-golangci-lint.sh
# GO111MODULE=off go get -u github.com/FiloSottile/vendorcheck
Expand Down
39 changes: 30 additions & 9 deletions cmd/skywire-node/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package commands

import (
"encoding/json"
"log"
"log/syslog"
"os"
"os/signal"
"strings"
"syscall"
"time"

logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"

"github.com/spf13/cobra"

"github.com/skycoin/skywire/internal/pathutil"
Expand All @@ -18,32 +20,46 @@ import (

const configEnv = "SW_CONFIG"

var log = logging.MustGetLogger("skywire-node")
var (
syslogAddr string
tag string
)

var rootCmd = &cobra.Command{
Use: "skywire-node [config-path]",
Short: "App Node for skywire",
Run: func(_ *cobra.Command, args []string) {
configPath := pathutil.FindConfigPath(args, 0, configEnv, pathutil.NodeDefaults())

logger := logging.MustGetLogger(tag)

if syslogAddr != "none" {
hook, err := logrus_syslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
if err != nil {
logger.Error("Unable to connect to syslog daemon")
} else {
logging.AddHook(hook)
}
}

file, err := os.Open(configPath)
if err != nil {
log.Fatalf("Failed to open config: %s", err)
logger.Fatalf("Failed to open config: %s", err)
}

conf := &node.Config{}
if err := json.NewDecoder(file).Decode(&conf); err != nil {
log.Fatalf("Failed to decode %s: %s", configPath, err)
logger.Fatalf("Failed to decode %s: %s", configPath, err)
}

node, err := node.NewNode(conf)
if err != nil {
log.Fatal("Failed to initialise node: ", err)
logger.Fatal("Failed to initialise node: ", err)
}

go func() {
if err := node.Start(); err != nil {
log.Fatal("Failed to start node: ", err)
logger.Fatal("Failed to start node: ", err)
}
}()

Expand All @@ -53,21 +69,26 @@ var rootCmd = &cobra.Command{
go func() {
select {
case <-time.After(10 * time.Second):
log.Fatal("Timeout reached: terminating")
logger.Fatal("Timeout reached: terminating")
case s := <-ch:
log.Fatalf("Received signal %s: terminating", s)
logger.Fatalf("Received signal %s: terminating", s)
}
}()

if err := node.Close(); err != nil {
if !strings.Contains(err.Error(), "closed") {
log.Fatal("Failed to close node: ", err)
logger.Fatal("Failed to close node: ", err)
}
}
},
Version: node.Version,
}

func init() {
rootCmd.Flags().StringVarP(&syslogAddr, "syslog", "", "none", "syslog server address. E.g. localhost:514")
rootCmd.Flags().StringVarP(&tag, "tag", "", "skywire", "logging tag")
}

// Execute executes root CLI command.
func Execute() {
if err := rootCmd.Execute(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/ramya-rao-a/go-outline v0.0.0-20181122025142-7182a932836a // indirect
github.com/rogpeppe/godef v1.1.1 // indirect
github.com/sdboyer/constext v0.0.0-20170321163424-836a14457353 // indirect
github.com/sirupsen/logrus v1.4.0 // indirect
github.com/sirupsen/logrus v1.4.0
github.com/skycoin/skycoin v0.25.1
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
Expand Down
5 changes: 3 additions & 2 deletions pkg/setup/mock_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire/pkg/cipher"
"github.com/skycoin/skywire/pkg/routing"
"github.com/skycoin/skywire/pkg/transport"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCreateLoop(t *testing.T) {
Expand Down

0 comments on commit b312750

Please sign in to comment.