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

VPN improvements #491

Merged
merged 35 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
44ffef2
Add `IsAlive` to route group and skywire app conn
Darkren Aug 21, 2020
aa54554
Provide hypervisor API method to get app connections info
Darkren Aug 21, 2020
200b432
Regenerate mocks
Darkren Aug 21, 2020
d251e0c
Fix visor's mock RPC client
Darkren Aug 21, 2020
e3d3f68
Export `NoiseRouteGroup`, fix hypervisor panic
Darkren Aug 21, 2020
2f3ce95
Fix hypervisor panic
Darkren Aug 21, 2020
46f274f
Add network probe packets
Darkren Aug 24, 2020
cc1398f
Make route group handle network probe packet
Darkren Aug 24, 2020
3be70ca
Make `ConnectionsSummary` API call return latency, throughput, bandwi…
Darkren Aug 24, 2020
026ffbc
Fix hypervisor panic on nil connection, while collecting summary
Darkren Aug 25, 2020
38c9a11
Fix panic again
Darkren Aug 25, 2020
82b6a3b
Temporarily remove network probe sending
Darkren Aug 25, 2020
dc7c1ac
Revert
Darkren Aug 25, 2020
4d796db
Add debug logs, start service loops after wrapping RG with noise
Darkren Aug 25, 2020
c96f3d7
Add debug logs
Darkren Aug 25, 2020
3da1903
Comment out part
Darkren Aug 25, 2020
232b949
Fix
Darkren Aug 25, 2020
c3fd7ea
Debug
Darkren Aug 25, 2020
1881c9a
Add debug logs
Darkren Aug 25, 2020
0a96730
Fix network probe packet size
Darkren Aug 25, 2020
412944a
Revert network probe packet handling
Darkren Aug 25, 2020
8e0f58f
Add debug logs
Darkren Aug 25, 2020
7847618
Add debug log
Darkren Aug 25, 2020
ce9c599
Add debug logs
Darkren Aug 25, 2020
6c9e61e
Add debug logs
Darkren Aug 25, 2020
109859d
Add debug log
Darkren Aug 25, 2020
774d6fc
Fix latency response
Darkren Aug 25, 2020
6483080
Remove unused function
Darkren Aug 25, 2020
fc5ca1c
Refactor code a bit
Darkren Aug 25, 2020
0cd67b3
Make linter happy
Darkren Aug 25, 2020
5330591
Remove debug logs
Darkren Aug 25, 2020
1f06331
Resort some imports
Darkren Aug 25, 2020
f89dade
Merge branch 'develop' of github.com:skycoin/skywire into feature/vpn…
Darkren Aug 28, 2020
06d9033
Make bandwidth fields uint64
Darkren Sep 28, 2020
da7a697
Merge branch 'feature/v0.4.0' of github.com:skycoin/skywire into feat…
Darkren Sep 28, 2020
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
7 changes: 2 additions & 5 deletions internal/utclient/mock_api_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions pkg/app/appevent/mock_rpc_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions pkg/app/appnet/mock_networker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions pkg/app/appnet/skywire_conn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package appnet

import (
"net"
"sync"
"time"

"github.com/skycoin/skywire/pkg/router"
)

// SkywireConn is a connection wrapper for skynet.
type SkywireConn struct {
net.Conn
nrg *router.NoiseRouteGroup
freePort func()
freePortMx sync.RWMutex
once sync.Once
}

// IsAlive checks whether connection is alive.
func (c *SkywireConn) IsAlive() bool {
return c.nrg.IsAlive()
}

// Latency returns latency till remote (ms).
func (c *SkywireConn) Latency() time.Duration {
return c.nrg.Latency()
}

// Throughput returns throughput till remote (bytes/s).
func (c *SkywireConn) Throughput() uint32 {
return c.nrg.Throughput()
}

// BandwidthSent returns amount of bandwidth sent (bytes).
func (c *SkywireConn) BandwidthSent() uint64 {
return c.nrg.BandwidthSent()
}

// Close closes connection.
func (c *SkywireConn) Close() error {
var err error

c.once.Do(func() {
defer func() {
c.freePortMx.RLock()
defer c.freePortMx.RUnlock()
if c.freePort != nil {
c.freePort()
}
}()

err = c.Conn.Close()
})

return err
}
35 changes: 6 additions & 29 deletions pkg/app/appnet/skywire_networker.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ func (r *SkywireNetworker) DialContext(ctx context.Context, addr Addr) (conn net
return nil, err
}

return &skywireConn{
return &SkywireConn{
Conn: conn,
nrg: conn.(*router.NoiseRouteGroup),
freePort: freePort,
}, nil
}
Expand Down Expand Up @@ -178,7 +179,10 @@ func (l *skywireListener) Accept() (net.Conn, error) {
return nil, errors.New("listening on closed connection")
}

return conn, nil
return &SkywireConn{
Conn: conn,
nrg: conn.(*router.NoiseRouteGroup),
}, nil
}

// Close closes listener.
Expand All @@ -203,30 +207,3 @@ func (l *skywireListener) Addr() net.Addr {
func (l *skywireListener) putConn(conn net.Conn) {
l.connsCh <- conn
}

// skywireConn is a connection wrapper for skynet.
type skywireConn struct {
net.Conn
freePort func()
freePortMx sync.RWMutex
once sync.Once
}

// Close closes connection.
func (c *skywireConn) Close() error {
var err error

c.once.Do(func() {
defer func() {
c.freePortMx.RLock()
defer c.freePortMx.RUnlock()
if c.freePort != nil {
c.freePort()
}
}()

err = c.Conn.Close()
})

return err
}
32 changes: 26 additions & 6 deletions pkg/app/appserver/mock_proc_manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions pkg/app/appserver/mock_rpc_ingress_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions pkg/app/appserver/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"strings"
"sync"
"sync/atomic"
"time"

"github.com/skycoin/skycoin/src/util/logging"

"github.com/skycoin/skywire/pkg/app/appcommon"
"github.com/skycoin/skywire/pkg/app/appdisc"
"github.com/skycoin/skywire/pkg/app/appnet"
)

var (
Expand All @@ -38,6 +40,7 @@ type Proc struct {
waitMx sync.Mutex
waitErr error

rpcGWMu sync.Mutex
rpcGW *RPCIngressGateway // gateway shared over 'conn' - introduced AFTER proc is started
conn net.Conn // connection to proc - introduced AFTER proc is started
connCh chan struct{} // push here when conn is received - protected by 'connOnce'
Expand Down Expand Up @@ -94,7 +97,9 @@ func (p *Proc) InjectConn(conn net.Conn) bool {
p.connOnce.Do(func() {
ok = true
p.conn = conn
p.rpcGWMu.Lock()
p.rpcGW = NewRPCGateway(p.log)
p.rpcGWMu.Unlock()

// Send ready signal.
p.connCh <- struct{}{}
Expand Down Expand Up @@ -254,3 +259,57 @@ func (p *Proc) Wait() error {
func (p *Proc) IsRunning() bool {
return atomic.LoadInt32(&p.isRunning) == 1
}

// ConnectionSummary sums up the connection stats.
type ConnectionSummary struct {
IsAlive bool `json:"is_alive"`
Latency time.Duration `json:"latency"`
Throughput uint32 `json:"throughput"`
BandwidthSent uint64 `json:"bandwidth_sent"`
Error string `json:"error"`
}

// ConnectionsSummary returns all of the proc's connections stats.
func (p *Proc) ConnectionsSummary() []ConnectionSummary {
p.rpcGWMu.Lock()
rpcGW := p.rpcGW
p.rpcGWMu.Unlock()

if rpcGW == nil {
return nil
}

var summaries []ConnectionSummary
rpcGW.cm.DoRange(func(id uint16, v interface{}) bool {
if v == nil {
summaries = append(summaries, ConnectionSummary{})
return true
}

conn, ok := v.(net.Conn)
if !ok {
summaries = append(summaries, ConnectionSummary{})
}

wrappedConn := conn.(*appnet.WrappedConn)

skywireConn, isSkywireConn := wrappedConn.Conn.(*appnet.SkywireConn)
if !isSkywireConn {
summaries = append(summaries, ConnectionSummary{
Error: "Can't get such info from this conn",
})
return true
}

summaries = append(summaries, ConnectionSummary{
IsAlive: skywireConn.IsAlive(),
Latency: skywireConn.Latency(),
Throughput: skywireConn.Throughput(),
BandwidthSent: skywireConn.BandwidthSent(),
})

return true
})

return summaries
}
10 changes: 10 additions & 0 deletions pkg/app/appserver/proc_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ProcManager interface {
Stop(appName string) error
Wait(appName string) error
Range(next func(appName string, proc *Proc) bool)
ConnectionsSummary(appName string) ([]ConnectionSummary, error)
Addr() net.Addr
}

Expand Down Expand Up @@ -266,6 +267,15 @@ func (m *procManager) Range(next func(name string, proc *Proc) bool) {
}
}

func (m *procManager) ConnectionsSummary(appName string) ([]ConnectionSummary, error) {
p, err := m.get(appName)
if err != nil {
return nil, err
}

return p.ConnectionsSummary(), nil
}

// stopAll stops all the apps run with this manager instance.
func (m *procManager) stopAll() {
for name, proc := range m.procs {
Expand Down
9 changes: 3 additions & 6 deletions pkg/routefinder/rfclient/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions pkg/router/mock_router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading