Skip to content

Commit

Permalink
Updated config generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Lin committed Sep 30, 2019
1 parent 7eccea4 commit 47dcb67
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 144 deletions.
9 changes: 5 additions & 4 deletions cmd/apps/skychat/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"sync"
"time"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/skycoin/src/util/logging"

Expand All @@ -22,7 +24,7 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
)

var addr = flag.String("addr", ":8000", "address to bind")
var addr = flag.String("addr", skyenv.SkychatAddr, "address to bind")
var r = netutil.NewRetrier(50*time.Millisecond, 5, 2)

var (
Expand All @@ -34,11 +36,10 @@ var (
)

func main() {
appName := "skychat"
log = app.NewLogger(appName)
log = app.NewLogger(skyenv.SkychatName)
flag.Parse()

a, err := app.Setup(&app.Config{AppName: appName, AppVersion: "1.0", ProtocolVersion: "0.0.1"})
a, err := app.Setup(&app.Config{AppName: skyenv.SkychatName, AppVersion: skyenv.SkychatVersion, ProtocolVersion: skyenv.AppProtocolVersion})
if err != nil {
log.Fatal("Setup failure: ", err)
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/apps/therealproxy-client/therealproxy-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net"
"time"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/dmsg/cipher"

"github.com/SkycoinProject/skywire-mainnet/internal/netutil"
Expand All @@ -16,19 +18,17 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
)

const socksPort = 3

var r = netutil.NewRetrier(time.Second, 0, 1)

func main() {
log := app.NewLogger("socksproxy-client")
therealproxy.Log = log.PackageLogger("therealproxy")
log := app.NewLogger(skyenv.SkyproxyClientName)
therealproxy.Log = log.PackageLogger(skyenv.SkyproxyClientName)

var addr = flag.String("addr", ":1080", "Client address to listen on")
var addr = flag.String("addr", skyenv.SkyproxyClientAddr, "Client address to listen on")
var serverPK = flag.String("srv", "", "PubKey of the server to connect to")
flag.Parse()

config := &app.Config{AppName: "socksproxy-client", AppVersion: "1.0", ProtocolVersion: "0.0.1"}
config := &app.Config{AppName: skyenv.SkyproxyClientName, AppVersion: skyenv.SkyproxyClientVersion, ProtocolVersion: skyenv.AppProtocolVersion}
socksApp, err := app.Setup(config)
if err != nil {
log.Fatal("Setup failure: ", err)
Expand All @@ -50,7 +50,7 @@ func main() {

var conn net.Conn
err = r.Do(func() error {
conn, err = socksApp.Dial(routing.Addr{PubKey: pk, Port: routing.Port(socksPort)})
conn, err = socksApp.Dial(routing.Addr{PubKey: pk, Port: routing.Port(skyenv.SkyproxyPort)})
return err
})
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions cmd/apps/therealproxy/therealproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ package main
import (
"flag"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/skywire-mainnet/internal/therealproxy"
"github.com/SkycoinProject/skywire-mainnet/pkg/app"
)

func main() {
log := app.NewLogger("socksproxy")
therealproxy.Log = log.PackageLogger("therealproxy")
log := app.NewLogger(skyenv.SkyproxyName)
therealproxy.Log = log.PackageLogger(skyenv.SkyproxyName)

var passcode = flag.String("passcode", "", "Authorize user against this passcode")
flag.Parse()

config := &app.Config{AppName: "socksproxy", AppVersion: "1.0", ProtocolVersion: "0.0.1"}
config := &app.Config{AppName: skyenv.SkyproxyName, AppVersion: skyenv.SkyproxyVersion, ProtocolVersion: skyenv.AppProtocolVersion}
socksApp, err := app.Setup(config)
if err != nil {
log.Fatal("Setup failure: ", err)
Expand Down
11 changes: 7 additions & 4 deletions cmd/apps/therealssh-client/therealssh-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"flag"
"net/http"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/sirupsen/logrus"

Expand All @@ -17,14 +19,15 @@ import (
var log *logging.MasterLogger

func main() {
log = app.NewLogger("SSH-client")
ssh.Log = log.PackageLogger("therealssh")
log = app.NewLogger(skyenv.SkysshClientName)
ssh.Log = log.PackageLogger(skyenv.SkysshClientName)

var rpcAddr = flag.String("rpc", ":2222", "Client RPC address to listen on")
// TODO(evanlinjin): Change "rpc" to "addr".
var rpcAddr = flag.String("rpc", skyenv.SkysshClientAddr, "Client RPC address to listen on")
var debug = flag.Bool("debug", false, "enable debug messages")
flag.Parse()

config := &app.Config{AppName: "SSH-client", AppVersion: "1.0", ProtocolVersion: "0.0.1"}
config := &app.Config{AppName: skyenv.SkysshClientName, AppVersion: skyenv.SkysshClientVersion, ProtocolVersion: skyenv.AppProtocolVersion}
sshApp, err := app.Setup(config)
if err != nil {
log.Fatal("Setup failure: ", err)
Expand Down
8 changes: 5 additions & 3 deletions cmd/apps/therealssh/therealssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package main
import (
"flag"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
Expand All @@ -17,15 +19,15 @@ import (
var log *logging.MasterLogger

func main() {
log = app.NewLogger("SSH")
ssh.Log = log.PackageLogger("therealssh")
log = app.NewLogger(skyenv.SkysshName)
ssh.Log = log.PackageLogger(skyenv.SkysshName)

var authFile = flag.String("auth", "~/.therealssh/authorized_keys", "Auth file location. Should contain one PubKey per line.")
var debug = flag.Bool("debug", false, "enable debug messages")

flag.Parse()

config := &app.Config{AppName: "SSH", AppVersion: "1.0", ProtocolVersion: "0.0.1"}
config := &app.Config{AppName: skyenv.SkysshName, AppVersion: skyenv.SkysshVersion, ProtocolVersion: skyenv.AppProtocolVersion}
sshApp, err := app.Setup(config)
if err != nil {
log.Fatal("Setup failure: ", err)
Expand Down
4 changes: 3 additions & 1 deletion cmd/skywire-cli/commands/mdisc/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"text/tabwriter"
"time"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/dmsg/disc"
"github.com/spf13/cobra"

Expand All @@ -16,7 +18,7 @@ import (
var mdAddr string

func init() {
RootCmd.PersistentFlags().StringVar(&mdAddr, "addr", internal.DefaultDmsgDisc, "address of messaging discovery server")
RootCmd.PersistentFlags().StringVar(&mdAddr, "addr", skyenv.DefaultDmsgDiscAddr, "address of messaging discovery server")
}

// RootCmd is the command that contains sub-commands which interacts with messaging services.
Expand Down
85 changes: 70 additions & 15 deletions cmd/skywire-cli/commands/node/gen-config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package node

import (
"encoding/base64"
"fmt"
"path/filepath"
"time"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/spf13/cobra"

"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/internal"
"github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil"
"github.com/SkycoinProject/skywire-mainnet/pkg/visor"
)
Expand Down Expand Up @@ -69,9 +70,9 @@ func homeConfig() *visor.Config {

func localConfig() *visor.Config {
c := defaultConfig()
c.AppsPath = "/usr/local/SkycoinProject/skywire-mainnet/apps"
c.Transport.LogStore.Location = "/usr/local/SkycoinProject/skywire-mainnet/transport_logs"
c.Routing.Table.Location = "/usr/local/SkycoinProject/skywire-mainnet/routing.db"
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 All @@ -83,26 +84,29 @@ func defaultConfig() *visor.Config {
conf.Node.StaticPubKey = pk
conf.Node.StaticSecKey = sk

conf.Messaging.Discovery = internal.DefaultDmsgDisc
conf.Messaging.Discovery = skyenv.DefaultDmsgDiscAddr
conf.Messaging.ServerCount = 1

passcode := base64.StdEncoding.EncodeToString(cipher.RandByte(8))
// TODO(evanlinjin): We have disabled skyproxy passcode by default for now - We should make a cli arg for this.
//passcode := base64.StdEncoding.Strict().EncodeToString(cipher.RandByte(8))
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}},
defaultSkychatConfig(),
defaultSkysshConfig(),
defaultSkyproxyConfig(""),
defaultSkysshClientConfig(),
defaultSkyproxyClientConfig(),
}
conf.TrustedNodes = []cipher.PubKey{}

conf.Transport.Discovery = internal.DefaultTpDisc
conf.Transport.Discovery = skyenv.DefaultTpDiscAddr
conf.Transport.LogStore.Type = "file"
conf.Transport.LogStore.Location = "./skywire/transport_logs"

conf.Routing.RouteFinder = internal.DefaultRouteFinder
conf.Routing.RouteFinder = skyenv.DefaultRouteFinderAddr

sPK := cipher.PubKey{}
if err := sPK.UnmarshalText([]byte(internal.DefaultSetupPK)); err != nil {
log.WithError(err).Warnf("Failed to unmarshal default setup node public key %s", internal.DefaultSetupPK)
var sPK cipher.PubKey
if err := sPK.UnmarshalText([]byte(skyenv.DefaultSetupPK)); err != nil {
log.WithError(err).Warnf("Failed to unmarshal default setup node public key %s", skyenv.DefaultSetupPK)
}
conf.Routing.SetupNodes = []cipher.PubKey{sPK}
conf.Routing.Table.Type = "boltdb"
Expand All @@ -124,3 +128,54 @@ func defaultConfig() *visor.Config {

return conf
}

func defaultSkychatConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.SkychatName,
Version: skyenv.SkychatVersion,
AutoStart: true,
Port: routing.Port(skyenv.SkychatPort),
Args: []string{fmt.Sprintf(`--addr="%s"`, skyenv.SkychatAddr)},
}
}

func defaultSkysshConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.SkysshName,
Version: skyenv.SkysshVersion,
AutoStart: true,
Port: routing.Port(skyenv.SkysshPort),
}
}

func defaultSkyproxyConfig(passcode string) visor.AppConfig {
var args []string
if passcode != "" {
args = []string{fmt.Sprintf(`--passcode="%s"`, passcode)}
}
return visor.AppConfig{
App: skyenv.SkyproxyName,
Version: skyenv.SkyproxyVersion,
AutoStart: false,
Port: routing.Port(skyenv.SkyproxyPort),
Args: args,
}
}

func defaultSkysshClientConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.SkysshClientName,
Version: skyenv.SkysshVersion,
AutoStart: true,
Port: routing.Port(skyenv.SkysshClientPort),
}
}

func defaultSkyproxyClientConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.SkyproxyClientName,
Version: skyenv.SkyproxyClientVersion,
AutoStart: false,
Port: routing.Port(skyenv.SkyproxyClientPort),
}
}
2 changes: 0 additions & 2 deletions cmd/skywire-cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/commands/mdisc"
"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/commands/node"
"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/commands/rtfind"
"github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/commands/tpdisc"
)

var rootCmd = &cobra.Command{
Expand All @@ -21,7 +20,6 @@ func init() {
node.RootCmd,
mdisc.RootCmd,
rtfind.RootCmd,
tpdisc.RootCmd,
)
}

Expand Down
4 changes: 3 additions & 1 deletion cmd/skywire-cli/commands/rtfind/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"time"

"github.com/SkycoinProject/skywire-mainnet/internal/skyenv"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/spf13/cobra"

Expand All @@ -16,7 +18,7 @@ var frMinHops, frMaxHops uint16
var timeout time.Duration

func init() {
RootCmd.Flags().StringVar(&frAddr, "addr", internal.DefaultRouteFinder, "address in which to contact route finder service")
RootCmd.Flags().StringVar(&frAddr, "addr", skyenv.DefaultRouteFinderAddr, "address in which to contact route finder service")
RootCmd.Flags().Uint16Var(&frMinHops, "min-hops", 1, "min hops for the returning routeFinderRoutesCmd")
RootCmd.Flags().Uint16Var(&frMaxHops, "max-hops", 1000, "max hops for the returning routeFinderRoutesCmd")
RootCmd.Flags().DurationVar(&timeout, "timeout", 10*time.Second, "timeout for remote server requests")
Expand Down
Loading

0 comments on commit 47dcb67

Please sign in to comment.