Skip to content

Commit

Permalink
Merge pull request #3
Browse files Browse the repository at this point in the history
Release v0.1.2
  • Loading branch information
bsrinivas8687 authored Jun 25, 2021
2 parents 5ca7358 + c81dddc commit 1af0727
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Licence](https://img.shields.io/github/license/sentinel-official/cli-client.svg)](https://github.com/sentinel-official/cli-client/blob/development/LICENSE)
[![LoC](https://tokei.rs/b1/github/sentinel-official/cli-client)](https://github.com/sentinel-official/cli-client)

Download the latest version of CLI client software from the releases section [here](https://github.com/sentinel-official/dvpn-node/releases/latest "here").
Download the latest version of CLI client software from the releases section [here](https://github.com/sentinel-official/cli-client/releases/latest "here").

## Install dependencies

Expand Down Expand Up @@ -63,6 +63,7 @@ port install wireguard-tools
--keyring-backend file \
--chain-id sentinelhub-2 \
--node https://rpc.sentinel.co:443 \
--gas-prices 0.1udvpn \
--from <KEY_NAME> <NODE_ADDRESS> <DEPOSIT>
```

Expand All @@ -85,6 +86,7 @@ port install wireguard-tools
--keyring-backend file \
--chain-id sentinelhub-2 \
--node https://rpc.sentinel.co:443 \
--gas-prices 0.1udvpn \
--yes \
--from <KEY_NAME> <SUBSCRIPTION_ID> <NODE_ADDRESS>
```
Expand Down
2 changes: 1 addition & 1 deletion cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func ConnectCmd() *cobra.Command {

flags.AddTxFlagsToCmd(cmd)

cmd.PersistentFlags().String(flags.FlagChainID, "", "the network chain identity")
cmd.Flags().String(flags.FlagChainID, "", "the network chain identity")

return cmd
}
11 changes: 11 additions & 0 deletions types/bandwidth.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package types

import (
"fmt"

hubtypes "github.com/sentinel-official/hub/types"

netutil "github.com/sentinel-official/cli-client/utils/net"
)

type Bandwidth struct {
Upload int64 `json:"upload"`
Download int64 `json:"download"`
}

func (b Bandwidth) String() string {
return fmt.Sprintf("%s+%s",
netutil.ToReadable(b.Upload, 2),
netutil.ToReadable(b.Download, 2),
)
}

func NewBandwidthFromRaw(v hubtypes.Bandwidth) Bandwidth {
return Bandwidth{
Upload: v.Upload.Int64(),
Expand Down
70 changes: 70 additions & 0 deletions utils/net/bytes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net

import (
"fmt"
)

const (
B int64 = 1
KB = 1e3 * B
MB = 1e3 * KB
GB = 1e3 * MB
TB = 1e3 * GB
)

func ToReadable(bytes int64, decimals int) (out string) {
var (
i int64
rem int64
unit string
)

switch {
case bytes > TB:
i = bytes / TB
rem = bytes - (i * TB)
unit = "TB"
case bytes > GB:
i = bytes / GB
rem = bytes - (i * GB)
unit = "GB"
case bytes > MB:
i = bytes / MB
rem = bytes - (i * MB)
unit = "MB"
case bytes > KB:
i = bytes / KB
rem = bytes - (i * KB)
unit = "KB"
default:
i = bytes / B
rem = bytes - (i * B)
unit = "B"
}

if decimals == 0 {
return fmt.Sprintf("%d%s", i, unit)
}

width := 0
switch {
case rem > GB:
width = 12
case rem > MB:
width = 9
case rem > KB:
width = 6
default:
width = 3
}

remString := fmt.Sprintf("%d", rem)
for iter := len(remString); iter < width; iter++ {
remString = "0" + remString
}
if decimals > len(remString) {
decimals = len(remString)
}

return fmt.Sprintf("%d.%s%s", i, remString[:decimals], unit)
}
3 changes: 3 additions & 0 deletions x/node/client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
"Provider",
"Price",
"Country",
"Speed test",
"Peers",
"Handshake",
"Status",
Expand Down Expand Up @@ -113,6 +114,7 @@ func QueryNode() *cobra.Command {
item.Provider,
item.Price.Raw().String(),
item.Location.Country,
item.Bandwidth.String(),
fmt.Sprintf("%d", item.Peers),
fmt.Sprintf("%t", item.Handshake.Enable),
item.Status,
Expand Down Expand Up @@ -217,6 +219,7 @@ func QueryNodes() *cobra.Command {
item.Provider,
item.Price.Raw().String(),
item.Location.Country,
item.Bandwidth.String(),
fmt.Sprintf("%d", item.Peers),
fmt.Sprintf("%t", item.Handshake.Enable),
item.Status,
Expand Down
5 changes: 3 additions & 2 deletions x/plan/client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
plantypes "github.com/sentinel-official/hub/x/plan/types"
"github.com/spf13/cobra"

netutil "github.com/sentinel-official/cli-client/utils/net"
"github.com/sentinel-official/cli-client/x/plan/types"
)

Expand Down Expand Up @@ -65,7 +66,7 @@ func QueryPlan() *cobra.Command {
fmt.Sprintf("%d", item.ID),
item.Provider,
item.Price.Raw().String(),
fmt.Sprintf("%d", item.Bytes),
netutil.ToReadable(item.Bytes, 2),
item.Validity.String(),
item.Status,
},
Expand Down Expand Up @@ -155,7 +156,7 @@ func QueryPlans() *cobra.Command {
fmt.Sprintf("%d", items[i].ID),
items[i].Provider,
items[i].Price.Raw().String(),
fmt.Sprintf("%d", items[i].Bytes),
netutil.ToReadable(items[i].Bytes, 2),
items[i].Validity.String(),
items[i].Status,
},
Expand Down
7 changes: 4 additions & 3 deletions x/provider/client/cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func GetTxCommand() *cobra.Command {

func txRegister() *cobra.Command {
cmd := &cobra.Command{
Use: "register [name]",
Short: "Register a provider",
Args: cobra.ExactArgs(1),
Use: "register [name]",
Short: "Register a provider",
Args: cobra.ExactArgs(1),
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/session/client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func QuerySession() *cobra.Command {
item.Node,
item.Address,
item.Duration.String(),
fmt.Sprintf("%d+%d", item.Bandwidth.Download, item.Bandwidth.Upload),
item.Bandwidth.String(),
item.Status,
},
)
Expand Down Expand Up @@ -174,7 +174,7 @@ func QuerySessions() *cobra.Command {
items[i].Node,
items[i].Address,
items[i].Duration.String(),
fmt.Sprintf("%d+%d", items[i].Bandwidth.Download, items[i].Bandwidth.Upload),
items[i].Bandwidth.String(),
items[i].Status,
},
)
Expand Down
13 changes: 7 additions & 6 deletions x/subscription/client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
subscriptiontypes "github.com/sentinel-official/hub/x/subscription/types"
"github.com/spf13/cobra"

netutil "github.com/sentinel-official/cli-client/utils/net"
"github.com/sentinel-official/cli-client/x/subscription/types"
)

Expand Down Expand Up @@ -80,7 +81,7 @@ func QuerySubscription() *cobra.Command {
item.Node,
item.Price.Raw().String(),
item.Deposit.Raw().String(),
fmt.Sprintf("%d", item.Free),
netutil.ToReadable(item.Free, 2),
item.Status,
},
)
Expand Down Expand Up @@ -188,7 +189,7 @@ func QuerySubscriptions() *cobra.Command {
items[i].Node,
items[i].Price.Raw().String(),
items[i].Deposit.Raw().String(),
fmt.Sprintf("%d", items[i].Free),
netutil.ToReadable(items[i].Free, 2),
items[i].Status,
},
)
Expand Down Expand Up @@ -254,8 +255,8 @@ func QueryQuota() *cobra.Command {
table.Append(
[]string{
item.Address,
fmt.Sprintf("%d", item.Allocated),
fmt.Sprintf("%d", item.Consumed),
netutil.ToReadable(item.Allocated, 2),
netutil.ToReadable(item.Consumed, 2),
},
)

Expand Down Expand Up @@ -315,8 +316,8 @@ func QueryQuotas() *cobra.Command {
table.Append(
[]string{
items[i].Address,
fmt.Sprintf("%d", items[i].Allocated),
fmt.Sprintf("%d", items[i].Consumed),
netutil.ToReadable(items[i].Allocated, 2),
netutil.ToReadable(items[i].Consumed, 2),
},
)
}
Expand Down

0 comments on commit 1af0727

Please sign in to comment.