From 2e4c945b7f085c22120ce867e66f01f80001bab1 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Mon, 4 Oct 2021 12:09:08 +0700 Subject: [PATCH 1/7] added connection duration to vpn-client --- internal/vpn/client.go | 34 ++++++++++++++++++++++++++++------ pkg/app/appserver/app_stats.go | 5 +++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/internal/vpn/client.go b/internal/vpn/client.go index b4711da66c..ef39147749 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -10,6 +10,7 @@ import ( "runtime" "strconv" "sync" + "sync/atomic" "time" "github.com/sirupsen/logrus" @@ -50,6 +51,8 @@ type Client struct { tunMu sync.Mutex tun TUNDevice tunCreated bool + + connectedDuration int64 } // NewClient creates VPN client instance. @@ -181,10 +184,13 @@ func (c *Client) Serve() error { fmt.Printf("Failed to close TUN: %v\n", err) } - fmt.Println("Closed TUN") + c.log.Info("Closing TUN") }() - defer c.setAppStatus(ClientStatusShuttingDown) + defer func() { + c.setAppStatus(ClientStatusShuttingDown) + c.resetConnDuration() + }() c.setAppStatus(ClientStatusConnecting) @@ -195,6 +201,7 @@ func (c *Client) Serve() error { } if err := c.dialServeConn(); err != nil { + c.resetConnDuration() c.setAppStatus(ClientStatusReconnecting) fmt.Println("Connection broke, reconnecting...") return fmt.Errorf("dialServeConn: %w", err) @@ -382,6 +389,8 @@ func (c *Client) serveConn(conn net.Conn) error { } c.setAppStatus(ClientStatusRunning) + c.resetConnDuration() + t := time.NewTicker(time.Second) defer func() { if !c.cfg.Killswitch { @@ -412,10 +421,19 @@ func (c *Client) serveConn(conn net.Conn) error { }() // only one side may fail here, so we wait till at least one fails - select { - case <-connToTunDoneCh: - case <-tunToConnCh: - case <-c.closeC: +serveLoop: + for { + select { + case <-connToTunDoneCh: + break serveLoop + case <-tunToConnCh: + break serveLoop + case <-c.closeC: + break serveLoop + case <-t.C: + atomic.AddInt64(&c.connectedDuration, 1) + c.log.Infof("VPN Connection Duration: %d seconds", c.connectedDuration) + } } // here we setup system privileges again, so deferred calls may be done safely @@ -729,6 +747,10 @@ func (c *Client) isClosed() bool { return false } +func (c *Client) resetConnDuration() { + atomic.StoreInt64(&c.connectedDuration, 0) +} + func ipFromEnv(key string) (net.IP, error) { ip, ok, err := IPFromEnv(key) if err != nil { diff --git a/pkg/app/appserver/app_stats.go b/pkg/app/appserver/app_stats.go index 2a454555fb..a6295d6603 100644 --- a/pkg/app/appserver/app_stats.go +++ b/pkg/app/appserver/app_stats.go @@ -6,6 +6,7 @@ import ( // AppStats contains app runtime statistics. type AppStats struct { - Connections []ConnectionSummary `json:"connections"` - StartTime *time.Time `json:"start_time,omitempty"` + Connections []ConnectionSummary `json:"connections"` + StartTime *time.Time `json:"start_time,omitempty"` + ConnectionDuration int64 `json:"connection_duration,omitempty"` } From afcdbba1fa1d1ad9ac80411990b5eb6fb7d82642 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Tue, 5 Oct 2021 09:10:15 +0700 Subject: [PATCH 2/7] VPN connection duration: added mock --- internal/vpn/client.go | 9 +- pkg/app/appevent/mock_rpc_client.go | 4 +- pkg/app/appserver/mock_proc_manager.go | 26 ++++- pkg/app/appserver/mock_rpc_ingress_client.go | 20 +++- pkg/app/appserver/proc.go | 18 ++++ pkg/app/appserver/proc_manager.go | 3 +- pkg/app/appserver/rpc_ingress_client.go | 6 ++ pkg/app/appserver/rpc_ingress_gateway.go | 7 ++ pkg/app/client.go | 5 + pkg/app/launcher/app_state.go | 5 +- pkg/app/launcher/launcher.go | 1 + pkg/routefinder/rfclient/mock_client.go | 3 +- pkg/router/mock_router.go | 4 +- pkg/setup/mock_id_reserver.go | 2 + .../setupclient/mock_route_group_dialer.go | 43 ++++++++ .../network/addrresolver/mock_api_client.go | 26 ++--- pkg/transport/network/mock_dialer.go | 4 +- pkg/visor/hypervisorconfig/README.md | 4 - pkg/visor/visorconfig/README.md | 98 +++++-------------- 19 files changed, 185 insertions(+), 103 deletions(-) create mode 100644 pkg/setup/setupclient/mock_route_group_dialer.go diff --git a/internal/vpn/client.go b/internal/vpn/client.go index ef39147749..bdf011c45e 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -432,7 +432,7 @@ serveLoop: break serveLoop case <-t.C: atomic.AddInt64(&c.connectedDuration, 1) - c.log.Infof("VPN Connection Duration: %d seconds", c.connectedDuration) + c.setConnectionDuration() } } @@ -737,6 +737,12 @@ func (c *Client) setAppStatus(status ClientStatus) { } } +func (c *Client) setConnectionDuration() { + if err := c.appCl.SetConnectionDuration(c.connectedDuration); err != nil { + fmt.Printf("Failed to set connection duration: %v\n", err) + } +} + func (c *Client) isClosed() bool { select { case <-c.closeC: @@ -749,6 +755,7 @@ func (c *Client) isClosed() bool { func (c *Client) resetConnDuration() { atomic.StoreInt64(&c.connectedDuration, 0) + c.setConnectionDuration() } func ipFromEnv(key string) (net.IP, error) { diff --git a/pkg/app/appevent/mock_rpc_client.go b/pkg/app/appevent/mock_rpc_client.go index cb04624faf..393e3af472 100644 --- a/pkg/app/appevent/mock_rpc_client.go +++ b/pkg/app/appevent/mock_rpc_client.go @@ -5,9 +5,9 @@ package appevent import ( context "context" - mock "github.com/stretchr/testify/mock" - appcommon "github.com/skycoin/skywire/pkg/app/appcommon" + + mock "github.com/stretchr/testify/mock" ) // MockRPCClient is an autogenerated mock type for the RPCClient type diff --git a/pkg/app/appserver/mock_proc_manager.go b/pkg/app/appserver/mock_proc_manager.go index b4c6cc568d..ec2b9910b0 100644 --- a/pkg/app/appserver/mock_proc_manager.go +++ b/pkg/app/appserver/mock_proc_manager.go @@ -3,11 +3,10 @@ package appserver import ( - net "net" - + appcommon "github.com/skycoin/skywire/pkg/app/appcommon" mock "github.com/stretchr/testify/mock" - appcommon "github.com/skycoin/skywire/pkg/app/appcommon" + net "net" ) // MockProcManager is an autogenerated mock type for the ProcManager type @@ -152,6 +151,27 @@ func (_m *MockProcManager) Start(conf appcommon.ProcConfig) (appcommon.ProcID, e return r0, r1 } +// Stats provides a mock function with given fields: appName +func (_m *MockProcManager) Stats(appName string) (AppStats, error) { + ret := _m.Called(appName) + + var r0 AppStats + if rf, ok := ret.Get(0).(func(string) AppStats); ok { + r0 = rf(appName) + } else { + r0 = ret.Get(0).(AppStats) + } + + var r1 error + if rf, ok := ret.Get(1).(func(string) error); ok { + r1 = rf(appName) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // Stop provides a mock function with given fields: appName func (_m *MockProcManager) Stop(appName string) error { ret := _m.Called(appName) diff --git a/pkg/app/appserver/mock_rpc_ingress_client.go b/pkg/app/appserver/mock_rpc_ingress_client.go index 4f989a2db6..766102d3a3 100644 --- a/pkg/app/appserver/mock_rpc_ingress_client.go +++ b/pkg/app/appserver/mock_rpc_ingress_client.go @@ -3,12 +3,12 @@ package appserver import ( - time "time" - + appnet "github.com/skycoin/skywire/pkg/app/appnet" mock "github.com/stretchr/testify/mock" - appnet "github.com/skycoin/skywire/pkg/app/appnet" routing "github.com/skycoin/skywire/pkg/routing" + + time "time" ) // MockRPCIngressClient is an autogenerated mock type for the RPCIngressClient type @@ -142,6 +142,20 @@ func (_m *MockRPCIngressClient) Read(connID uint16, b []byte) (int, error) { return r0, r1 } +// SetConnectionDuration provides a mock function with given fields: dur +func (_m *MockRPCIngressClient) SetConnectionDuration(dur int64) error { + ret := _m.Called(dur) + + var r0 error + if rf, ok := ret.Get(0).(func(int64) error); ok { + r0 = rf(dur) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // SetDeadline provides a mock function with given fields: connID, d func (_m *MockRPCIngressClient) SetDeadline(connID uint16, d time.Time) error { ret := _m.Called(connID, d) diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index ca14e50476..23a055bb75 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -53,6 +53,10 @@ type Proc struct { statusMx sync.RWMutex status string + + // connection duration (i.e. when vpn client is connected, the app will set the connection duration) + connDuration int64 + connDurationMu sync.RWMutex } // NewProc constructs `Proc`. @@ -277,6 +281,20 @@ func (p *Proc) SetDetailedStatus(status string) { p.status = status } +// SetConnectionDuration sets the proc's connection duration +func (p *Proc) SetConnectionDuration(dur int64) { + p.connDurationMu.Lock() + defer p.connDurationMu.Unlock() + p.connDuration = dur +} + +// ConnectionDuration gets proc's connection duration +func (p *Proc) ConnectionDuration() int64 { + p.connDurationMu.RLock() + defer p.connDurationMu.RUnlock() + return p.connDuration +} + // DetailedStatus gets proc's detailed status. func (p *Proc) DetailedStatus() string { p.statusMx.RLock() diff --git a/pkg/app/appserver/proc_manager.go b/pkg/app/appserver/proc_manager.go index 2992fcd60e..df35f58163 100644 --- a/pkg/app/appserver/proc_manager.go +++ b/pkg/app/appserver/proc_manager.go @@ -277,7 +277,8 @@ func (m *procManager) Stats(appName string) (AppStats, error) { } stats := AppStats{ - Connections: p.ConnectionsSummary(), + Connections: p.ConnectionsSummary(), + ConnectionDuration: p.ConnectionDuration(), } startTime, ok := p.StartTime() diff --git a/pkg/app/appserver/rpc_ingress_client.go b/pkg/app/appserver/rpc_ingress_client.go index 2558da1a82..c1957e33c0 100644 --- a/pkg/app/appserver/rpc_ingress_client.go +++ b/pkg/app/appserver/rpc_ingress_client.go @@ -15,6 +15,7 @@ import ( // RPCIngressClient describes RPC interface to communicate with the server. type RPCIngressClient interface { SetDetailedStatus(status string) error + SetConnectionDuration(dur int64) error Dial(remote appnet.Addr) (connID uint16, localPort routing.Port, err error) Listen(local appnet.Addr) (uint16, error) Accept(lisID uint16) (connID uint16, remote appnet.Addr, err error) @@ -46,6 +47,11 @@ func (c *rpcIngressClient) SetDetailedStatus(status string) error { return c.rpc.Call(c.formatMethod("SetDetailedStatus"), &status, nil) } +// SetConnectionDuration sets the connection duration for an app +func (c *rpcIngressClient) SetConnectionDuration(dur int64) error { + return c.rpc.Call(c.formatMethod("SetConnectionDuration"), dur, nil) +} + // Dial sends `Dial` command to the server. func (c *rpcIngressClient) Dial(remote appnet.Addr) (connID uint16, localPort routing.Port, err error) { var resp DialResp diff --git a/pkg/app/appserver/rpc_ingress_gateway.go b/pkg/app/appserver/rpc_ingress_gateway.go index b452ebf590..025dcf0d49 100644 --- a/pkg/app/appserver/rpc_ingress_gateway.go +++ b/pkg/app/appserver/rpc_ingress_gateway.go @@ -85,6 +85,13 @@ func (r *RPCIngressGateway) SetDetailedStatus(status *string, _ *struct{}) (err return nil } +// SetConnectionDuration sets the connection duration of an app (vpn-client in this instance) +func (r *RPCIngressGateway) SetConnectionDuration(dur int64, _ *struct{}) (err error) { + defer rpcutil.LogCall(r.log, "SetConnectionDuration", dur)(nil, &err) + r.proc.SetConnectionDuration(dur) + return nil +} + // DialResp contains response parameters for `Dial`. type DialResp struct { ConnID uint16 diff --git a/pkg/app/client.go b/pkg/app/client.go index 8ad159586d..1629ab3f32 100644 --- a/pkg/app/client.go +++ b/pkg/app/client.go @@ -68,6 +68,11 @@ func (c *Client) SetDetailedStatus(status string) error { return c.rpcC.SetDetailedStatus(status) } +// SetConnectionDuration sets the detailed app connection duration within the visor. +func (c *Client) SetConnectionDuration(dur int64) error { + return c.rpcC.SetConnectionDuration(dur) +} + // Dial dials the remote visor using `remote`. func (c *Client) Dial(remote appnet.Addr) (net.Conn, error) { connID, localPort, err := c.rpcC.Dial(remote) diff --git a/pkg/app/launcher/app_state.go b/pkg/app/launcher/app_state.go index d48f11e8e9..4afd185bd4 100644 --- a/pkg/app/launcher/app_state.go +++ b/pkg/app/launcher/app_state.go @@ -14,6 +14,7 @@ const ( // AppState defines state parameters for a registered App. type AppState struct { AppConfig - Status AppStatus `json:"status"` - DetailedStatus string `json:"detailed_status"` + Status AppStatus `json:"status"` + DetailedStatus string `json:"detailed_status"` + ConnectionDuration int64 `json:"connection_duration,omitempty"` } diff --git a/pkg/app/launcher/launcher.go b/pkg/app/launcher/launcher.go index d67f6fee0d..1e3369a9c1 100644 --- a/pkg/app/launcher/launcher.go +++ b/pkg/app/launcher/launcher.go @@ -192,6 +192,7 @@ func (l *Launcher) AppStates() []*AppState { connSummary := proc.ConnectionsSummary() if connSummary != nil { state.Status = AppStatusRunning + state.ConnectionDuration = proc.ConnectionDuration() } } states = append(states, state) diff --git a/pkg/routefinder/rfclient/mock_client.go b/pkg/routefinder/rfclient/mock_client.go index b0b6242019..decbba4c0f 100644 --- a/pkg/routefinder/rfclient/mock_client.go +++ b/pkg/routefinder/rfclient/mock_client.go @@ -5,9 +5,8 @@ package rfclient import ( context "context" - mock "github.com/stretchr/testify/mock" - routing "github.com/skycoin/skywire/pkg/routing" + mock "github.com/stretchr/testify/mock" ) // MockClient is an autogenerated mock type for the Client type diff --git a/pkg/router/mock_router.go b/pkg/router/mock_router.go index ff271b86ce..6b1865b74f 100644 --- a/pkg/router/mock_router.go +++ b/pkg/router/mock_router.go @@ -4,11 +4,13 @@ package router import ( context "context" - net "net" cipher "github.com/skycoin/dmsg/cipher" + mock "github.com/stretchr/testify/mock" + net "net" + routing "github.com/skycoin/skywire/pkg/routing" ) diff --git a/pkg/setup/mock_id_reserver.go b/pkg/setup/mock_id_reserver.go index 351a2d0fc5..8e8eace704 100644 --- a/pkg/setup/mock_id_reserver.go +++ b/pkg/setup/mock_id_reserver.go @@ -6,9 +6,11 @@ import ( context "context" cipher "github.com/skycoin/dmsg/cipher" + mock "github.com/stretchr/testify/mock" routerclient "github.com/skycoin/skywire/pkg/router/routerclient" + routing "github.com/skycoin/skywire/pkg/routing" ) diff --git a/pkg/setup/setupclient/mock_route_group_dialer.go b/pkg/setup/setupclient/mock_route_group_dialer.go new file mode 100644 index 0000000000..2193909f8c --- /dev/null +++ b/pkg/setup/setupclient/mock_route_group_dialer.go @@ -0,0 +1,43 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +package setupclient + +import ( + context "context" + + cipher "github.com/skycoin/dmsg/cipher" + + dmsg "github.com/skycoin/dmsg" + + logging "github.com/skycoin/skycoin/src/util/logging" + + mock "github.com/stretchr/testify/mock" + + routing "github.com/skycoin/skywire/pkg/routing" +) + +// MockRouteGroupDialer is an autogenerated mock type for the RouteGroupDialer type +type MockRouteGroupDialer struct { + mock.Mock +} + +// Dial provides a mock function with given fields: ctx, log, dmsgC, setupNodes, req +func (_m *MockRouteGroupDialer) Dial(ctx context.Context, log *logging.Logger, dmsgC *dmsg.Client, setupNodes []cipher.PubKey, req routing.BidirectionalRoute) (routing.EdgeRules, error) { + ret := _m.Called(ctx, log, dmsgC, setupNodes, req) + + var r0 routing.EdgeRules + if rf, ok := ret.Get(0).(func(context.Context, *logging.Logger, *dmsg.Client, []cipher.PubKey, routing.BidirectionalRoute) routing.EdgeRules); ok { + r0 = rf(ctx, log, dmsgC, setupNodes, req) + } else { + r0 = ret.Get(0).(routing.EdgeRules) + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *logging.Logger, *dmsg.Client, []cipher.PubKey, routing.BidirectionalRoute) error); ok { + r1 = rf(ctx, log, dmsgC, setupNodes, req) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} diff --git a/pkg/transport/network/addrresolver/mock_api_client.go b/pkg/transport/network/addrresolver/mock_api_client.go index a6cd7281d6..c8ccca07a3 100644 --- a/pkg/transport/network/addrresolver/mock_api_client.go +++ b/pkg/transport/network/addrresolver/mock_api_client.go @@ -5,9 +5,11 @@ package addrresolver import ( context "context" - pfilter "github.com/AudriusButkevicius/pfilter" cipher "github.com/skycoin/dmsg/cipher" + mock "github.com/stretchr/testify/mock" + + pfilter "github.com/AudriusButkevicius/pfilter" ) // MockAPIClient is an autogenerated mock type for the APIClient type @@ -29,13 +31,13 @@ func (_m *MockAPIClient) BindSTCPR(ctx context.Context, port string) error { return r0 } -// BindSUDPH provides a mock function with given fields: filter +// BindSUDPH provides a mock function with given fields: filter, handshake func (_m *MockAPIClient) BindSUDPH(filter *pfilter.PacketFilter, handshake Handshake) (<-chan RemoteVisor, error) { - ret := _m.Called(filter) + ret := _m.Called(filter, handshake) var r0 <-chan RemoteVisor - if rf, ok := ret.Get(0).(func(*pfilter.PacketFilter) <-chan RemoteVisor); ok { - r0 = rf(filter) + if rf, ok := ret.Get(0).(func(*pfilter.PacketFilter, Handshake) <-chan RemoteVisor); ok { + r0 = rf(filter, handshake) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(<-chan RemoteVisor) @@ -43,8 +45,8 @@ func (_m *MockAPIClient) BindSUDPH(filter *pfilter.PacketFilter, handshake Hands } var r1 error - if rf, ok := ret.Get(1).(func(*pfilter.PacketFilter) error); ok { - r1 = rf(filter) + if rf, ok := ret.Get(1).(func(*pfilter.PacketFilter, Handshake) error); ok { + r1 = rf(filter, handshake) } else { r1 = ret.Error(1) } @@ -87,20 +89,20 @@ func (_m *MockAPIClient) Health(ctx context.Context) (int, error) { return r0, r1 } -// Resolve provides a mock function with given fields: ctx, tType, pk -func (_m *MockAPIClient) Resolve(ctx context.Context, tType string, pk cipher.PubKey) (VisorData, error) { - ret := _m.Called(ctx, tType, pk) +// Resolve provides a mock function with given fields: ctx, netType, pk +func (_m *MockAPIClient) Resolve(ctx context.Context, netType string, pk cipher.PubKey) (VisorData, error) { + ret := _m.Called(ctx, netType, pk) var r0 VisorData if rf, ok := ret.Get(0).(func(context.Context, string, cipher.PubKey) VisorData); ok { - r0 = rf(ctx, tType, pk) + r0 = rf(ctx, netType, pk) } else { r0 = ret.Get(0).(VisorData) } var r1 error if rf, ok := ret.Get(1).(func(context.Context, string, cipher.PubKey) error); ok { - r1 = rf(ctx, tType, pk) + r1 = rf(ctx, netType, pk) } else { r1 = ret.Error(1) } diff --git a/pkg/transport/network/mock_dialer.go b/pkg/transport/network/mock_dialer.go index e0cef6585f..b9278f7fee 100644 --- a/pkg/transport/network/mock_dialer.go +++ b/pkg/transport/network/mock_dialer.go @@ -4,10 +4,12 @@ package network import ( context "context" - net "net" cipher "github.com/skycoin/dmsg/cipher" + mock "github.com/stretchr/testify/mock" + + net "net" ) // MockDialer is an autogenerated mock type for the Dialer type diff --git a/pkg/visor/hypervisorconfig/README.md b/pkg/visor/hypervisorconfig/README.md index 9d469d0f2b..b98bc9b925 100644 --- a/pkg/visor/hypervisorconfig/README.md +++ b/pkg/visor/hypervisorconfig/README.md @@ -1,11 +1,8 @@ # Config -- `-` (PubKey) -- `-` (SecKey) - `db_path` (string) - `enable_auth` (bool) - `cookies` ([CookieConfig](#CookieConfig)) -- `-` (string) - `dmsg_port` (uint16) - `http_addr` (string) - `enable_tls` (bool) @@ -20,4 +17,3 @@ - `expires_duration` (Duration) - `path` (string) - `domain` (string) -- `-` (bool) diff --git a/pkg/visor/visorconfig/README.md b/pkg/visor/visorconfig/README.md index a7aa361702..96c3846d75 100644 --- a/pkg/visor/visorconfig/README.md +++ b/pkg/visor/visorconfig/README.md @@ -1,7 +1,5 @@ # V1 -- `` (*[Common](#Common)) -- `mu` ([RWMutex](#RWMutex)) - `dmsg` (*[DmsgConfig](#DmsgConfig)) - `dmsgpty` (*[V1Dmsgpty](#V1Dmsgpty)) - `stcp` (*[STCPConfig](#STCPConfig)) @@ -12,68 +10,55 @@ - `hypervisors` () - `cli_addr` (string) - `log_level` (string) +- `local_path` (string) +- `stun_servers` ([]string) - `shutdown_timeout` (Duration) -- `restart_check_delay` (string) -- `public_trusted_visor` (bool) +- `restart_check_delay` (Duration) +- `is_public` (bool) +- `persistent_transports` ([][PersistentTransports](#PersistentTransports)) - `hypervisor` (*[Config](#Config)) -# V1UptimeTracker +# V1Launcher -- `addr` (string) +- `service_discovery` (string) +- `apps` ([][AppConfig](#AppConfig)) +- `server_addr` (string) +- `bin_path` (string) # V1Transport - `discovery` (string) - `address_resolver` (string) -- `log_store` (*[V1LogStore](#V1LogStore)) -- `trusted_visors` () - - -# V1Launcher - -- `discovery` (*[V1AppDisc](#V1AppDisc)) -- `apps` ([][AppConfig](#AppConfig)) -- `server_addr` (string) -- `bin_path` (string) -- `local_path` (string) +- `public_autoconnect` (bool) +- `transport_setup_nodes` () -# V1AppDisc +# V1Routing -- `update_interval` (Duration) -- `service_discovery` (string) +- `setup_nodes` () +- `route_finder` (string) +- `route_finder_timeout` (Duration) +- `min_hops` (uint16) -# V1LogStore +# V1UptimeTracker -- `type` (string) - Type defines the log store type. Valid values: file, memory. -- `location` (string) +- `addr` (string) # V1Dmsgpty - `port` (uint16) -- `authorization_file` (string) - `cli_network` (string) - `cli_address` (string) -# V1Routing - -- `setup_nodes` () -- `route_finder` (string) -- `route_finder_timeout` (Duration) +# PersistentTransports - -# Common - -- `path` (string) -- `log` (*[MasterLogger](#MasterLogger)) -- `version` (string) -- `sk` (SecKey) - `pk` (PubKey) +- `type` (Type) # DmsgConfig @@ -82,14 +67,17 @@ - `sessions_count` (int) +# STCPConfig + +- `pk_table` () +- `local_address` (string) + + # Config -- `-` (PubKey) -- `-` (SecKey) - `db_path` (string) - `enable_auth` (bool) - `cookies` ([CookieConfig](#CookieConfig)) -- `-` (string) - `dmsg_port` (uint16) - `http_addr` (string) - `enable_tls` (bool) @@ -104,38 +92,6 @@ - `expires_duration` (Duration) - `path` (string) - `domain` (string) -- `-` (bool) - - -# RWMutex - -- `w` ([Mutex](#Mutex)) -- `writerSem` (uint32) -- `readerSem` (uint32) -- `readerCount` (int32) -- `readerWait` (int32) - - -# Mutex - -- `state` (int32) -- `sema` (uint32) - - -# STCPConfig - -- `pk_table` () -- `local_address` (string) - - -# MasterLogger - -- `` (*[Logger](#Logger)) - - -# Logger - -- `` (FieldLogger) # AppConfig From eb4b1370c7be6d91353b828114de2fcdb702e1d8 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Tue, 5 Oct 2021 22:37:05 +0700 Subject: [PATCH 3/7] atomic load --- internal/vpn/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/vpn/client.go b/internal/vpn/client.go index bdf011c45e..fbf05a6ece 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -738,7 +738,7 @@ func (c *Client) setAppStatus(status ClientStatus) { } func (c *Client) setConnectionDuration() { - if err := c.appCl.SetConnectionDuration(c.connectedDuration); err != nil { + if err := c.appCl.SetConnectionDuration(atomic.LoadInt64(&c.connectedDuration)); err != nil { fmt.Printf("Failed to set connection duration: %v\n", err) } } From 06dda5ef6bb6ed9c064173ab25b127f0546d8b85 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Thu, 7 Oct 2021 11:58:27 +0700 Subject: [PATCH 4/7] fixes formatting --- internal/vpn/client.go | 5 +---- pkg/app/appevent/mock_rpc_client.go | 4 ++-- pkg/app/appserver/mock_proc_manager.go | 5 +++-- pkg/app/appserver/mock_rpc_ingress_client.go | 6 +++--- pkg/app/appserver/proc.go | 4 ++-- pkg/routefinder/rfclient/mock_client.go | 3 ++- pkg/router/mock_router.go | 4 +--- pkg/setup/mock_id_reserver.go | 2 -- pkg/setup/setupclient/mock_route_group_dialer.go | 5 +---- pkg/transport/network/addrresolver/mock_api_client.go | 4 +--- pkg/transport/network/mock_dialer.go | 4 +--- 11 files changed, 17 insertions(+), 29 deletions(-) diff --git a/internal/vpn/client.go b/internal/vpn/client.go index bc71b69995..bd0e8e8ce1 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -268,10 +268,7 @@ func (c *Client) removeDirectRouteFn(ip net.IP, i int) error { } defer c.releaseSysPrivileges() - if err := c.removeDirectRoute(ip); err != nil { - return err - } - return nil + return c.removeDirectRoute(ip) } // RemoveDirectRoute removes direct route. Packets destined to `ip` will diff --git a/pkg/app/appevent/mock_rpc_client.go b/pkg/app/appevent/mock_rpc_client.go index 393e3af472..cb04624faf 100644 --- a/pkg/app/appevent/mock_rpc_client.go +++ b/pkg/app/appevent/mock_rpc_client.go @@ -5,9 +5,9 @@ package appevent import ( context "context" - appcommon "github.com/skycoin/skywire/pkg/app/appcommon" - mock "github.com/stretchr/testify/mock" + + appcommon "github.com/skycoin/skywire/pkg/app/appcommon" ) // MockRPCClient is an autogenerated mock type for the RPCClient type diff --git a/pkg/app/appserver/mock_proc_manager.go b/pkg/app/appserver/mock_proc_manager.go index ec2b9910b0..66135ebce5 100644 --- a/pkg/app/appserver/mock_proc_manager.go +++ b/pkg/app/appserver/mock_proc_manager.go @@ -3,10 +3,11 @@ package appserver import ( - appcommon "github.com/skycoin/skywire/pkg/app/appcommon" + net "net" + mock "github.com/stretchr/testify/mock" - net "net" + appcommon "github.com/skycoin/skywire/pkg/app/appcommon" ) // MockProcManager is an autogenerated mock type for the ProcManager type diff --git a/pkg/app/appserver/mock_rpc_ingress_client.go b/pkg/app/appserver/mock_rpc_ingress_client.go index 709b596007..5d42d2aa58 100644 --- a/pkg/app/appserver/mock_rpc_ingress_client.go +++ b/pkg/app/appserver/mock_rpc_ingress_client.go @@ -3,12 +3,12 @@ package appserver import ( - appnet "github.com/skycoin/skywire/pkg/app/appnet" + time "time" + mock "github.com/stretchr/testify/mock" + appnet "github.com/skycoin/skywire/pkg/app/appnet" routing "github.com/skycoin/skywire/pkg/routing" - - time "time" ) // MockRPCIngressClient is an autogenerated mock type for the RPCIngressClient type diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index a6fe6ea953..c176717f3b 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -57,8 +57,8 @@ type Proc struct { connDuration int64 connDurationMu sync.RWMutex - errMx sync.RWMutex - err string + errMx sync.RWMutex + err string } // NewProc constructs `Proc`. diff --git a/pkg/routefinder/rfclient/mock_client.go b/pkg/routefinder/rfclient/mock_client.go index decbba4c0f..b0b6242019 100644 --- a/pkg/routefinder/rfclient/mock_client.go +++ b/pkg/routefinder/rfclient/mock_client.go @@ -5,8 +5,9 @@ package rfclient import ( context "context" - routing "github.com/skycoin/skywire/pkg/routing" mock "github.com/stretchr/testify/mock" + + routing "github.com/skycoin/skywire/pkg/routing" ) // MockClient is an autogenerated mock type for the Client type diff --git a/pkg/router/mock_router.go b/pkg/router/mock_router.go index 6b1865b74f..ff271b86ce 100644 --- a/pkg/router/mock_router.go +++ b/pkg/router/mock_router.go @@ -4,13 +4,11 @@ package router import ( context "context" + net "net" cipher "github.com/skycoin/dmsg/cipher" - mock "github.com/stretchr/testify/mock" - net "net" - routing "github.com/skycoin/skywire/pkg/routing" ) diff --git a/pkg/setup/mock_id_reserver.go b/pkg/setup/mock_id_reserver.go index 8e8eace704..351a2d0fc5 100644 --- a/pkg/setup/mock_id_reserver.go +++ b/pkg/setup/mock_id_reserver.go @@ -6,11 +6,9 @@ import ( context "context" cipher "github.com/skycoin/dmsg/cipher" - mock "github.com/stretchr/testify/mock" routerclient "github.com/skycoin/skywire/pkg/router/routerclient" - routing "github.com/skycoin/skywire/pkg/routing" ) diff --git a/pkg/setup/setupclient/mock_route_group_dialer.go b/pkg/setup/setupclient/mock_route_group_dialer.go index 2193909f8c..8e38eff154 100644 --- a/pkg/setup/setupclient/mock_route_group_dialer.go +++ b/pkg/setup/setupclient/mock_route_group_dialer.go @@ -5,12 +5,9 @@ package setupclient import ( context "context" - cipher "github.com/skycoin/dmsg/cipher" - dmsg "github.com/skycoin/dmsg" - + cipher "github.com/skycoin/dmsg/cipher" logging "github.com/skycoin/skycoin/src/util/logging" - mock "github.com/stretchr/testify/mock" routing "github.com/skycoin/skywire/pkg/routing" diff --git a/pkg/transport/network/addrresolver/mock_api_client.go b/pkg/transport/network/addrresolver/mock_api_client.go index c8ccca07a3..c078b497f4 100644 --- a/pkg/transport/network/addrresolver/mock_api_client.go +++ b/pkg/transport/network/addrresolver/mock_api_client.go @@ -5,11 +5,9 @@ package addrresolver import ( context "context" + pfilter "github.com/AudriusButkevicius/pfilter" cipher "github.com/skycoin/dmsg/cipher" - mock "github.com/stretchr/testify/mock" - - pfilter "github.com/AudriusButkevicius/pfilter" ) // MockAPIClient is an autogenerated mock type for the APIClient type diff --git a/pkg/transport/network/mock_dialer.go b/pkg/transport/network/mock_dialer.go index b9278f7fee..e0cef6585f 100644 --- a/pkg/transport/network/mock_dialer.go +++ b/pkg/transport/network/mock_dialer.go @@ -4,12 +4,10 @@ package network import ( context "context" + net "net" cipher "github.com/skycoin/dmsg/cipher" - mock "github.com/stretchr/testify/mock" - - net "net" ) // MockDialer is an autogenerated mock type for the Dialer type From 382e79a6211f851a18e58bc4469f90e95d3942eb Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Fri, 8 Oct 2021 02:05:57 +0700 Subject: [PATCH 5/7] move duration to /connections endpoint --- pkg/app/appserver/app_stats.go | 1 - pkg/app/appserver/proc.go | 28 +++++++++++++++------------- pkg/app/appserver/proc_manager.go | 1 - pkg/app/launcher/app_state.go | 1 - pkg/app/launcher/launcher.go | 1 - 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/pkg/app/appserver/app_stats.go b/pkg/app/appserver/app_stats.go index a6295d6603..33d8d99b0e 100644 --- a/pkg/app/appserver/app_stats.go +++ b/pkg/app/appserver/app_stats.go @@ -8,5 +8,4 @@ import ( type AppStats struct { Connections []ConnectionSummary `json:"connections"` StartTime *time.Time `json:"start_time,omitempty"` - ConnectionDuration int64 `json:"connection_duration,omitempty"` } diff --git a/pkg/app/appserver/proc.go b/pkg/app/appserver/proc.go index c176717f3b..9a0cab4a13 100644 --- a/pkg/app/appserver/proc.go +++ b/pkg/app/appserver/proc.go @@ -324,13 +324,14 @@ func (p *Proc) Error() string { // ConnectionSummary sums up the connection stats. type ConnectionSummary struct { - IsAlive bool `json:"is_alive"` - Latency time.Duration `json:"latency"` - UploadSpeed uint32 `json:"upload_speed"` - DownloadSpeed uint32 `json:"download_speed"` - BandwidthSent uint64 `json:"bandwidth_sent"` - BandwidthReceived uint64 `json:"bandwidth_received"` - Error string `json:"error"` + IsAlive bool `json:"is_alive"` + Latency time.Duration `json:"latency"` + UploadSpeed uint32 `json:"upload_speed"` + DownloadSpeed uint32 `json:"download_speed"` + BandwidthSent uint64 `json:"bandwidth_sent"` + BandwidthReceived uint64 `json:"bandwidth_received"` + Error string `json:"error"` + ConnectionDuration int64 `json:"connection_duration,omitempty"` } // ConnectionsSummary returns all of the proc's connections stats. @@ -366,12 +367,13 @@ func (p *Proc) ConnectionsSummary() []ConnectionSummary { } summaries = append(summaries, ConnectionSummary{ - IsAlive: skywireConn.IsAlive(), - Latency: skywireConn.Latency(), - UploadSpeed: skywireConn.UploadSpeed(), - DownloadSpeed: skywireConn.DownloadSpeed(), - BandwidthSent: skywireConn.BandwidthSent(), - BandwidthReceived: skywireConn.BandwidthReceived(), + IsAlive: skywireConn.IsAlive(), + Latency: skywireConn.Latency(), + UploadSpeed: skywireConn.UploadSpeed(), + DownloadSpeed: skywireConn.DownloadSpeed(), + BandwidthSent: skywireConn.BandwidthSent(), + BandwidthReceived: skywireConn.BandwidthReceived(), + ConnectionDuration: p.ConnectionDuration(), }) return true diff --git a/pkg/app/appserver/proc_manager.go b/pkg/app/appserver/proc_manager.go index 287729651d..72ff36745a 100644 --- a/pkg/app/appserver/proc_manager.go +++ b/pkg/app/appserver/proc_manager.go @@ -290,7 +290,6 @@ func (m *procManager) Stats(appName string) (AppStats, error) { stats := AppStats{ Connections: p.ConnectionsSummary(), - ConnectionDuration: p.ConnectionDuration(), } startTime, ok := p.StartTime() diff --git a/pkg/app/launcher/app_state.go b/pkg/app/launcher/app_state.go index 597e465e19..6142bbe320 100644 --- a/pkg/app/launcher/app_state.go +++ b/pkg/app/launcher/app_state.go @@ -19,5 +19,4 @@ type AppState struct { AppConfig Status AppStatus `json:"status"` DetailedStatus string `json:"detailed_status"` - ConnectionDuration int64 `json:"connection_duration,omitempty"` } diff --git a/pkg/app/launcher/launcher.go b/pkg/app/launcher/launcher.go index d8b2f2d4cf..304337a6fb 100644 --- a/pkg/app/launcher/launcher.go +++ b/pkg/app/launcher/launcher.go @@ -199,7 +199,6 @@ func (l *Launcher) AppStates() []*AppState { connSummary := proc.ConnectionsSummary() if connSummary != nil { state.Status = AppStatusRunning - state.ConnectionDuration = proc.ConnectionDuration() } } states = append(states, state) From 21b54ce820437445fe0e7b279bfc1063301f1874 Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Fri, 8 Oct 2021 02:10:21 +0700 Subject: [PATCH 6/7] formatting --- cmd/skywire-visor/commands/root.go | 5 ++--- pkg/app/appserver/app_stats.go | 4 ++-- pkg/app/appserver/proc_manager.go | 2 +- pkg/app/launcher/app_state.go | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/skywire-visor/commands/root.go b/cmd/skywire-visor/commands/root.go index d6783b978d..be4062370a 100644 --- a/cmd/skywire-visor/commands/root.go +++ b/cmd/skywire-visor/commands/root.go @@ -2,8 +2,10 @@ package commands import ( "context" + "embed" "fmt" "io" + "io/fs" "io/ioutil" "net/http" _ "net/http/pprof" // nolint:gosec // https://golang.org/doc/diagnostics.html#profiling @@ -15,9 +17,6 @@ import ( "syscall" "time" - "embed" - "io/fs" - "github.com/pkg/profile" "github.com/skycoin/dmsg/buildinfo" "github.com/skycoin/dmsg/cmdutil" diff --git a/pkg/app/appserver/app_stats.go b/pkg/app/appserver/app_stats.go index 33d8d99b0e..2a454555fb 100644 --- a/pkg/app/appserver/app_stats.go +++ b/pkg/app/appserver/app_stats.go @@ -6,6 +6,6 @@ import ( // AppStats contains app runtime statistics. type AppStats struct { - Connections []ConnectionSummary `json:"connections"` - StartTime *time.Time `json:"start_time,omitempty"` + Connections []ConnectionSummary `json:"connections"` + StartTime *time.Time `json:"start_time,omitempty"` } diff --git a/pkg/app/appserver/proc_manager.go b/pkg/app/appserver/proc_manager.go index 72ff36745a..dc359b97d4 100644 --- a/pkg/app/appserver/proc_manager.go +++ b/pkg/app/appserver/proc_manager.go @@ -289,7 +289,7 @@ func (m *procManager) Stats(appName string) (AppStats, error) { } stats := AppStats{ - Connections: p.ConnectionsSummary(), + Connections: p.ConnectionsSummary(), } startTime, ok := p.StartTime() diff --git a/pkg/app/launcher/app_state.go b/pkg/app/launcher/app_state.go index 6142bbe320..3ff33130a0 100644 --- a/pkg/app/launcher/app_state.go +++ b/pkg/app/launcher/app_state.go @@ -17,6 +17,6 @@ const ( // AppState defines state parameters for a registered App. type AppState struct { AppConfig - Status AppStatus `json:"status"` - DetailedStatus string `json:"detailed_status"` + Status AppStatus `json:"status"` + DetailedStatus string `json:"detailed_status"` } From b0ed94ea3ac89d099b30d5b58fe664daf42ae78a Mon Sep 17 00:00:00 2001 From: Alexander Adhyatma Date: Fri, 8 Oct 2021 22:30:25 +0700 Subject: [PATCH 7/7] added changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 467ba9661c..58aecb5370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - added public_autoconnect field to transport section - added transport_setup_nodes field to transport section - added MinHops field to V1Routing section of config +- added connection_duration field to `/api/visor/{pk}/apps/vpn-client/connections` ## 0.2.1 - 2020.04.07