Skip to content

Commit

Permalink
Merge branch 'mainnet' into feature/remove-transport-manager-dependency
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/router/router.go
#	pkg/setup/node_test.go
#	pkg/transport/manager.go
  • Loading branch information
nkryuchkov committed Jul 17, 2019
2 parents 8d65884 + 1d4b619 commit e9d9cc1
Show file tree
Hide file tree
Showing 80 changed files with 893 additions and 367 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
.idea/

/skywire.json
/*-config.json
/apps/
/skywire/
/local*
Expand Down
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ issues:
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- "G304: Potential file inclusion via variable"
- "G204: Subprocess launched with variable"
- "G104: Errors unhandled"
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked

# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
Expand All @@ -192,4 +188,4 @@ issues:
# large codebase. It's not practical to fix all existing issues at the moment
# of integration: much better don't allow issues in new code.
# Default is false.
new: false
new: false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
- [2. Get an IP of node](#2-get-an-ip-of-node)
- [3. Open in browser containerized `skychat` application](#3-open-in-browser-containerized-skychat-application)
- [4. Create new dockerized `skywire-visors`](#4-create-new-dockerized-skywire-visors)
- [5. Env-vars for develoment-/testing- purposes](#5-env-vars-for-develoment-testing--purposes)
- [5. Env-vars for development-/testing- purposes](#5-env-vars-for-development-testing--purposes)
- [6. "Hello-Mike-Hello-Joe" test](#6-hello-mike-hello-joe-test)

## Notes on this release
Expand Down Expand Up @@ -424,7 +424,7 @@ Instead of skywire-runner you can use:
- `golang`, `buildpack-deps:stretch-scm` "as is"
- and `debian`, `ubuntu` - after `apt-get install ca-certificates` in them. Look in `skywire-runner.Dockerfile` for example

#### 5. Env-vars for develoment-/testing- purposes
#### 5. Env-vars for development-/testing- purposes

```bash
export SW_NODE_A=127.0.0.1
Expand Down
4 changes: 2 additions & 2 deletions ci_scripts/run-internal-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m

go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealproxy -run TestProxy >> ./logs/internal/TestProxy.log

go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestListAuthoriser >> ./logs/internal/TestListAuthoriser.log
go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestFileAuthoriser >> ./logs/internal/TestFileAuthoriser.log
go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestListAuthorizer >> ./logs/internal/TestListAuthorizer.log
go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestFileAuthorizer >> ./logs/internal/TestFileAuthorizer.log
go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestChannelServe >> ./logs/internal/TestChannelServe.log
go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestChannelSendWrite >> ./logs/internal/TestChannelSendWrite.log
go clean -testcache &>/dev/null || go test -race -tags no_ci -cover -timeout=5m github.com/skycoin/skywire/internal/therealssh -run TestChannelRead >> ./logs/internal/TestChannelRead.log
Expand Down
12 changes: 8 additions & 4 deletions cmd/apps/helloworld/helloworld.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import (
func main() {
helloworldApp, err := app.Setup(&app.Config{AppName: "helloworld", AppVersion: "1.0", ProtocolVersion: "0.0.1"})
if err != nil {
log.Fatal("Setup failure: ", err)
log.Fatal("Setup failure:", err)
}
defer helloworldApp.Close()
defer func() {
if err := helloworldApp.Close(); err != nil {
log.Println("Failed to close app: ", err)
}
}()

if len(os.Args) == 1 {
log.Println("listening for incoming connections")
Expand All @@ -32,12 +36,12 @@ func main() {
go func() {
buf := make([]byte, 4)
if _, err := conn.Read(buf); err != nil {
log.Println("Failed to read remote data: ", err)
log.Println("Failed to read remote data:", err)
}

log.Printf("Message from %s: %s", conn.RemoteAddr().String(), string(buf))
if _, err := conn.Write([]byte("pong")); err != nil {
log.Println("Failed to write to a remote node: ", err)
log.Println("Failed to write to a remote node:", err)
}
}()
}
Expand Down
15 changes: 11 additions & 4 deletions cmd/apps/skychat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func main() {
if err != nil {
log.Fatal("Setup failure: ", err)
}
defer func() { _ = a.Close() }()
defer func() {
if err := a.Close(); err != nil {
log.Println("Failed to close app:", err)
}
}()

chatApp = a

Expand All @@ -61,7 +65,7 @@ func listenLoop() {
for {
conn, err := chatApp.Accept()
if err != nil {
log.Println("failed to accept conn: ", err)
log.Println("failed to accept conn:", err)
return
}

Expand All @@ -80,11 +84,14 @@ func handleConn(conn net.Conn) {
buf := make([]byte, 32*1024)
n, err := conn.Read(buf)
if err != nil {
log.Println("failed to read packet: ", err)
log.Println("failed to read packet:", err)
return
}

clientMsg, _ := json.Marshal(map[string]string{"sender": raddr.PubKey.Hex(), "message": string(buf[:n])}) // nolint
clientMsg, err := json.Marshal(map[string]string{"sender": raddr.PubKey.Hex(), "message": string(buf[:n])})
if err != nil {
log.Printf("Failed to marshal json: %v", err)
}
select {
case clientCh <- string(clientMsg):
log.Printf("received and sent to ui: %s\n", clientMsg)
Expand Down
6 changes: 5 additions & 1 deletion cmd/apps/therealproxy-client/therealproxy-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func main() {
if err != nil {
log.Fatal("Setup failure: ", err)
}
defer socksApp.Close()
defer func() {
if err := socksApp.Close(); err != nil {
log.Println("Failed to close app:", err)
}
}()

if *serverPK == "" {
log.Fatal("Invalid server PubKey")
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps/therealproxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Create 2 node config files:
- `skywire1.json`

```json
{
{
"apps": [
{
"app": "socksproxy",
Expand Down
6 changes: 5 additions & 1 deletion cmd/apps/therealproxy/therealproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ func main() {
if err != nil {
log.Fatal("Setup failure: ", err)
}
defer socksApp.Close()
defer func() {
if err := socksApp.Close(); err != nil {
log.Println("Failed to close app:", err)
}
}()

srv, err := therealproxy.NewServer(*passcode)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions cmd/apps/therealssh-client/therealssh-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ func main() {
if err != nil {
log.Fatal("Setup failure: ", err)
}
defer sshApp.Close()
defer func() {
if err := sshApp.Close(); err != nil {
log.Println("Failed to close app:", err)
}
}()

ssh.Debug = *debug

rpc, client, err := ssh.NewClient(*rpcAddr, sshApp)
if err != nil {
log.Fatal("Client setup failure: ", err)
}
defer client.Close()
defer func() {
if err := client.Close(); err != nil {
log.Println("Failed to close client:", err)
}
}()

if err := http.Serve(rpc, nil); err != nil {
log.Fatal("Failed to start RPC interface: ", err)
Expand Down
16 changes: 12 additions & 4 deletions cmd/apps/therealssh/therealssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"flag"
"log"

homedir "github.com/mitchellh/go-homedir"
"github.com/mitchellh/go-homedir"

ssh "github.com/skycoin/skywire/internal/therealssh"
"github.com/skycoin/skywire/pkg/app"
Expand All @@ -24,7 +24,11 @@ func main() {
if err != nil {
log.Fatal("Setup failure: ", err)
}
defer sshApp.Close()
defer func() {
if err := sshApp.Close(); err != nil {
log.Println("Failed to close app:", err)
}
}()

path, err := homedir.Expand(*authFile)
if err != nil {
Expand All @@ -35,11 +39,15 @@ func main() {

auth, err := ssh.NewFileAuthorizer(path)
if err != nil {
log.Fatal("Failed to setup Authoriser: ", err)
log.Fatal("Failed to setup Authorizer: ", err)
}

server := ssh.NewServer(auth)
defer server.Close()
defer func() {
if err := server.Close(); err != nil {
log.Println("Failed to close server:", err)
}
}()

for {
conn, err := sshApp.Accept()
Expand Down
7 changes: 4 additions & 3 deletions cmd/messaging-server/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"net"
"net/http"
"os"
"path/filepath"

"github.com/prometheus/client_golang/prometheus/promhttp"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/dmsg"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/disc"
Expand Down Expand Up @@ -56,7 +57,7 @@ var rootCmd = &cobra.Command{
logging.SetLevel(logLevel)

if syslogAddr != "" {
hook, err := logrus_syslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
hook, err := logrussyslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
if err != nil {
logger.Fatalf("Unable to connect to syslog daemon on %v", syslogAddr)
}
Expand Down Expand Up @@ -97,7 +98,7 @@ func parseConfig(configFile string) *Config {
var rdr io.Reader
var err error
if !cfgFromStdin {
rdr, err = os.Open(configFile)
rdr, err = os.Open(filepath.Clean(configFile))
if err != nil {
log.Fatalf("Failed to open config: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/setup-node/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"os"

"github.com/prometheus/client_golang/prometheus/promhttp"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

Expand All @@ -33,7 +33,7 @@ var rootCmd = &cobra.Command{

logger := logging.MustGetLogger(tag)
if syslogAddr != "" {
hook, err := logrus_syslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
hook, err := logrussyslog.NewSyslogHook("udp", syslogAddr, syslog.LOG_INFO, tag)
if err != nil {
logger.Fatalf("Unable to connect to syslog daemon on %v", syslogAddr)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/skywire-cli/commands/node/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ func defaultConfig() *visor.Config {
conf.Transport.LogStore.Location = "./skywire/transport_logs"

conf.Routing.RouteFinder = "https://routefinder.skywire.skycoin.net/"

const defaultSetupNodePK = "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557"
sPK := cipher.PubKey{}
sPK.UnmarshalText([]byte("0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557")) // nolint: errcheck
if err := sPK.UnmarshalText([]byte(defaultSetupNodePK)); err != nil {
log.WithError(err).Warnf("Failed to unmarshal default setup node public key %s", defaultSetupNodePK)
}
conf.Routing.SetupNodes = []cipher.PubKey{sPK}
conf.Routing.Table.Type = "boltdb"
conf.Routing.Table.Location = "./skywire/routing.db"
Expand Down
6 changes: 5 additions & 1 deletion cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package commands

import (
"log"

"github.com/spf13/cobra"

"github.com/skycoin/skywire/cmd/skywire-cli/commands/mdisc"
Expand All @@ -25,5 +27,7 @@ func init() {

// Execute executes root CLI command.
func Execute() {
_ = rootCmd.Execute() //nolint:errcheck
if err := rootCmd.Execute(); err != nil {
log.Fatal("Failed to execute command: ", err)
}
}
9 changes: 5 additions & 4 deletions cmd/skywire-visor/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (
"log"
"log/syslog"
"net/http"
_ "net/http/pprof" // no_lint
_ "net/http/pprof" // used for HTTP profiling
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/pkg/profile"
logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/skycoin/src/util/logging"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -109,7 +110,7 @@ func (cfg *runCfg) startLogger() *runCfg {
cfg.logger = cfg.masterLogger.PackageLogger(cfg.tag)

if cfg.syslogAddr != "none" {
hook, err := logrus_syslog.NewSyslogHook("udp", cfg.syslogAddr, syslog.LOG_INFO, cfg.tag)
hook, err := logrussyslog.NewSyslogHook("udp", cfg.syslogAddr, syslog.LOG_INFO, cfg.tag)
if err != nil {
cfg.logger.Error("Unable to connect to syslog daemon:", err)
} else {
Expand All @@ -125,7 +126,7 @@ func (cfg *runCfg) readConfig() *runCfg {
var err error
if !cfg.cfgFromStdin {
configPath := pathutil.FindConfigPath(cfg.args, 0, configEnv, pathutil.NodeDefaults())
rdr, err = os.Open(configPath)
rdr, err = os.Open(filepath.Clean(configPath))
if err != nil {
cfg.logger.Fatalf("Failed to open config: %s", err)
}
Expand Down
20 changes: 13 additions & 7 deletions cmd/therealssh-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
ssh "github.com/skycoin/skywire/internal/therealssh"
)

var (
rpcAddr string
)
var rpcAddr string

var rootCmd = &cobra.Command{
Use: "SSH-cli [user@]remotePK [command] [args...]",
Expand Down Expand Up @@ -55,7 +53,11 @@ var rootCmd = &cobra.Command{
if err := client.Call("RPCClient.RequestPTY", ptyArgs, &channelID); err != nil {
log.Fatal("Failed to request PTY:", err)
}
defer client.Call("RPCClient.Close", &channelID, nil) // nolint: errcheck
defer func() {
if err := client.Call("RPCClient.Close", &channelID, nil); err != nil {
log.Printf("Failed to close RPC client: %v", err)
}
}()

var socketPath string
execArgs := &ssh.ExecArgs{ChannelID: channelID, CommandWithArgs: args[1:]}
Expand All @@ -82,13 +84,13 @@ var rootCmd = &cobra.Command{
for range ch {
size, err := pty.GetsizeFull(os.Stdin)
if err != nil {
log.Println("Failed to change pty size: ", err)
log.Println("Failed to change pty size:", err)
return
}

var result int
if err := client.Call("RPCClient.WindowChange", &ssh.WindowChangeArgs{ChannelID: channelID, Size: size}, &result); err != nil {
log.Println("Failed to change pty size: ", err)
log.Println("Failed to change pty size:", err)
}
}
}()
Expand All @@ -97,7 +99,11 @@ var rootCmd = &cobra.Command{
if err != nil {
log.Fatal("Failed to set terminal to raw mode:", err)
}
defer terminal.Restore(int(os.Stdin.Fd()), oldState) // nolint
defer func() {
if err := terminal.Restore(int(os.Stdin.Fd()), oldState); err != nil {
log.Printf("Failed to restore terminal: %v", err)
}
}()

go func() {
if _, err := io.Copy(conn, os.Stdin); err != nil {
Expand Down
Loading

0 comments on commit e9d9cc1

Please sign in to comment.