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

Scaling fixes #479

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion functions/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions functions/mqhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -140,8 +141,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
Expand All @@ -165,7 +164,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 {
Expand Down
7 changes: 0 additions & 7 deletions functions/mqpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
12 changes: 9 additions & 3 deletions nmproxy/turn/turn_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down