Skip to content

Commit

Permalink
Merge pull request #132
Browse files Browse the repository at this point in the history
Release v0.6.4
  • Loading branch information
bsrinivas8687 committed Mar 20, 2023
2 parents d084cfe + 3d0aad7 commit 440149f
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 159 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea/
/.github/
/.vscode/
/bin/
/vendor/
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: "CodeQL"
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:

jobs:
analyze:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store*
/.idea/
/.vscode/
/bin/
/vendor/
4 changes: 2 additions & 2 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func configInit() *cobra.Command {
}
}

if err := os.MkdirAll(home, 0700); err != nil {
if err = os.MkdirAll(home, 0700); err != nil {
return err
}

Expand Down Expand Up @@ -109,7 +109,7 @@ func configSet() *cobra.Command {

v.Set(args[0], args[1])

if err := v.Unmarshal(config); err != nil {
if err = v.Unmarshal(config); err != nil {
return err
}

Expand Down
46 changes: 13 additions & 33 deletions cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import (
"bufio"
"fmt"
"path/filepath"
"text/tabwriter"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/crypto/hd"
cryptohd "github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/go-bip39"
"github.com/pkg/errors"
hubtypes "github.com/sentinel-official/hub/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/sentinel-official/dvpn-node/types"
"github.com/sentinel-official/dvpn-node/utils"
)

func KeysCmd() *cobra.Command {
Expand Down Expand Up @@ -61,7 +60,7 @@ func keysAdd() *cobra.Command {
}

if !skipConfigValidation {
if err := config.Validate(); err != nil {
if err = config.Validate(); err != nil {
return err
}
}
Expand Down Expand Up @@ -121,27 +120,20 @@ func keysAdd() *cobra.Command {
}

var (
hdPath = hd.CreateHDPath(sdk.GetConfig().GetCoinType(), account, index)
algorithms, _ = kr.SupportedAlgorithms()
coinType = sdk.GetConfig().GetCoinType()
path = cryptohd.CreateHDPath(coinType, account, index)
)

algorithm, err := keyring.NewSigningAlgoFromString(string(hd.Secp256k1Type), algorithms)
key, err := kr.NewAccount(name, mnemonic, "", path.String(), cryptohd.Secp256k1)
if err != nil {
return err
}

key, err := kr.NewAccount(name, mnemonic, "", hdPath.String(), algorithm)
if err != nil {
return err
}

_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "operator: %s\n", key.GetAddress())
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "address: %s\n", hubtypes.NodeAddress(key.GetAddress()))
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "\n")
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "**Important** write this mnemonic phrase in a safe place\n")
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "%s\n", mnemonic)
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "\n")

return nil
return utils.WriteKeys(cmd.OutOrStdout(), key)
},
}

Expand Down Expand Up @@ -178,7 +170,7 @@ func keysShow() *cobra.Command {
}

if !skipConfigValidation {
if err := config.Validate(); err != nil {
if err = config.Validate(); err != nil {
return err
}
}
Expand All @@ -202,10 +194,7 @@ func keysShow() *cobra.Command {
return err
}

fmt.Printf("operator: %s\n", key.GetAddress())
fmt.Printf("address: %s\n", hubtypes.NodeAddress(key.GetAddress()))

return nil
return utils.WriteKeys(cmd.OutOrStdout(), key)
},
}

Expand Down Expand Up @@ -238,7 +227,7 @@ func keysList() *cobra.Command {
}

if !skipConfigValidation {
if err := config.Validate(); err != nil {
if err = config.Validate(); err != nil {
return err
}
}
Expand All @@ -257,16 +246,7 @@ func keysList() *cobra.Command {
return err
}

w := tabwriter.NewWriter(cmd.OutOrStdout(), 1, 1, 1, ' ', 0)
for _, key := range keys {
_, _ = fmt.Fprintf(w, "%s\t%s\t%s\n",
key.GetName(),
key.GetAddress(),
hubtypes.NodeAddress(key.GetAddress().Bytes()),
)
}

return w.Flush()
return utils.WriteKeys(cmd.OutOrStdout(), keys...)
},
}

Expand Down Expand Up @@ -300,7 +280,7 @@ func keysDelete() *cobra.Command {
}

if !skipConfigValidation {
if err := config.Validate(); err != nil {
if err = config.Validate(); err != nil {
return err
}
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/go-kit/kit/transport/http/jsonrpc"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gorm.io/driver/sqlite"
Expand All @@ -21,6 +20,7 @@ import (

"github.com/sentinel-official/dvpn-node/api"
"github.com/sentinel-official/dvpn-node/context"
"github.com/sentinel-official/dvpn-node/libs/geoip"
"github.com/sentinel-official/dvpn-node/lite"
"github.com/sentinel-official/dvpn-node/node"
"github.com/sentinel-official/dvpn-node/services/v2ray"
Expand Down Expand Up @@ -73,7 +73,7 @@ func StartCmd() *cobra.Command {

if !skipConfigValidation {
log.Info("Validating the configuration", "data", config)
if err := config.Validate(); err != nil {
if err = config.Validate(); err != nil {
return err
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func StartCmd() *cobra.Command {
}

log.Info("Fetching the GeoIP location info...")
location, err := utils.FetchGeoIPLocation()
location, err := geoip.Location()
if err != nil {
return err
}
Expand All @@ -162,12 +162,12 @@ func StartCmd() *cobra.Command {
}

log.Info("Initializing the VPN service", "type", service.Type())
if err := service.Init(home); err != nil {
if err = service.Init(home); err != nil {
return err
}

log.Info("Starting the VPN service", "type", service.Type())
if err := service.Start(); err != nil {
if err = service.Start(); err != nil {
return err
}

Expand All @@ -184,7 +184,7 @@ func StartCmd() *cobra.Command {
}

log.Info("Migrating the database models...")
if err := database.AutoMigrate(&types.Session{}); err != nil {
if err = database.AutoMigrate(&types.Session{}); err != nil {
return err
}

Expand All @@ -199,7 +199,7 @@ func StartCmd() *cobra.Command {
http.MethodPost,
},
AllowHeaders: []string{
jsonrpc.ContentType,
types.ContentType,
},
},
)
Expand All @@ -218,7 +218,7 @@ func StartCmd() *cobra.Command {
WithService(service)

n := node.NewNode(ctx)
if err := n.Initialize(); err != nil {
if err = n.Initialize(); err != nil {
return err
}

Expand Down
21 changes: 11 additions & 10 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
tmlog "github.com/tendermint/tendermint/libs/log"
"gorm.io/gorm"

geoiptypes "github.com/sentinel-official/dvpn-node/libs/geoip/types"
"github.com/sentinel-official/dvpn-node/lite"
"github.com/sentinel-official/dvpn-node/types"
)
Expand All @@ -20,7 +21,7 @@ type Context struct {
config *types.Config
database *gorm.DB
handler http.Handler
location *types.GeoIPLocation
location *geoiptypes.GeoIPLocation
logger tmlog.Logger
service types.Service
}
Expand All @@ -29,14 +30,14 @@ func NewContext() *Context {
return &Context{}
}

func (c *Context) WithBandwidth(v *hubtypes.Bandwidth) *Context { c.bandwidth = v; return c }
func (c *Context) WithClient(v *lite.Client) *Context { c.client = v; return c }
func (c *Context) WithConfig(v *types.Config) *Context { c.config = v; return c }
func (c *Context) WithDatabase(v *gorm.DB) *Context { c.database = v; return c }
func (c *Context) WithHandler(v http.Handler) *Context { c.handler = v; return c }
func (c *Context) WithLocation(v *types.GeoIPLocation) *Context { c.location = v; return c }
func (c *Context) WithLogger(v tmlog.Logger) *Context { c.logger = v; return c }
func (c *Context) WithService(v types.Service) *Context { c.service = v; return c }
func (c *Context) WithBandwidth(v *hubtypes.Bandwidth) *Context { c.bandwidth = v; return c }
func (c *Context) WithClient(v *lite.Client) *Context { c.client = v; return c }
func (c *Context) WithConfig(v *types.Config) *Context { c.config = v; return c }
func (c *Context) WithDatabase(v *gorm.DB) *Context { c.database = v; return c }
func (c *Context) WithHandler(v http.Handler) *Context { c.handler = v; return c }
func (c *Context) WithLocation(v *geoiptypes.GeoIPLocation) *Context { c.location = v; return c }
func (c *Context) WithLogger(v tmlog.Logger) *Context { c.logger = v; return c }
func (c *Context) WithService(v types.Service) *Context { c.service = v; return c }

func (c *Context) Address() hubtypes.NodeAddress { return c.Operator().Bytes() }
func (c *Context) Bandwidth() *hubtypes.Bandwidth { return c.bandwidth }
Expand All @@ -47,7 +48,7 @@ func (c *Context) Handler() http.Handler { return c.handler }
func (c *Context) IntervalSetSessions() time.Duration { return c.Config().Node.IntervalSetSessions }
func (c *Context) IntervalUpdateStatus() time.Duration { return c.Config().Node.IntervalUpdateStatus }
func (c *Context) ListenOn() string { return c.Config().Node.ListenOn }
func (c *Context) Location() *types.GeoIPLocation { return c.location }
func (c *Context) Location() *geoiptypes.GeoIPLocation { return c.location }
func (c *Context) Log() tmlog.Logger { return c.logger }
func (c *Context) Moniker() string { return c.Config().Node.Moniker }
func (c *Context) Operator() sdk.AccAddress { return c.client.FromAddress() }
Expand Down
17 changes: 8 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ require (
github.com/avast/retry-go/v4 v4.3.3
github.com/cosmos/cosmos-sdk v0.45.11
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v3 v3.4.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.0
github.com/go-kit/kit v0.12.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.0
github.com/sentinel-official/hub v0.10.1
github.com/showwin/speedtest-go v1.5.2
github.com/showwin/speedtest-go v1.6.0
github.com/soheilhy/cmux v0.1.5
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/tendermint/tendermint v0.34.23
github.com/v2fly/v2ray-core/v5 v5.4.0
github.com/v2fly/v2ray-core/v5 v5.4.1
golang.org/x/crypto v0.7.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.29.0
google.golang.org/protobuf v1.30.0
gorm.io/driver/sqlite v1.4.4
gorm.io/gorm v1.24.6
)
Expand All @@ -37,7 +35,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/bytedance/sonic v1.8.4 // indirect
github.com/bytedance/sonic v1.8.5 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
Expand All @@ -61,12 +59,13 @@ require (
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/goccy/go-json v0.10.1 // indirect
github.com/go-playground/validator/v10 v10.12.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/gogo/protobuf v1.3.3 // indirect
Expand Down Expand Up @@ -112,7 +111,7 @@ require (
github.com/onsi/gomega v1.27.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pires/go-proxyproto v0.6.2 // indirect
github.com/pires/go-proxyproto v0.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.13.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand Down

0 comments on commit 440149f

Please sign in to comment.