From 26680be0e8b0dc7b36c2b5ce5eb4eea63e82a10f Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Tue, 27 Jun 2023 22:41:01 +0530 Subject: [PATCH 1/4] use endpoint detection config from peer update --- functions/mqhandlers.go | 4 +--- go.mod | 4 ++-- go.sum | 8 ++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/functions/mqhandlers.go b/functions/mqhandlers.go index 0eff6fa7..16061c8d 100644 --- a/functions/mqhandlers.go +++ b/functions/mqhandlers.go @@ -140,8 +140,6 @@ func HostPeerUpdate(client mqtt.Client, msg mqtt.Message) { server.Version = peerUpdate.ServerVersion config.WriteServerConfig() } - // endpoint detection always comes from the server - config.Netclient().Host.EndpointDetection = peerUpdate.Host.EndpointDetection gwDetected := config.GW4PeerDetected || config.GW6PeerDetected currentGW4 := config.GW4Addr currentGW6 := config.GW6Addr @@ -165,7 +163,7 @@ func HostPeerUpdate(client mqtt.Client, msg mqtt.Message) { gwDelta, &originalGW, ) - if config.Netclient().Host.EndpointDetection { + if peerUpdate.EndpointDetection { slog.Debug("endpoint detection enabled") go handleEndpointDetection(&peerUpdate) } else { diff --git a/go.mod b/go.mod index 5daa028c..8f5b4a67 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/google/nftables v0.1.0 github.com/google/uuid v1.3.0 github.com/gorilla/websocket v1.5.0 - github.com/gravitl/netmaker v0.20.2-0.20230607190105-1e65fa2f9ad5 + github.com/gravitl/netmaker v0.20.3-0.20230627170624-243cc7449057 github.com/gravitl/txeh v0.0.0-20230509181318-3778c58bd69f github.com/guumaster/hostctl v1.1.4 github.com/hashicorp/go-version v1.6.0 @@ -124,7 +124,7 @@ require ( golang.org/x/image v0.6.0 // indirect golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c // indirect golang.org/x/mod v0.8.0 // indirect - golang.org/x/oauth2 v0.8.0 // indirect + golang.org/x/oauth2 v0.9.0 // indirect golang.org/x/sync v0.1.0 // indirect golang.org/x/text v0.10.0 // indirect golang.org/x/tools v0.6.0 // indirect diff --git a/go.sum b/go.sum index 95578879..0bb1b636 100644 --- a/go.sum +++ b/go.sum @@ -192,8 +192,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gravitl/netmaker v0.20.2-0.20230607190105-1e65fa2f9ad5 h1:fdGc8TxzqRSx7tCnuWPOffWDPbrLtdxpTRwnHD4OzbI= -github.com/gravitl/netmaker v0.20.2-0.20230607190105-1e65fa2f9ad5/go.mod h1:7ikBzRznRUag2KrQhw7etTJhOwNj3Op8wMvXCBVOI/M= +github.com/gravitl/netmaker v0.20.3-0.20230627170624-243cc7449057 h1:LgISep7GNdpA8fFM44sHZYVQOen/AZRzAOzDC7c9WR4= +github.com/gravitl/netmaker v0.20.3-0.20230627170624-243cc7449057/go.mod h1:h/8zpORPHUNX5POfb7h2M3p30qK/PLoX1XhSPqc6xJc= github.com/gravitl/txeh v0.0.0-20230509181318-3778c58bd69f h1:XzsYovKdrDvj2z2HEHoeHU67+JIEFMHQKHU6oU+1fVE= github.com/gravitl/txeh v0.0.0-20230509181318-3778c58bd69f/go.mod h1:Nqo/7iOJSVP1JRSUv+FkZ0FgBjK89gjU0D/V8nH4xy8= github.com/guumaster/hostctl v1.1.4 h1:4zb9wEurBlz/hQiXFz9feHHfunf7oj+9serAH8ohGuM= @@ -508,8 +508,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= -golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= +golang.org/x/oauth2 v0.9.0 h1:BPpt2kU7oMRq3kCHAA1tbSEshXRw1LpG2ztgDwrzuAs= +golang.org/x/oauth2 v0.9.0/go.mod h1:qYgFZaFiu6Wg24azG8bdV52QJXJGbZzIIsRCdVKzbLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= From 2a9e037a0aa1bbf4d8d1aff6368e317bcf535a8e Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Wed, 28 Jun 2023 08:36:12 +0530 Subject: [PATCH 2/4] set orders matters to false --- functions/daemon.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/daemon.go b/functions/daemon.go index 5c545b5b..46bb59aa 100644 --- a/functions/daemon.go +++ b/functions/daemon.go @@ -226,7 +226,7 @@ func setupMQTT(server *config.Server) error { setHostSubscription(client, server.Name) checkin() }) - opts.SetOrderMatters(true) + opts.SetOrderMatters(false) opts.SetResumeSubs(true) opts.SetConnectionLostHandler(func(c mqtt.Client, e error) { slog.Warn("detected broker connection lost for", "server", server.Broker) From 63a7cb86784d2ea15601a92e0eabe8975b368bef Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Wed, 28 Jun 2023 10:43:54 +0530 Subject: [PATCH 3/4] reset turn peer connection checker on peerupdate --- functions/mqhandlers.go | 1 + nmproxy/turn/turn_helper.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/functions/mqhandlers.go b/functions/mqhandlers.go index 16061c8d..ae2ca959 100644 --- a/functions/mqhandlers.go +++ b/functions/mqhandlers.go @@ -125,6 +125,7 @@ func HostPeerUpdate(client mqtt.Client, msg mqtt.Message) { slog.Error("error unmarshalling peer data", "error", err) return } + turn.ResetCh <- struct{}{} if peerUpdate.ServerVersion != config.Version { slog.Warn("server/client version mismatch", "server", peerUpdate.ServerVersion, "client", config.Version) if versionLessThan(config.Version, peerUpdate.ServerVersion) && config.Netclient().Host.AutoUpdate { diff --git a/nmproxy/turn/turn_helper.go b/nmproxy/turn/turn_helper.go index 774c7bcf..c1bbea45 100644 --- a/nmproxy/turn/turn_helper.go +++ b/nmproxy/turn/turn_helper.go @@ -23,10 +23,12 @@ import ( var ( // PeerSignalCh - channel to recieve peer signals PeerSignalCh = make(chan nm_models.Signal, 50) - // PeerConnectionCheckInterval - time interval to check peer connection status - PeerConnectionCheckInterval = time.Minute + // peerConnectionCheckInterval - time interval to check peer connection status + peerConnectionCheckInterval = time.Second * 90 // LastHandShakeThreshold - threshold for considering inactive connection LastHandShakeThreshold = time.Minute * 3 + + ResetCh = make(chan struct{}, 2) ) // WatchPeerSignals - processes the peer signals for any turn updates from peers @@ -152,12 +154,16 @@ func handleDisconnect(signal nm_models.Signal) error { // if connection is bad, host will signal peers to use turn func WatchPeerConnections(ctx context.Context, waitg *sync.WaitGroup) { defer waitg.Done() - t := time.NewTicker(time.Minute) + t := time.NewTicker(peerConnectionCheckInterval) defer t.Stop() for { select { case <-ctx.Done(): return + case <-ResetCh: + if t != nil { + t.Reset(peerConnectionCheckInterval) + } case <-t.C: iface, err := wg.GetWgIface(ncutils.GetInterfaceName()) if err != nil { From 27457717c623a170668718a1f00700829f2e7cf7 Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Wed, 28 Jun 2023 10:53:41 +0530 Subject: [PATCH 4/4] disable auto switch of proxy --- functions/mqpublish.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/functions/mqpublish.go b/functions/mqpublish.go index 921362c7..011c3be9 100644 --- a/functions/mqpublish.go +++ b/functions/mqpublish.go @@ -291,13 +291,6 @@ func UpdateHostSettings() error { publishMsg = true } } - if !config.Netclient().ProxyEnabledSet && proxyCfg.GetCfg().ShouldUseProxy() && - !config.Netclient().ProxyEnabled && !proxyCfg.NatAutoSwitchDone() { - logger.Log(0, "Host is behind NAT, enabling proxy...") - proxyCfg.SetNatAutoSwitch() - config.Netclient().ProxyEnabled = true - publishMsg = true - } ip, err := getInterfaces() if err != nil { logger.Log(0, "failed to retrieve local interfaces during check-in", err.Error())