mirror of
https://github.com/gravitl/netmaker.git
synced 2026-04-23 00:17:10 +08:00
NM-122: Auto Relay, auto assignment of Gw (#3697)
* add auto realy handlers and logic funcs * add pro func connectors * Add auto relayed peer ips on peer update, set auto relay on gw creation * add network id to signal, add autorelay nodes to peerudpate * add autorelay peer update logic * add nodes to peer update * revert node model change * reset auto relayed peers on the relay node on reset, add auto relay nodes to pull * add logic api to update auto relay node * add autoassigngw field to node, add logic to swith relay node in relayme udpate api * add gw nodes to pull * intilaise gw map * HA relay functionality * add autoassign gw option to enrollment key * publish intant action to auto assign gw * fix static checks * unset relay if auto assign removed * add host node model to auto relay info * add host node model to auto relay info * only use hostNode model for gws info * handle autoassigned gw peer in the update * handle autoassigned gw peer in the update * handle peer updates for autoassigned gw peer * unset auto assigned peer if relayed or failedovered
This commit is contained in:
+23
-4
@@ -108,21 +108,28 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
|
||||
case models.CheckIn:
|
||||
sendPeerUpdate = HandleHostCheckin(&hostUpdate.Host, currentHost)
|
||||
case models.Acknowledgement:
|
||||
nodes, err := logic.GetAllNodes()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
hu := hostactions.GetAction(currentHost.ID.String())
|
||||
if hu != nil {
|
||||
if err = HostUpdate(hu); err != nil {
|
||||
slog.Error("failed to send new node to host", "name", hostUpdate.Host.Name, "id", currentHost.ID, "error", err)
|
||||
return
|
||||
} else {
|
||||
nodes, err := logic.GetAllNodes()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = PublishSingleHostPeerUpdate(currentHost, nodes, nil, nil, false, nil); err != nil {
|
||||
slog.Error("failed peers publish after join acknowledged", "name", hostUpdate.Host.Name, "id", currentHost.ID, "error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// send latest host update
|
||||
HostUpdate(&models.HostUpdate{
|
||||
Action: models.UpdateHost,
|
||||
Host: *currentHost})
|
||||
PublishSingleHostPeerUpdate(currentHost, nodes, nil, nil, false, nil)
|
||||
}
|
||||
case models.UpdateHost:
|
||||
if hostUpdate.Host.PublicKey != currentHost.PublicKey {
|
||||
@@ -188,6 +195,18 @@ func SignalPeer(signal models.Signal) {
|
||||
logger.Log(0, msg)
|
||||
return
|
||||
}
|
||||
node, err := logic.GetNodeByID(signal.FromNodeID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
peer, err := logic.GetNodeByID(signal.ToNodeID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if node.Network != peer.Network {
|
||||
return
|
||||
}
|
||||
signal.NetworkID = node.Network
|
||||
signal.IsPro = servercfg.IsPro
|
||||
peerHost, err := logic.GetHost(signal.ToHostID)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user