mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
update relay when relayed address updated
This commit is contained in:
parent
7701aead2c
commit
cb0635f0ee
2 changed files with 50 additions and 1 deletions
|
@ -635,6 +635,10 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
}
|
||||
relayedUpdate := false
|
||||
if node.IsRelayed == "yes" && (node.Address != newNode.Address || node.Address6 != newNode.Address6) {
|
||||
relayedUpdate = true
|
||||
}
|
||||
|
||||
if !servercfg.GetRce() {
|
||||
newNode.PostDown = node.PostDown
|
||||
|
@ -659,7 +663,9 @@ func updateNode(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if relayedUpdate {
|
||||
updateRelay(&node, &newNode)
|
||||
}
|
||||
if servercfg.IsDNSMode() {
|
||||
logic.SetDNS()
|
||||
}
|
||||
|
@ -758,3 +764,25 @@ func runForceServerUpdate(node *models.Node) {
|
|||
func isServer(node *models.Node) bool {
|
||||
return node.IsServer == "yes"
|
||||
}
|
||||
|
||||
func updateRelay(oldnode, newnode *models.Node) {
|
||||
relay := logic.FindRelay(oldnode)
|
||||
newrelay := relay
|
||||
if oldnode.Address != newnode.Address {
|
||||
for i, ip := range newrelay.RelayAddrs {
|
||||
if ip == oldnode.Address {
|
||||
newrelay.RelayAddrs = append(newrelay.RelayAddrs[:i], relay.RelayAddrs[i+1:]...)
|
||||
newrelay.RelayAddrs = append(newrelay.RelayAddrs, newnode.Address)
|
||||
}
|
||||
}
|
||||
}
|
||||
if oldnode.Address6 != newnode.Address6 {
|
||||
for i, ip := range newrelay.RelayAddrs {
|
||||
if ip == oldnode.Address {
|
||||
newrelay.RelayAddrs = append(newrelay.RelayAddrs[:i], newrelay.RelayAddrs[i+1:]...)
|
||||
newrelay.RelayAddrs = append(newrelay.RelayAddrs, newnode.Address6)
|
||||
}
|
||||
}
|
||||
}
|
||||
logic.UpdateNode(relay, newrelay)
|
||||
}
|
||||
|
|
|
@ -681,3 +681,24 @@ func unsetHub(networkName string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func FindRelay(node *models.Node) *models.Node {
|
||||
if node.IsRelayed == "no" {
|
||||
return nil
|
||||
}
|
||||
peers, err := GetNetworkNodes(node.Network)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, peer := range peers {
|
||||
if peer.IsRelay == "no" {
|
||||
continue
|
||||
}
|
||||
for _, ip := range peer.RelayAddrs {
|
||||
if ip == node.Address || ip == node.Address6 {
|
||||
return &peer
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue