diff --git a/internal/gui/gui.go b/internal/gui/gui.go index 111fe2c70..5729d6657 100644 --- a/internal/gui/gui.go +++ b/internal/gui/gui.go @@ -4,7 +4,6 @@ package gui import ( - "context" "embed" "fmt" "io" @@ -20,7 +19,6 @@ import ( "github.com/skycoin/skycoin/src/util/logging" "github.com/toqueteos/webbrowser" - "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/skyenv" "github.com/skycoin/skywire/pkg/visor/visorconfig" ) @@ -193,25 +191,25 @@ func handleVPNLinkButton(conf *visorconfig.V1) { } // GetAvailPublicVPNServers gets all available public VPN server from service discovery URL -func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { - sdClient := servicedisc.NewClient(log, servicedisc.Config{ - Type: servicedisc.ServiceTypeVPN, - PK: conf.PK, - SK: conf.SK, - DiscAddr: conf.Launcher.ServiceDisc, - }) - //ctx, _ := context.WithTimeout(context.Background(), 7*time.Second) - vpnServers, err := sdClient.Services(context.Background(), 0) - if err != nil { - log.Error("Error getting public vpn servers: ", err) - return nil - } - serverAddrs := make([]string, len(vpnServers)) - for idx, server := range vpnServers { - serverAddrs[idx] = server.Addr.PubKey().String() - } - return serverAddrs -} +//func GetAvailPublicVPNServers(conf *visorconfig.V1) []string { +// sdClient := servicedisc.NewClient(log, servicedisc.Config{ +// Type: servicedisc.ServiceTypeVPN, +// PK: conf.PK, +// SK: conf.SK, +// DiscAddr: conf.Launcher.ServiceDisc, +// }) +// //ctx, _ := context.WithTimeout(context.Background(), 7*time.Second) +// vpnServers, err := sdClient.Services(context.Background(), 0) +// if err != nil { +// log.Error("Error getting public vpn servers: ", err) +// return nil +// } +// serverAddrs := make([]string, len(vpnServers)) +// for idx, server := range vpnServers { +// serverAddrs[idx] = server.Addr.PubKey().String() +// } +// return serverAddrs +//} func initUninstallBtn() { if !checkIsPackage() { diff --git a/internal/vpn/tun_device_unix.go b/internal/vpn/tun_device_unix.go index ea77020b5..423f50a13 100644 --- a/internal/vpn/tun_device_unix.go +++ b/internal/vpn/tun_device_unix.go @@ -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) diff --git a/pkg/router/network_stats.go b/pkg/router/network_stats.go index 919975503..98d0202c3 100644 --- a/pkg/router/network_stats.go +++ b/pkg/router/network_stats.go @@ -20,7 +20,7 @@ type networkStats struct { func newNetworkStats() *networkStats { return &networkStats{ - bandwidthReceivedRecStart: time.Now(), + bandwidthReceivedRecStart: time.Now().UTC(), } } @@ -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) diff --git a/pkg/router/route_group.go b/pkg/router/route_group.go index 50abd8a39..9c120db79 100644 --- a/pkg/router/route_group.go +++ b/pkg/router/route_group.go @@ -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())) } @@ -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) @@ -603,6 +602,10 @@ func (rg *RouteGroup) handlePacket(packet routing.Packet) error { }) } + if packet.Type() != routing.ClosePacket || packet.Type() != routing.HandshakePacket { + rg.networkStats.AddBandwidthReceived(uint64(packet.Size())) + } + return nil } @@ -615,6 +618,8 @@ func (rg *RouteGroup) handleNetworkProbePacket(packet routing.Packet) error { ms := sentAtMs % 1000 sentAt := time.Unix(int64(sentAtMs/1000), int64(ms)*int64(time.Millisecond)) + rg.logger.Debugf("Latency is around %d ms", time.Since(sentAt).Milliseconds()) + rg.networkStats.SetLatency(time.Since(sentAt)) rg.networkStats.SetUploadSpeed(uint32(throughput)) @@ -629,7 +634,6 @@ func (rg *RouteGroup) handleDataPacket(packet routing.Packet) error { if rg.isRemoteClosed() { return nil } - rg.networkStats.AddBandwidthReceived(uint64(packet.Size())) select { case <-rg.closed: diff --git a/pkg/router/route_group_test.go b/pkg/router/route_group_test.go index 3464aa416..c06ff11ce 100644 --- a/pkg/router/route_group_test.go +++ b/pkg/router/route_group_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/skycoin/dmsg/cipher" + "github.com/skycoin/skycoin/src/util/logging" "github.com/stretchr/testify/require" "github.com/skycoin/skywire/pkg/routing" @@ -30,6 +31,7 @@ func TestRouteGroup_RemoteAddr(t *testing.T) { } func createRouteGroup(cfg *RouteGroupConfig) *RouteGroup { + l := logging.NewMasterLogger() rt := routing.NewTable() pk1, _ := cipher.GenerateKeyPair() @@ -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 }