adding force peer push every 5 min

This commit is contained in:
afeiszli
2022-02-08 21:34:38 -05:00
parent d5bae019b3
commit d4b15f0a2d
2 changed files with 43 additions and 22 deletions

View File

@@ -242,6 +242,23 @@ func Keepalive(ctx context.Context) {
case <-ctx.Done(): case <-ctx.Done():
return return
case <-time.After(time.Second * KEEPALIVE_TIMEOUT): case <-time.After(time.Second * KEEPALIVE_TIMEOUT):
sendPeers()
return
}
}
}
var counter = make(chan int, 0)
// sendPeers - retrieve networks, send peer ports to all peers
func sendPeers() {
var force bool
var tmpcount = <-counter + 1
counter <- tmpcount
if tmpcount == 5 {
force = true
counter <- 0
}
networks, err := logic.GetNetworks() networks, err := logic.GetNetworks()
if err != nil { if err != nil {
logger.Log(1, "error retrieving networks for keepalive", err.Error()) logger.Log(1, "error retrieving networks for keepalive", err.Error())
@@ -252,7 +269,10 @@ func Keepalive(ctx context.Context) {
serverNode.SetLastCheckIn() serverNode.SetLastCheckIn()
logic.UpdateNode(&serverNode, &serverNode) logic.UpdateNode(&serverNode, &serverNode)
if network.DefaultUDPHolePunch == "yes" { if network.DefaultUDPHolePunch == "yes" {
if logic.ShouldPublishPeerPorts(&serverNode) { if logic.ShouldPublishPeerPorts(&serverNode) || force {
if force {
logger.Log(2, "sending scheduled peer update (5 min)")
}
err = PublishPeerUpdate(&serverNode) err = PublishPeerUpdate(&serverNode)
if err != nil { if err != nil {
logger.Log(1, "error publishing udp port updates for network", network.NetID) logger.Log(1, "error publishing udp port updates for network", network.NetID)
@@ -267,8 +287,6 @@ func Keepalive(ctx context.Context) {
} }
} }
} }
}
}
// func publishServerKeepalive(client mqtt.Client, network *models.Network) { // func publishServerKeepalive(client mqtt.Client, network *models.Network) {
// nodes, err := logic.GetNetworkNodes(network.NetID) // nodes, err := logic.GetNetworkNodes(network.NetID)

View File

@@ -132,7 +132,10 @@ func SetupMQTT(cfg *config.ClientConfig, publish bool) mqtt.Client {
ncutils.Log("detected broker connection lost, running pull for " + cfg.Node.Network) ncutils.Log("detected broker connection lost, running pull for " + cfg.Node.Network)
_, err := Pull(cfg.Node.Network, true) _, err := Pull(cfg.Node.Network, true)
if err != nil { if err != nil {
ncutils.Log("could not run pull, please restart daemon or examine network connectivity --- " + err.Error()) ncutils.Log("could not run pull, server unreachable, restarting daemon in 5 minutes..." + err.Error())
time.Sleep(time.Minute * 5)
ncutils.Log("restarting netclient")
daemon.Restart()
} }
ncutils.Log("connection re-established with mqtt server") ncutils.Log("connection re-established with mqtt server")
}) })