Browse Source

Merge pull request #2123 from gravitl/GRA-1337-local-addr-detection

GRA-1337: adjust peer updates to send ifaces with peer - hotfix
dcarns 2 years ago
parent
commit
2cd40cffd0
3 changed files with 40 additions and 22 deletions
  1. 15 6
      logic/peers.go
  2. 13 5
      models/metrics.go
  3. 12 11
      models/mqtt.go

+ 15 - 6
logic/peers.go

@@ -159,10 +159,11 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 		IngressInfo: models.IngressInfo{
 		IngressInfo: models.IngressInfo{
 			ExtPeers: make(map[string]models.ExtClientInfo),
 			ExtPeers: make(map[string]models.ExtClientInfo),
 		},
 		},
-		EgressInfo: make(map[string]models.EgressInfo),
-		PeerIDs:    make(models.PeerMap, 0),
-		Peers:      []wgtypes.PeerConfig{},
-		NodePeers:  []wgtypes.PeerConfig{},
+		EgressInfo:      make(map[string]models.EgressInfo),
+		PeerIDs:         make(models.PeerMap, 0),
+		Peers:           []wgtypes.PeerConfig{},
+		NodePeers:       []wgtypes.PeerConfig{},
+		HostNetworkInfo: models.HostInfoMap{},
 	}
 	}
 
 
 	logger.Log(1, "peer update for host", host.ID.String())
 	logger.Log(1, "peer update for host", host.ID.String())
@@ -277,6 +278,7 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 					}
 					}
 				}
 				}
 
 
+				peerProxyPort := GetProxyListenPort(peerHost)
 				var nodePeer wgtypes.PeerConfig
 				var nodePeer wgtypes.PeerConfig
 				if _, ok := hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()]; !ok {
 				if _, ok := hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()]; !ok {
 					hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()] = make(map[string]models.IDandAddr)
 					hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()] = make(map[string]models.IDandAddr)
@@ -287,7 +289,11 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 						Address:         peer.PrimaryAddress(),
 						Address:         peer.PrimaryAddress(),
 						Name:            peerHost.Name,
 						Name:            peerHost.Name,
 						Network:         peer.Network,
 						Network:         peer.Network,
-						ProxyListenPort: GetProxyListenPort(peerHost),
+						ProxyListenPort: peerProxyPort,
+					}
+					hostPeerUpdate.HostNetworkInfo[peerHost.PublicKey.String()] = models.HostNetworkInfo{
+						Interfaces:      peerHost.Interfaces,
+						ProxyListenPort: peerProxyPort,
 					}
 					}
 					nodePeer = peerConfig
 					nodePeer = peerConfig
 				} else {
 				} else {
@@ -301,6 +307,10 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 						Network:         peer.Network,
 						Network:         peer.Network,
 						ProxyListenPort: GetProxyListenPort(peerHost),
 						ProxyListenPort: GetProxyListenPort(peerHost),
 					}
 					}
+					hostPeerUpdate.HostNetworkInfo[peerHost.PublicKey.String()] = models.HostNetworkInfo{
+						Interfaces:      peerHost.Interfaces,
+						ProxyListenPort: peerProxyPort,
+					}
 					nodePeer = hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]]
 					nodePeer = hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]]
 				}
 				}
 
 
@@ -310,7 +320,6 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
 						Address:         peer.PrimaryAddress(),
 						Address:         peer.PrimaryAddress(),
 						Name:            peerHost.Name,
 						Name:            peerHost.Name,
 						Network:         peer.Network,
 						Network:         peer.Network,
-						Interfaces:      peerHost.Interfaces,
 						ProxyListenPort: peerHost.ProxyListenPort,
 						ProxyListenPort: peerHost.ProxyListenPort,
 					}
 					}
 					hostPeerUpdate.NodePeers = append(hostPeerUpdate.NodePeers, nodePeer)
 					hostPeerUpdate.NodePeers = append(hostPeerUpdate.NodePeers, nodePeer)

+ 13 - 5
models/metrics.go

@@ -29,11 +29,19 @@ type Metric struct {
 
 
 // IDandAddr - struct to hold ID and primary Address
 // IDandAddr - struct to hold ID and primary Address
 type IDandAddr struct {
 type IDandAddr struct {
-	ID              string  `json:"id" bson:"id" yaml:"id"`
-	Address         string  `json:"address" bson:"address" yaml:"address"`
-	Name            string  `json:"name" bson:"name" yaml:"name"`
-	IsServer        string  `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
-	Network         string  `json:"network" bson:"network" yaml:"network" validate:"network"`
+	ID              string `json:"id" bson:"id" yaml:"id"`
+	Address         string `json:"address" bson:"address" yaml:"address"`
+	Name            string `json:"name" bson:"name" yaml:"name"`
+	IsServer        string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
+	Network         string `json:"network" bson:"network" yaml:"network" validate:"network"`
+	ProxyListenPort int    `json:"proxy_listen_port" yaml:"proxy_listen_port"`
+}
+
+// HostInfoMap - map of host public keys to host networking info
+type HostInfoMap map[string]HostNetworkInfo
+
+// HostNetworkInfo - holds info related to host networking (used for client side peer calculations)
+type HostNetworkInfo struct {
 	Interfaces      []Iface `json:"interfaces" yaml:"interfaces"`
 	Interfaces      []Iface `json:"interfaces" yaml:"interfaces"`
 	ProxyListenPort int     `json:"proxy_listen_port" yaml:"proxy_listen_port"`
 	ProxyListenPort int     `json:"proxy_listen_port" yaml:"proxy_listen_port"`
 }
 }

+ 12 - 11
models/mqtt.go

@@ -8,17 +8,18 @@ import (
 
 
 // HostPeerUpdate - struct for host peer updates
 // HostPeerUpdate - struct for host peer updates
 type HostPeerUpdate struct {
 type HostPeerUpdate struct {
-	Host          Host                 `json:"host" bson:"host" yaml:"host"`
-	Server        string               `json:"server" bson:"server" yaml:"server"`
-	ServerVersion string               `json:"serverversion" bson:"serverversion" yaml:"serverversion"`
-	ServerAddrs   []ServerAddr         `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"`
-	NodePeers     []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
-	Peers         []wgtypes.PeerConfig
-	HostPeerIDs   HostPeerMap           `json:"hostpeerids" bson:"hostpeerids" yaml:"hostpeerids"`
-	ProxyUpdate   ProxyManagerPayload   `json:"proxy_update" bson:"proxy_update" yaml:"proxy_update"`
-	EgressInfo    map[string]EgressInfo `json:"egress_info" bson:"egress_info" yaml:"egress_info"` // map key is node ID
-	IngressInfo   IngressInfo           `json:"ingress_info" bson:"ext_peers" yaml:"ext_peers"`
-	PeerIDs       PeerMap               `json:"peerids" bson:"peerids" yaml:"peerids"`
+	Host            Host                 `json:"host" bson:"host" yaml:"host"`
+	Server          string               `json:"server" bson:"server" yaml:"server"`
+	ServerVersion   string               `json:"serverversion" bson:"serverversion" yaml:"serverversion"`
+	ServerAddrs     []ServerAddr         `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"`
+	NodePeers       []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
+	Peers           []wgtypes.PeerConfig
+	HostPeerIDs     HostPeerMap           `json:"hostpeerids" bson:"hostpeerids" yaml:"hostpeerids"`
+	ProxyUpdate     ProxyManagerPayload   `json:"proxy_update" bson:"proxy_update" yaml:"proxy_update"`
+	EgressInfo      map[string]EgressInfo `json:"egress_info" bson:"egress_info" yaml:"egress_info"` // map key is node ID
+	IngressInfo     IngressInfo           `json:"ingress_info" bson:"ext_peers" yaml:"ext_peers"`
+	PeerIDs         PeerMap               `json:"peerids" bson:"peerids" yaml:"peerids"`
+	HostNetworkInfo HostInfoMap           `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"`
 }
 }
 
 
 // IngressInfo - struct for ingress info
 // IngressInfo - struct for ingress info