From 9cadc9cecc78b24c5faaca8b1a12d098cdfe150a Mon Sep 17 00:00:00 2001 From: ersonp Date: Mon, 20 Sep 2021 18:25:27 +0530 Subject: [PATCH 01/13] Remove stcpr heartbeat --- pkg/transport/network/addrresolver/client.go | 38 ++++---------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index d74cd5d3fb..1474fefd13 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -27,14 +27,12 @@ import ( const ( // sudphPriority is used to set an order how connection filters apply. - sudphPriority = 1 - stcprBindPath = "/bind/stcpr" - stcprHeartbeatPath = "/heartbeat/stcpr" - stcprKeepHeartbeatInterval = 300 * time.Second - addrChSize = 1024 - udpKeepHeartbeatInterval = 10 * time.Second - udpKeepHeartbeatMessage = "heartbeat" - defaultUDPPort = "30178" + sudphPriority = 1 + stcprBindPath = "/bind/stcpr" + addrChSize = 1024 + udpKeepHeartbeatInterval = 10 * time.Second + udpKeepHeartbeatMessage = "heartbeat" + defaultUDPPort = "30178" ) var ( @@ -218,12 +216,6 @@ 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 } @@ -421,24 +413,6 @@ 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) keepSudphHeartbeatLoop(w io.Writer) error { for { From 8de6de9dfc7607015791552b6e7c170bdf473040 Mon Sep 17 00:00:00 2001 From: ersonp Date: Tue, 21 Sep 2021 15:45:22 +0530 Subject: [PATCH 02/13] Add unbind on close --- pkg/transport/manager.go | 1 + pkg/transport/network/addrresolver/client.go | 42 +++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index 2979948f38..fa5f6dd28a 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -555,6 +555,7 @@ func (tm *Manager) Close() { tm.Logger.WithError(err).Warnf("Failed to close %s client", client.Type()) } } + tm.arClient.Close() tm.wg.Wait() close(tm.readCh) } diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index 1474fefd13..51e299cc52 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -51,11 +51,11 @@ type Error struct { // APIClient implements address resolver API client. type APIClient interface { - io.Closer BindSTCPR(ctx context.Context, port string) error BindSUDPH(filter *pfilter.PacketFilter, handshake Handshake) (<-chan RemoteVisor, error) Resolve(ctx context.Context, netType string, pk cipher.PubKey) (VisorData, error) Health(ctx context.Context) (int, error) + Close() error } // VisorData stores visor data. @@ -219,6 +219,42 @@ func (c *httpClient) BindSTCPR(ctx context.Context, port string) error { return nil } +// UnBindSTCPR uinbinds client PK to IP:port on address resolver. +func (c *httpClient) unBindSTCPR(ctx context.Context) error { + if !c.isReady() { + c.log.Debugf("UnBindSTCPR: Address resolver is not ready yet, waiting...") + <-c.ready + c.log.Debugf("UnBindSTCPR: Address resolver became ready, unbinding") + } + + addresses, err := netutil.LocalAddresses() + if err != nil { + return err + } + + localAddresses := LocalAddresses{ + Addresses: addresses, + } + + c.log.Infof("UnBindSTCPR: Address resolver unbinding: %v", addresses) + resp, err := c.Post(ctx, stcprBindPath, localAddresses) + if err != nil { + return err + } + + defer func() { + if err := resp.Body.Close(); err != nil { + c.log.WithError(err).Warn("Failed to close response body") + } + }() + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("status: %d, error: %w", resp.StatusCode, extractError(resp.Body)) + } + + return nil +} + // Handshake type is used to decouple client from handshake and network packages type Handshake func(net.Conn) (net.Conn, error) @@ -410,6 +446,10 @@ func (c *httpClient) Close() error { close(c.closed) } + if err := c.unBindSTCPR(context.Background()); err != nil { + c.log.WithError(err).Errorf("Failed to unbind STCPR") + } + return nil } From 82d7748cc148224b5f4c187afebc3b7527fcbdfa Mon Sep 17 00:00:00 2001 From: ersonp Date: Tue, 21 Sep 2021 16:44:00 +0530 Subject: [PATCH 03/13] Fix unBindSTCPR --- pkg/transport/network/addrresolver/client.go | 34 +++++++++++++------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index 51e299cc52..7e7a863e31 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -29,6 +29,7 @@ const ( // sudphPriority is used to set an order how connection filters apply. sudphPriority = 1 stcprBindPath = "/bind/stcpr" + stcprUnbindPath = "/unbind/stcpr" addrChSize = 1024 udpKeepHeartbeatInterval = 10 * time.Second udpKeepHeartbeatMessage = "heartbeat" @@ -172,6 +173,25 @@ func (c *httpClient) Post(ctx context.Context, path string, payload interface{}) return c.httpClient.Do(req.WithContext(ctx)) } +// Delete performs a DELETE request. +func (c *httpClient) Delete(ctx context.Context, path string) (*http.Response, error) { + <-c.ready + var payload struct{} + body := bytes.NewBuffer(nil) + if err := json.NewEncoder(body).Encode(payload); err != nil { + return nil, err + } + + addr := c.httpClient.Addr() + path + + req, err := http.NewRequest(http.MethodDelete, addr, body) + if err != nil { + return nil, err + } + + return c.httpClient.Do(req.WithContext(ctx)) +} + // BindRequest stores bind request values. type BindRequest struct { Port string `json:"port"` @@ -227,17 +247,8 @@ func (c *httpClient) unBindSTCPR(ctx context.Context) error { c.log.Debugf("UnBindSTCPR: Address resolver became ready, unbinding") } - addresses, err := netutil.LocalAddresses() - if err != nil { - return err - } - - localAddresses := LocalAddresses{ - Addresses: addresses, - } - - c.log.Infof("UnBindSTCPR: Address resolver unbinding: %v", addresses) - resp, err := c.Post(ctx, stcprBindPath, localAddresses) + c.log.Debugf("UnBindSTCPR: Address resolver unbinding pk: %v", c.pk.String()) + resp, err := c.Delete(ctx, stcprUnbindPath) if err != nil { return err } @@ -252,6 +263,7 @@ func (c *httpClient) unBindSTCPR(ctx context.Context) error { return fmt.Errorf("status: %d, error: %w", resp.StatusCode, extractError(resp.Body)) } + c.log.Debugf("UnBindSTCPR: Address resolver successfully unbound pk: %v", c.pk.String()) return nil } From 5b08448ab446c83f4e8b4ca6cc07f72bfde1ac72 Mon Sep 17 00:00:00 2001 From: ersonp Date: Tue, 21 Sep 2021 19:01:54 +0530 Subject: [PATCH 04/13] Fix test --- pkg/transport/manager.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index fa5f6dd28a..7d45c3ab80 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -555,7 +555,10 @@ func (tm *Manager) Close() { tm.Logger.WithError(err).Warnf("Failed to close %s client", client.Type()) } } - tm.arClient.Close() + err := tm.arClient.Close() + if err != nil { + tm.Logger.WithError(err).Warnf("Failed to close arClient") + } tm.wg.Wait() close(tm.readCh) } From eb9994c16a9e228dd2738e66cec79199fd20fe74 Mon Sep 17 00:00:00 2001 From: ersonp Date: Tue, 21 Sep 2021 19:17:52 +0530 Subject: [PATCH 05/13] Update test setup node pk --- pkg/skyenv/values.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/skyenv/values.go b/pkg/skyenv/values.go index d416f06a12..e562e68303 100644 --- a/pkg/skyenv/values.go +++ b/pkg/skyenv/values.go @@ -41,7 +41,7 @@ const ( TestRouteFinderAddr = "http://routefinder.skywire.cc" TestUptimeTrackerAddr = "http://uptime.tracker.skywire.cc" TestAddressResolverAddr = "http://address.resolver.skywire.cc" - TestSetupPK = "026c5a07de617c5c488195b76e8671bf9e7ee654d0633933e202af9e111ffa358d" + TestSetupPK = "026c2a3e92d6253c5abd71a42628db6fca9dd9aa037ab6f4e3a31108558dfd87cf" ) // Dmsg port constants. From bd5cea5878327b9812cc7b8bddc6044feeee6ad1 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 00:02:10 +0530 Subject: [PATCH 06/13] Add unbind sudph --- pkg/transport/network/addrresolver/client.go | 39 +++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index 7e7a863e31..551814c698 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -12,6 +12,7 @@ import ( "net" "net/http" "net/url" + "sync" "time" "github.com/AudriusButkevicius/pfilter" @@ -33,6 +34,7 @@ const ( addrChSize = 1024 udpKeepHeartbeatInterval = 10 * time.Second udpKeepHeartbeatMessage = "heartbeat" + udpUnbindMessage = "unbind" defaultUDPPort = "30178" ) @@ -77,6 +79,7 @@ type httpClient struct { sudphConn net.PacketConn ready chan struct{} closed chan struct{} + unbindSUDPHWg sync.WaitGroup } // NewHTTP creates a new client setting a public key to the client to be used for auth. @@ -239,15 +242,15 @@ func (c *httpClient) BindSTCPR(ctx context.Context, port string) error { return nil } -// UnBindSTCPR uinbinds client PK to IP:port on address resolver. -func (c *httpClient) unBindSTCPR(ctx context.Context) error { +// unbindSTCPR uinbinds STCPR entry PK to IP:port on address resolver. +func (c *httpClient) unbindSTCPR(ctx context.Context) error { if !c.isReady() { - c.log.Debugf("UnBindSTCPR: Address resolver is not ready yet, waiting...") + c.log.Debugf("UnbindSTCPR: Address resolver is not ready yet, waiting...") <-c.ready - c.log.Debugf("UnBindSTCPR: Address resolver became ready, unbinding") + c.log.Debugf("UnbindSTCPR: Address resolver became ready, unbinding") } - c.log.Debugf("UnBindSTCPR: Address resolver unbinding pk: %v", c.pk.String()) + c.log.Debugf("UnbindSTCPR: Address resolver unbinding pk: %v", c.pk.String()) resp, err := c.Delete(ctx, stcprUnbindPath) if err != nil { return err @@ -263,7 +266,7 @@ func (c *httpClient) unBindSTCPR(ctx context.Context) error { return fmt.Errorf("status: %d, error: %w", resp.StatusCode, extractError(resp.Body)) } - c.log.Debugf("UnBindSTCPR: Address resolver successfully unbound pk: %v", c.pk.String()) + c.log.Debugf("UnbindSTCPR: Address resolver successfully unbound pk: %v", c.pk.String()) return nil } @@ -326,6 +329,12 @@ func (c *httpClient) BindSUDPH(filter *pfilter.PacketFilter, hs Handshake) (<-ch } }() + go func() { + if err := c.unbindSUDPH(arConn); err != nil { + c.log.WithError(err).Errorf("Failed to send UDP unbind packet to address-resolver") + } + }() + return addrCh, nil } @@ -452,13 +461,15 @@ func (c *httpClient) Close() error { }() if c.sudphConn != nil { + c.unbindSUDPHWg.Add(1) + close(c.closed) + c.unbindSUDPHWg.Wait() if err := c.sudphConn.Close(); err != nil { c.log.WithError(err).Errorf("Failed to close SUDPH") } - close(c.closed) } - if err := c.unBindSTCPR(context.Background()); err != nil { + if err := c.unbindSTCPR(context.Background()); err != nil { c.log.WithError(err).Errorf("Failed to unbind STCPR") } @@ -475,12 +486,22 @@ func (c *httpClient) keepSudphHeartbeatLoop(w io.Writer) error { if _, err := w.Write([]byte(udpKeepHeartbeatMessage)); err != nil { return err } - time.Sleep(udpKeepHeartbeatInterval) } } } +// unbindSUDPH unbinds SUDPH entry in address resolver. +func (c *httpClient) unbindSUDPH(w io.Writer) error { + // send unbind packet on shutdown + <-c.closed + defer c.unbindSUDPHWg.Done() + if _, err := w.Write([]byte(udpUnbindMessage)); err != nil { + return err + } + return nil +} + // extractError returns the decoded error message from Body. func extractError(r io.Reader) error { var apiError Error From 60db97bf7bee066ca5007cda8221945820f38f91 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 00:05:52 +0530 Subject: [PATCH 07/13] Export UDPUnbindMessage --- pkg/transport/network/addrresolver/client.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index 551814c698..d89be23547 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -34,8 +34,9 @@ const ( addrChSize = 1024 udpKeepHeartbeatInterval = 10 * time.Second udpKeepHeartbeatMessage = "heartbeat" - udpUnbindMessage = "unbind" defaultUDPPort = "30178" + // UDPUnbindMessage is used in unbind packet on visor shutdown. + UDPUnbindMessage = "unbind" ) var ( @@ -496,7 +497,7 @@ func (c *httpClient) unbindSUDPH(w io.Writer) error { // send unbind packet on shutdown <-c.closed defer c.unbindSUDPHWg.Done() - if _, err := w.Write([]byte(udpUnbindMessage)); err != nil { + if _, err := w.Write([]byte(UDPUnbindMessage)); err != nil { return err } return nil From c9a2f564c5f1881aaad7e8ea2c35b8063db21bf6 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 00:12:11 +0530 Subject: [PATCH 08/13] Update unbindSudphWg --- pkg/transport/network/addrresolver/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index d89be23547..4bb62e6e95 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -80,7 +80,7 @@ type httpClient struct { sudphConn net.PacketConn ready chan struct{} closed chan struct{} - unbindSUDPHWg sync.WaitGroup + unbindSudphWg sync.WaitGroup } // NewHTTP creates a new client setting a public key to the client to be used for auth. @@ -462,9 +462,9 @@ func (c *httpClient) Close() error { }() if c.sudphConn != nil { - c.unbindSUDPHWg.Add(1) + c.unbindSudphWg.Add(1) close(c.closed) - c.unbindSUDPHWg.Wait() + c.unbindSudphWg.Wait() if err := c.sudphConn.Close(); err != nil { c.log.WithError(err).Errorf("Failed to close SUDPH") } @@ -496,7 +496,7 @@ func (c *httpClient) keepSudphHeartbeatLoop(w io.Writer) error { func (c *httpClient) unbindSUDPH(w io.Writer) error { // send unbind packet on shutdown <-c.closed - defer c.unbindSUDPHWg.Done() + defer c.unbindSudphWg.Done() if _, err := w.Write([]byte(UDPUnbindMessage)); err != nil { return err } From 8a1e51b7bf878d42ba3dae50a3adec88fb034f27 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 00:33:57 +0530 Subject: [PATCH 09/13] Fix read sudph shutdown log --- pkg/transport/network/addrresolver/client.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index 4bb62e6e95..b84ae7cebe 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -430,6 +430,10 @@ func (c *httpClient) readSUDPHMessages(reader io.Reader) <-chan RemoteVisor { default: n, err := reader.Read(buf) if err != nil { + if c.isClosed() { + c.log.Infof("SUDPH conn closed on shutdown message: %v", err) + return + } c.log.Errorf("Failed to read SUDPH message: %v", err) return } @@ -503,6 +507,15 @@ func (c *httpClient) unbindSUDPH(w io.Writer) error { return nil } +func (c *httpClient) isClosed() bool { + select { + case <-c.closed: + return true + default: + return false + } +} + // extractError returns the decoded error message from Body. func extractError(r io.Reader) error { var apiError Error From c2f774b86a8799570f16dba84441f35ff4737bf6 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 00:40:43 +0530 Subject: [PATCH 10/13] Make format --- cmd/apps/skychat/chat.go | 5 ++--- cmd/skywire-visor/commands/systray.go | 1 + go.sum | 3 --- internal/gui/gui_darwin.go | 2 +- pkg/visor/hypervisorconfig/config.go | 3 +-- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/apps/skychat/chat.go b/cmd/apps/skychat/chat.go index eb2836207c..1ff04fb7ef 100644 --- a/cmd/apps/skychat/chat.go +++ b/cmd/apps/skychat/chat.go @@ -4,18 +4,17 @@ skychat app for skywire visor package main import ( + "embed" "encoding/json" "flag" "fmt" + "io/fs" "net" "net/http" "os" "sync" "time" - "embed" - "io/fs" - "github.com/skycoin/dmsg/buildinfo" "github.com/skycoin/dmsg/cipher" diff --git a/cmd/skywire-visor/commands/systray.go b/cmd/skywire-visor/commands/systray.go index 51768045b2..8dfe95c8c0 100644 --- a/cmd/skywire-visor/commands/systray.go +++ b/cmd/skywire-visor/commands/systray.go @@ -4,6 +4,7 @@ package commands import ( "context" + "github.com/getlantern/systray" "github.com/skycoin/skycoin/src/util/logging" diff --git a/go.sum b/go.sum index ff4ae52e02..e7e48d3e17 100644 --- a/go.sum +++ b/go.sum @@ -189,7 +189,6 @@ github.com/klauspost/reedsolomon v1.9.9/go.mod h1:O7yFFHiQwDR6b2t63KPUpccPtNdp5A github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -309,8 +308,6 @@ github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5k github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skycoin/dmsg v0.0.0-20210827120633-3d20b41d46a2 h1:Dlf/sDocfSgjP+ipVxzOtDVkkLN1u6ZqUyXzp22AkU4= -github.com/skycoin/dmsg v0.0.0-20210827120633-3d20b41d46a2/go.mod h1:XguFKwECpSMq+/AKv8TCTsRlCEHSEIbqoaxOyceK2Ys= github.com/skycoin/dmsg v0.0.0-20210915195912-2f9b055f39fe h1:3mNjtnypa8DC4kNiuLOJ1mqMdXPIAI6Se4k8fNNU2P0= github.com/skycoin/dmsg v0.0.0-20210915195912-2f9b055f39fe/go.mod h1:qs+tELY7/gHRHqCK0iPp62BuYlu10OcV5zN0lpa1Scc= github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 h1:1Nc5EBY6pjfw1kwW0duwyG+7WliWz5u9kgk1h5MnLuA= diff --git a/internal/gui/gui_darwin.go b/internal/gui/gui_darwin.go index 3fe6015a2e..0018cf0cc3 100644 --- a/internal/gui/gui_darwin.go +++ b/internal/gui/gui_darwin.go @@ -13,7 +13,7 @@ const ( pngIconPath = "/Applications/Skywire.app/Contents/Resources/icon.png" iconPath = "/Applications/Skywire.app/Contents/Resources/tray_icon.tiff" deinstallerPath = "/Applications/Skywire.app/Contents/deinstaller" - appPath = "/Applications/Skywire.app" + appPath = "/Applications/Skywire.app" ) func preReadIcon() error { diff --git a/pkg/visor/hypervisorconfig/config.go b/pkg/visor/hypervisorconfig/config.go index 1b165cc331..637e815a89 100644 --- a/pkg/visor/hypervisorconfig/config.go +++ b/pkg/visor/hypervisorconfig/config.go @@ -3,14 +3,13 @@ package hypervisorconfig import ( "encoding/hex" "encoding/json" + "io/fs" "log" "net/http" "os" "path/filepath" "time" - "io/fs" - "github.com/skycoin/dmsg/cipher" "github.com/skycoin/skywire/pkg/skyenv" From 921b22bd57cb4c85c2c9615e8eb8944922a569e2 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 13:50:41 +0530 Subject: [PATCH 11/13] Add log on sudph bind success --- pkg/transport/network/sudph.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/transport/network/sudph.go b/pkg/transport/network/sudph.go index ccd2eebfae..83cd4f0f01 100644 --- a/pkg/transport/network/sudph.go +++ b/pkg/transport/network/sudph.go @@ -69,6 +69,14 @@ func (c *sudphClient) listen() (net.Listener, error) { if err != nil { return nil, err } + + _, localPort, err := net.SplitHostPort(packetListener.LocalAddr().String()) + if err != nil { + return nil, err + } + + c.log.Infof("Successfully bound sudph to port %s", localPort) + go c.acceptAddresses(sudphVisorsConn, addrCh) return kcp.ServeConn(nil, 0, 0, sudphVisorsConn) } From 7539e1131df81c813a7ba4bb6a5597f01bbb1947 Mon Sep 17 00:00:00 2001 From: ersonp Date: Wed, 22 Sep 2021 20:13:49 +0530 Subject: [PATCH 12/13] Rename unbind to delbind --- pkg/transport/network/addrresolver/client.go | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index b84ae7cebe..5d2436f725 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -35,8 +35,8 @@ const ( udpKeepHeartbeatInterval = 10 * time.Second udpKeepHeartbeatMessage = "heartbeat" defaultUDPPort = "30178" - // UDPUnbindMessage is used in unbind packet on visor shutdown. - UDPUnbindMessage = "unbind" + // UDPDelBindMessage is used as a deletebind packet on visor shutdown. + UDPDelBindMessage = "delBind" ) var ( @@ -80,7 +80,7 @@ type httpClient struct { sudphConn net.PacketConn ready chan struct{} closed chan struct{} - unbindSudphWg sync.WaitGroup + delBindSudphWg sync.WaitGroup } // NewHTTP creates a new client setting a public key to the client to be used for auth. @@ -243,15 +243,15 @@ func (c *httpClient) BindSTCPR(ctx context.Context, port string) error { return nil } -// unbindSTCPR uinbinds STCPR entry PK to IP:port on address resolver. -func (c *httpClient) unbindSTCPR(ctx context.Context) error { +// delBindSTCPR uinbinds STCPR entry PK to IP:port on address resolver. +func (c *httpClient) delBindSTCPR(ctx context.Context) error { if !c.isReady() { - c.log.Debugf("UnbindSTCPR: Address resolver is not ready yet, waiting...") + c.log.Debugf("delBindSTCPR: Address resolver is not ready yet, waiting...") <-c.ready - c.log.Debugf("UnbindSTCPR: Address resolver became ready, unbinding") + c.log.Debugf("delBindSTCPR: Address resolver became ready, unbinding") } - c.log.Debugf("UnbindSTCPR: Address resolver unbinding pk: %v", c.pk.String()) + c.log.Debugf("delBindSTCPR: deleting the binding pk: %v from Address resolver", c.pk.String()) resp, err := c.Delete(ctx, stcprUnbindPath) if err != nil { return err @@ -267,7 +267,7 @@ func (c *httpClient) unbindSTCPR(ctx context.Context) error { return fmt.Errorf("status: %d, error: %w", resp.StatusCode, extractError(resp.Body)) } - c.log.Debugf("UnbindSTCPR: Address resolver successfully unbound pk: %v", c.pk.String()) + c.log.Debugf("delBindSTCPR: Deleted bind pk: %v from Address resolver successfully", c.pk.String()) return nil } @@ -331,7 +331,7 @@ func (c *httpClient) BindSUDPH(filter *pfilter.PacketFilter, hs Handshake) (<-ch }() go func() { - if err := c.unbindSUDPH(arConn); err != nil { + if err := c.delBindSUDPH(arConn); err != nil { c.log.WithError(err).Errorf("Failed to send UDP unbind packet to address-resolver") } }() @@ -466,15 +466,15 @@ func (c *httpClient) Close() error { }() if c.sudphConn != nil { - c.unbindSudphWg.Add(1) + c.delBindSudphWg.Add(1) close(c.closed) - c.unbindSudphWg.Wait() + c.delBindSudphWg.Wait() if err := c.sudphConn.Close(); err != nil { c.log.WithError(err).Errorf("Failed to close SUDPH") } } - if err := c.unbindSTCPR(context.Background()); err != nil { + if err := c.delBindSTCPR(context.Background()); err != nil { c.log.WithError(err).Errorf("Failed to unbind STCPR") } @@ -496,14 +496,16 @@ func (c *httpClient) keepSudphHeartbeatLoop(w io.Writer) error { } } -// unbindSUDPH unbinds SUDPH entry in address resolver. -func (c *httpClient) unbindSUDPH(w io.Writer) error { +// delBindSUDPH unbinds SUDPH entry in address resolver. +func (c *httpClient) delBindSUDPH(w io.Writer) error { // send unbind packet on shutdown <-c.closed - defer c.unbindSudphWg.Done() - if _, err := w.Write([]byte(UDPUnbindMessage)); err != nil { + defer c.delBindSudphWg.Done() + if _, err := w.Write([]byte(UDPDelBindMessage)); err != nil { return err } + c.log.Debugf("delBindSUDPH: Deleted bind pk: %v from Address resolver successfully", c.pk.String()) + return nil } From eb0168533e7364db895f6cbe3fc5a1fedf2dfe46 Mon Sep 17 00:00:00 2001 From: ersonp Date: Thu, 23 Sep 2021 00:44:53 +0530 Subject: [PATCH 13/13] Fic stcpr del bind --- pkg/transport/network/addrresolver/client.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/transport/network/addrresolver/client.go b/pkg/transport/network/addrresolver/client.go index 5d2436f725..cbc523c89d 100644 --- a/pkg/transport/network/addrresolver/client.go +++ b/pkg/transport/network/addrresolver/client.go @@ -30,7 +30,6 @@ const ( // sudphPriority is used to set an order how connection filters apply. sudphPriority = 1 stcprBindPath = "/bind/stcpr" - stcprUnbindPath = "/unbind/stcpr" addrChSize = 1024 udpKeepHeartbeatInterval = 10 * time.Second udpKeepHeartbeatMessage = "heartbeat" @@ -252,7 +251,7 @@ func (c *httpClient) delBindSTCPR(ctx context.Context) error { } c.log.Debugf("delBindSTCPR: deleting the binding pk: %v from Address resolver", c.pk.String()) - resp, err := c.Delete(ctx, stcprUnbindPath) + resp, err := c.Delete(ctx, stcprBindPath) if err != nil { return err } @@ -475,7 +474,7 @@ func (c *httpClient) Close() error { } if err := c.delBindSTCPR(context.Background()); err != nil { - c.log.WithError(err).Errorf("Failed to unbind STCPR") + c.log.WithError(err).Errorf("Failed to delete STCPR binding") } return nil