Skip to content

Commit

Permalink
Bumped Sentinel hub version. Add refactored code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrinivas8687 committed Jan 11, 2021
1 parent dfc3cf9 commit 18990f2
Show file tree
Hide file tree
Showing 38 changed files with 882 additions and 365 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bin/
/.idea/
/.idea/
.DS_Store*
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ FROM alpine:3.12
COPY --from=build /go/bin/sentinel-dvpn-node /usr/local/bin/run
COPY --from=build /root/hnsd/hnsd /usr/local/bin/hnsd

RUN apk add --no-cache easy-rsa ip6tables openvpn unbound-dev wireguard-tools && \
RUN apk add --no-cache ip6tables unbound-dev wireguard-tools && \
rm -rf /tmp/* /var/tmp/*

CMD ["run"]
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
# Sentinel dVPN Node
# Sentinel dVPN Node

* [Setup](https://github.com/sentinel-official/docs/tree/master/guides/nodes/dVPN/SETUP.md "Setup")
* [Configuration](https://github.com/sentinel-official/docs/tree/master/guides/nodes/dVPN/CONFIGURATION.md "Configuration")
* [Start](https://github.com/sentinel-official/docs/tree/master/guides/nodes/dVPN/START.md "Start")
* [Troubleshoot](https://github.com/sentinel-official/docs/tree/master/guides/nodes/dVPN/TROUBLESHOOT.md "Troubleshoot")
8 changes: 5 additions & 3 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"os"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/client/keys"
ckeys "github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/go-bip39"
hub "github.com/sentinel-official/hub/types"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -66,7 +67,7 @@ func keysAdd() *cobra.Command {
}

if recovery {
mnemonic, err = client.GetString("Enter your bip39 mnemonic.", bufio.NewReader(os.Stdin))
mnemonic, err = input.GetString("Enter your bip39 mnemonic.", bufio.NewReader(os.Stdin))
if err != nil {
return err
}
Expand All @@ -76,7 +77,8 @@ func keysAdd() *cobra.Command {
}
}

info, err := kb.CreateAccount(args[0], mnemonic, "", types.DefaultPassword, 0, 0)
info, err := kb.CreateAccount(args[0], mnemonic, "", types.DefaultPassword,
ckeys.CreateHDPath(0, 0).String(), ckeys.Secp256k1)
if err != nil {
return err
}
Expand Down
34 changes: 10 additions & 24 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"

clientutils "github.com/cosmos/cosmos-sdk/x/auth/client/utils"
cutils "github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/gorilla/mux"
"github.com/sentinel-official/hub"
sent "github.com/sentinel-official/hub/types"
Expand All @@ -21,6 +19,7 @@ import (
"github.com/sentinel-official/dvpn-node/node"
"github.com/sentinel-official/dvpn-node/rest"
"github.com/sentinel-official/dvpn-node/services/wireguard"
wgt "github.com/sentinel-official/dvpn-node/services/wireguard/types"
"github.com/sentinel-official/dvpn-node/types"
"github.com/sentinel-official/dvpn-node/utils"
)
Expand All @@ -35,27 +34,26 @@ func StartCmd() *cobra.Command {
return err
}

cfgFilePath := filepath.Join(home, "config.toml")
cfgFilePath := filepath.Join(home, types.ConfigFileName)
if _, err := os.Stat(cfgFilePath); err != nil {
return fmt.Errorf("config file does not exist at path '%s'", cfgFilePath)
}

ipv4Pool, err := types.NewIPv4PoolFromCIDR("10.8.0.2/24")
ipv4Pool, err := wgt.NewIPv4PoolFromCIDR("10.8.0.2/24")
if err != nil {
return err
}

ipv6Pool, err := types.NewIPv6PoolFromCIDR("fd86:ea04:1115::2/120")
ipv6Pool, err := wgt.NewIPv6PoolFromCIDR("fd86:ea04:1115::2/120")
if err != nil {
return err
}

var (
cfg = types.NewConfig()
cdc = hub.MakeCodec()
interrupt = make(chan os.Signal)
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
service = wireguard.NewWireGuard(types.NewIPPool(ipv4Pool, ipv6Pool))
cfg = types.NewConfig()
cdc = hub.MakeCodec()
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
service = wireguard.NewWireGuard(wgt.NewIPPool(ipv4Pool, ipv6Pool))
)

if err := cfg.LoadFromPath(cfgFilePath); err != nil {
Expand All @@ -71,7 +69,7 @@ func StartCmd() *cobra.Command {
}

client = client.WithCodec(cdc).
WithTxEncoder(clientutils.GetTxEncoder(cdc))
WithTxEncoder(cutils.GetTxEncoder(cdc))

account, err := client.QueryAccount(client.FromAddress())
if err != nil {
Expand All @@ -81,18 +79,6 @@ func StartCmd() *cobra.Command {
return fmt.Errorf("account does not exist with address '%s'", client.FromAddress())
}

signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
go func() {
<-interrupt

fmt.Println("\r")
if err := service.Stop(); err != nil {
panic(err)
}

os.Exit(0)
}()

logger.Info("Initializing the service", "type", service.Type())
if err := service.Initialize(home); err != nil {
return err
Expand Down
3 changes: 1 addition & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/gorilla/mux"
hub "github.com/sentinel-official/hub/types"
"github.com/sentinel-official/hub/x/node"
"github.com/tendermint/tendermint/libs/log"

"github.com/sentinel-official/dvpn-node/lite"
Expand Down Expand Up @@ -51,7 +50,7 @@ func (c *Context) WithValue(key, value interface{}) *Context {

func (c *Context) Address() hub.NodeAddress { return c.Operator().Bytes() }
func (c *Context) Bandwidth() hub.Bandwidth { return c.bandwidth }
func (c *Context) Type() node.Category { return c.service.Type() }
func (c *Context) Type() uint64 { return c.service.Type() }
func (c *Context) Client() *lite.Client { return c.client }
func (c *Context) Config() *types.Config { return c.config }
func (c *Context) Context() context.Context { return c.ctx }
Expand Down
15 changes: 10 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ module github.com/sentinel-official/dvpn-node
go 1.15

require (
github.com/cosmos/cosmos-sdk v0.37.14
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8
github.com/gorilla/mux v1.7.4
github.com/cosmos/cosmos-sdk v0.39.2
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/gorilla/mux v1.8.0
github.com/pelletier/go-toml v1.8.0
github.com/sentinel-official/hub v0.3.3
github.com/sentinel-official/hub v0.4.0-rc1
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.1
github.com/tendermint/tendermint v0.32.13
github.com/tendermint/tendermint v0.33.9
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/sync v0.0.0-20201008141435-b3e1573b7520
)

replace (
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
)
Loading

0 comments on commit 18990f2

Please sign in to comment.