Skip to content

Commit

Permalink
Merge pull request #8
Browse files Browse the repository at this point in the history
Release v0.1.7
  • Loading branch information
bsrinivas8687 authored Jul 6, 2021
2 parents 4003297 + d51b736 commit 726ee3e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
6 changes: 5 additions & 1 deletion services/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (w *WireGuard) IsUp() bool {
return true
}

func (w *WireGuard) PreUp() error {
return w.cfg.WriteToFile(w.Home())
}

func (w *WireGuard) Up() error {
var (
path = filepath.Join(w.Home(), fmt.Sprintf("%s.conf", w.cfg.Name))
Expand Down Expand Up @@ -89,7 +93,7 @@ func (w *WireGuard) PostDown() error {
return nil
}

func (w *WireGuard) Transfer() (int64, int64, error) {
func (w *WireGuard) Transfer() (u int64, d int64, err error) {
iFace, err := w.RealInterface()
if err != nil {
return 0, 0, err
Expand Down
4 changes: 0 additions & 4 deletions services/wireguard/wireguard_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/alessio/shellescape"
)

func (w *WireGuard) PreUp() error {
return w.cfg.WriteToFile(w.Home())
}

func (w *WireGuard) RealInterface() (string, error) {
nameFile, err := os.Open(
fmt.Sprintf("/var/run/wireguard/%s.name", shellescape.Quote(w.cfg.Name)))
Expand Down
30 changes: 0 additions & 30 deletions services/wireguard/wireguard_linux.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,5 @@
package wireguard

import (
"fmt"
"net"
"strings"

"golang.org/x/net/nettest"
)

func (w *WireGuard) PreUp() error {
iFace, err := nettest.RoutedInterface("ip", net.FlagUp|net.FlagBroadcast)
if err != nil {
return err
}

w.cfg.Interface.PostUp = strings.Join([]string{
"iptables -A FORWARD -i %i -j ACCEPT",
fmt.Sprintf("iptables -t nat -A POSTROUTING -o %s -j MASQUERADE", iFace.Name),
"ip6tables -A FORWARD -i %i -j ACCEPT",
fmt.Sprintf("ip6tables -t nat -A POSTROUTING -o %s -j MASQUERADE", iFace.Name),
}, ";")
w.cfg.Interface.PostDown = strings.Join([]string{
"iptables -D FORWARD -i %i -j ACCEPT",
fmt.Sprintf("iptables -t nat -D POSTROUTING -o %s -j MASQUERADE", iFace.Name),
"ip6tables -D FORWARD -i %i -j ACCEPT",
fmt.Sprintf("ip6tables -t nat -D POSTROUTING -o %s -j MASQUERADE", iFace.Name),
}, ";")

return w.cfg.WriteToFile(w.Home())
}

func (w *WireGuard) RealInterface() (string, error) {
return w.cfg.Name, nil
}
5 changes: 3 additions & 2 deletions x/session/client/cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strconv"
"time"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
Expand Down Expand Up @@ -68,7 +69,7 @@ func QuerySession() *cobra.Command {
fmt.Sprintf("%d", item.Subscription),
item.Node,
item.Address,
item.Duration.String(),
item.Duration.Truncate(1 * time.Second).String(),
item.Bandwidth.String(),
item.Status,
},
Expand Down Expand Up @@ -173,7 +174,7 @@ func QuerySessions() *cobra.Command {
fmt.Sprintf("%d", items[i].Subscription),
items[i].Node,
items[i].Address,
items[i].Duration.String(),
items[i].Duration.Truncate(1 * time.Second).String(),
items[i].Bandwidth.String(),
items[i].Status,
},
Expand Down

0 comments on commit 726ee3e

Please sign in to comment.