Skip to content

Commit

Permalink
Merge branch 'develop' into nat-info
Browse files Browse the repository at this point in the history
  • Loading branch information
jdknives authored Sep 7, 2021
2 parents ba9a4ae + 26404fe commit 24d92c0
Show file tree
Hide file tree
Showing 26 changed files with 577 additions and 226 deletions.
1 change: 1 addition & 0 deletions docker/images/visor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ RUN apk add --no-cache make git && \
cp ./apps/vpn-server /apps/ && \
cp ./apps/vpn-client /apps/ && \
cp ./apps/skysocks /apps/ && \
cp ./apps/skysocks-client /apps/ && \
cp ./apps/skychat /apps/

## Resulting image
Expand Down
48 changes: 37 additions & 11 deletions pkg/transport/network/addrresolver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ import (

const (
// sudphPriority is used to set an order how connection filters apply.
sudphPriority = 1
stcprBindPath = "/bind/stcpr"
addrChSize = 1024
udpKeepAliveInterval = 10 * time.Second
udpKeepAliveMessage = "keepalive"
defaultUDPPort = "30178"
sudphPriority = 1
stcprBindPath = "/bind/stcpr"
stcprHeartbeatPath = "/heartbeat/stcpr"
stcprKeepHeartbeatInterval = 300 * time.Second
addrChSize = 1024
udpKeepHeartbeatInterval = 10 * time.Second
udpKeepHeartbeatMessage = "heartbeat"
defaultUDPPort = "30178"
)

var (
Expand Down Expand Up @@ -216,6 +218,12 @@ func (c *httpClient) BindSTCPR(ctx context.Context, port string) error {
return fmt.Errorf("status: %d, error: %w", resp.StatusCode, extractError(resp.Body))
}

go func() {
if err := c.keepStcprHeartbeatLoop(ctx); err != nil {
c.log.WithError(err).Errorf("Failed to send TCP heartbeat signal to address-resolver")
}
}()

return nil
}

Expand Down Expand Up @@ -273,8 +281,8 @@ func (c *httpClient) BindSUDPH(filter *pfilter.PacketFilter, hs Handshake) (<-ch
addrCh := c.readSUDPHMessages(arConn)

go func() {
if err := c.keepAliveLoop(arConn); err != nil {
c.log.WithError(err).Errorf("Failed to send keep alive UDP packet to address-resolver")
if err := c.keepSudphHeartbeatLoop(arConn); err != nil {
c.log.WithError(err).Errorf("Failed to send UDP heartbeat packet to address-resolver")
}
}()

Expand Down Expand Up @@ -413,18 +421,36 @@ func (c *httpClient) Close() error {
return nil
}

// Keep stcpr heartbeat in address-resolver
func (c *httpClient) keepStcprHeartbeatLoop(ctx context.Context) error {
for {
_, err := c.Get(ctx, stcprHeartbeatPath)
if err != nil {
return err
}

c.log.Debugf("Sent TCP heartbeat signal to address-resolver")
select {
case <-c.closed:
return nil
default:
time.Sleep(stcprKeepHeartbeatInterval)
}
}
}

// Keep NAT mapping alive.
func (c *httpClient) keepAliveLoop(w io.Writer) error {
func (c *httpClient) keepSudphHeartbeatLoop(w io.Writer) error {
for {
select {
case <-c.closed:
return nil
default:
if _, err := w.Write([]byte(udpKeepAliveMessage)); err != nil {
if _, err := w.Write([]byte(udpKeepHeartbeatMessage)); err != nil {
return err
}

time.Sleep(udpKeepAliveInterval)
time.Sleep(udpKeepHeartbeatInterval)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/transport/network/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,10 @@ type dialFunc func(ctx context.Context, addr string) (net.Conn, error)
// and dials that visor address(es)
// dial process is specific to transport type and is provided by the client
func (c *resolvedClient) dialVisor(ctx context.Context, rPK cipher.PubKey, dial dialFunc) (net.Conn, error) {
c.log.Infof("Dialing PK %v", rPK)
visorData, err := c.ar.Resolve(ctx, string(c.netType), rPK)
if err != nil {
return nil, fmt.Errorf("resolve PK: %w", err)
}
c.log.Infof("Resolved PK %v to visor data %v", rPK, visorData)

if visorData.IsLocal {
for _, host := range visorData.Addresses {
Expand Down
6 changes: 6 additions & 0 deletions pkg/visor/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type API interface {

SetMinHops(uint16) error

GetPersistentTransports() ([]transport.PersistentTransports, error)
SetPersistentTransports([]transport.PersistentTransports) error
}

Expand Down Expand Up @@ -787,3 +788,8 @@ func (v *Visor) SetMinHops(in uint16) error {
func (v *Visor) SetPersistentTransports(pts []transport.PersistentTransports) error {
return v.conf.UpdatePersistentTransports(pts)
}

// GetPersistentTransports sets min_hops routing config of visor
func (v *Visor) GetPersistentTransports() ([]transport.PersistentTransports, error) {
return v.conf.GetPersistentTransports()
}
12 changes: 12 additions & 0 deletions pkg/visor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func (hv *Hypervisor) makeMux() chi.Router {
r.Get("/visors/{pk}/update/available/{channel}", hv.visorUpdateAvailable())
r.Get("/visors/{pk}/runtime-logs", hv.getRuntimeLogs())
r.Post("/visors/{pk}/min-hops", hv.postMinHops())
r.Get("/visors/{pk}/persistent-transports", hv.getPersistentTransports())
r.Put("/visors/{pk}/persistent-transports", hv.putPersistentTransports())
})
})
Expand Down Expand Up @@ -1342,6 +1343,17 @@ func (hv *Hypervisor) putPersistentTransports() http.HandlerFunc {
})
}

func (hv *Hypervisor) getPersistentTransports() http.HandlerFunc {
return hv.withCtx(hv.visorCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) {
pts, err := ctx.API.GetPersistentTransports()
if err != nil {
httputil.WriteJSON(w, r, http.StatusInternalServerError, err)
return
}
httputil.WriteJSON(w, r, http.StatusOK, pts)
})
}

/*
<<< Helper functions >>>
*/
Expand Down
12 changes: 12 additions & 0 deletions pkg/visor/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ func (rc *rpcClient) SetPersistentTransports(pts []transport.PersistentTransport
return err
}

// GetPersistentTransports gets the persistent_transports from visor routing config
func (rc *rpcClient) GetPersistentTransports() ([]transport.PersistentTransports, error) {
var tps []transport.PersistentTransports
err := rc.Call("GetPersistentTransports", &struct{}{}, &tps)
return tps, err
}

// StatusMessage defines a status of visor update.
type StatusMessage struct {
Text string
Expand Down Expand Up @@ -949,3 +956,8 @@ func (mc *mockRPCClient) SetMinHops(_ uint16) error {
func (mc *mockRPCClient) SetPersistentTransports(_ []transport.PersistentTransports) error {
return nil
}

// GetPersistentTransports implements API
func (mc *mockRPCClient) GetPersistentTransports() ([]transport.PersistentTransports, error) {
return []transport.PersistentTransports{}, nil
}
11 changes: 10 additions & 1 deletion static/skywire-manager-src/src/app/app.datatypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class Node {
version: string;
apps: Application[];
transports: Transport[];
persistentTransports: PersistentTransport[];
routesCount: number;
minHops: number;
routes?: Route[];
Expand All @@ -28,13 +29,21 @@ export interface Application {
}

export interface Transport {
isUp: boolean;
id: string;
localPk: string;
remotePk: string;
type: string;
recv: number|null;
sent: number|null;

// Calculated internally
isPersistent?: boolean;
notFound?: boolean;
}

export interface PersistentTransport {
pk: string;
type: string;
}

export interface Route {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<!-- Column names. -->
<tr>
<th class="sortable-column small-column" (click)="dataSorter.changeSortingOrder(hypervisorSortData)" [matTooltip]="'nodes.hypervisor' | translate">
<mat-icon class="hypervisor-icon gray-text">star_outline</mat-icon>
<mat-icon class="hypervisor-icon grey-text">star_outline</mat-icon>
<mat-icon *ngIf="dataSorter.currentSortingColumn === hypervisorSortData" [inline]="true">{{ dataSorter.sortingArrow }}</mat-icon>
</th>
<th class="sortable-column small-column" (click)="dataSorter.changeSortingOrder(stateSortData)" [matTooltip]="'nodes.state-tooltip' | translate">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
color: $yellow;
}

.gray-text {
color: $light-gray !important;
}

.small-column {
width: 1px;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<app-transport-list
*ngIf="transports"
[transports]="transports"
[showShortList]="false"
[nodePK]="nodePK">
*ngIf="node"
[node]="node"
[showShortList]="false">
</app-transport-list>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';

import { Node, Transport } from '../../../../../app.datatypes';
import { Node } from '../../../../../app.datatypes';
import { NodeComponent } from '../../node.component';

/**
Expand All @@ -13,17 +13,13 @@ import { NodeComponent } from '../../node.component';
styleUrls: ['./all-transports.component.scss']
})
export class AllTransportsComponent implements OnInit, OnDestroy {
transports: Transport[];
nodePK: string;
node: Node;

private dataSubscription: Subscription;

ngOnInit() {
// Get the node data from the parent page.
this.dataSubscription = NodeComponent.currentNode.subscribe((node: Node) => {
this.nodePK = node.localPk;
this.transports = node.transports;
});
this.dataSubscription = NodeComponent.currentNode.subscribe((node: Node) => this.node = node);
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<app-transport-list
[transports]="transports"
[showShortList]="true"
[nodePK]="nodePK">
[node]="node"
[showShortList]="true">
</app-transport-list>

<app-route-list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';

import { Node, Transport, Route } from '../../../../app.datatypes';
import { Node, Route } from '../../../../app.datatypes';
import { NodeComponent } from '../node.component';

/**
Expand All @@ -13,7 +13,7 @@ import { NodeComponent } from '../node.component';
styleUrls: ['./routing.component.scss']
})
export class RoutingComponent implements OnInit, OnDestroy {
transports: Transport[];
node: Node;
routes: Route[];
nodePK: string;

Expand All @@ -23,7 +23,7 @@ export class RoutingComponent implements OnInit, OnDestroy {
// Get the node data from the parent page.
this.dataSubscription = NodeComponent.currentNode.subscribe((node: Node) => {
this.nodePK = node.localPk;
this.transports = node.transports;
this.node = node;
this.routes = node.routes;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
{{ 'transports.dialog.errors.transport-type-error' | translate }}
</mat-error>
</mat-form-field>

<mat-checkbox
color="primary"
[checked]="makePersistent"
(change)="setMakePersistent($event)"
>
{{ 'transports.dialog.make-persistent' | translate }}
<mat-icon [inline]="true" class="help-icon" [matTooltip]="'transports.dialog.persistent-tooltip' | translate">help</mat-icon>
</mat-checkbox>
</form>

<app-button
Expand Down
Loading

0 comments on commit 24d92c0

Please sign in to comment.