Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/vpn stats #1184

Merged
merged 22 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ for:

install:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.44.2
- sudo apt-get install gcc libgtk-3-dev libayatana-appindicator3-dev -y
- make dep
- sh: ci_scripts/create-ip-aliases.sh

Expand Down
3 changes: 3 additions & 0 deletions internal/vpn/tun_device_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
func newTUNDevice() (TUNDevice, error) {
tun, err := water.New(water.Config{
DeviceType: water.TUN,
PlatformSpecificParams: water.PlatformSpecificParams{
Name: "utun4",
},
})
if err != nil {
return nil, fmt.Errorf("error allocating TUN interface: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions pkg/router/network_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type networkStats struct {

func newNetworkStats() *networkStats {
return &networkStats{
bandwidthReceivedRecStart: time.Now(),
bandwidthReceivedRecStart: time.Now().UTC(),
}
}

func (s *networkStats) SetLatency(latency time.Duration) {
atomic.StoreUint32(&s.latency, uint32(latency.Milliseconds()))
func (s *networkStats) SetLatency(latency uint32) {
atomic.StoreUint32(&s.latency, latency)
}

func (s *networkStats) Latency() time.Duration {
Expand Down Expand Up @@ -69,8 +69,8 @@ func (s *networkStats) AddBandwidthReceived(amount uint64) {

func (s *networkStats) RemoteThroughput() int64 {
s.bandwidthReceivedRecStartMu.Lock()
timePassed := time.Since(s.bandwidthReceivedRecStart)
s.bandwidthReceivedRecStart = time.Now()
timePassed := time.Now().UTC().Sub(s.bandwidthReceivedRecStart) //nolint:gosimple
s.bandwidthReceivedRecStart = time.Now().UTC()
s.bandwidthReceivedRecStartMu.Unlock()

bandwidth := atomic.SwapUint64(&s.bandwidthReceived, 0)
Expand Down
12 changes: 7 additions & 5 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func (rg *RouteGroup) writePacket(ctx context.Context, tp *transport.ManagedTran
err := tp.WritePacket(ctx, packet)
// note equality here. update activity only if there was NO error
if err == nil {
if packet.Type() == routing.DataPacket {
if packet.Type() != routing.ClosePacket || packet.Type() != routing.HandshakePacket {
rg.networkStats.AddBandwidthSent(uint64(packet.Size()))
}

Expand Down Expand Up @@ -425,8 +425,7 @@ func (rg *RouteGroup) sendNetworkProbe() error {
}

throughput := rg.networkStats.RemoteThroughput()
timestamp := time.Now().UnixNano() / int64(time.Millisecond)

timestamp := time.Now().UTC().UnixNano() / int64(time.Millisecond)
rg.networkStats.SetDownloadSpeed(uint32(throughput))

packet := routing.MakeNetworkProbePacket(rule.NextRouteID(), timestamp, throughput)
Expand Down Expand Up @@ -610,9 +609,12 @@ func (rg *RouteGroup) handleNetworkProbePacket(packet routing.Packet) error {
throughput := binary.BigEndian.Uint64(payload[8:])

ms := sentAtMs % 1000
sentAt := time.Unix(int64(sentAtMs/1000), int64(ms)*int64(time.Millisecond))
sentAt := time.Unix(int64(sentAtMs/1000), int64(ms)*int64(time.Millisecond)).UTC()

latency := time.Now().UTC().Sub(sentAt).Milliseconds()
rg.logger.Debugf("Latency is around %d ms", latency)

rg.networkStats.SetLatency(time.Since(sentAt))
rg.networkStats.SetLatency(uint32(latency))
rg.networkStats.SetUploadSpeed(uint32(throughput))

return nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/router/route_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package router
import (
"testing"

"github.com/skycoin/skycoin/src/util/logging"
"github.com/stretchr/testify/require"

"github.com/skycoin/skywire-utilities/pkg/cipher"
Expand Down Expand Up @@ -30,6 +31,7 @@ func TestRouteGroup_RemoteAddr(t *testing.T) {
}

func createRouteGroup(cfg *RouteGroupConfig) *RouteGroup {
l := logging.NewMasterLogger()
rt := routing.NewTable()

pk1, _ := cipher.GenerateKeyPair()
Expand All @@ -38,7 +40,6 @@ func createRouteGroup(cfg *RouteGroupConfig) *RouteGroup {
port2 := routing.Port(2)
desc := routing.NewRouteDescriptor(pk1, pk2, port1, port2)

rg := NewRouteGroup(cfg, rt, desc, nil)

rg := NewRouteGroup(cfg, rt, desc, l)
return rg
}