2
0
Эх сурвалжийг харах

fix peer endpoint selection

abhishek9686 1 жил өмнө
parent
commit
bad78e2683
2 өөрчлөгдсөн 10 нэмэгдсэн , 8 устгасан
  1. 3 0
      logic/extpeers.go
  2. 7 8
      logic/peers.go

+ 3 - 0
logic/extpeers.go

@@ -475,6 +475,9 @@ func getExtpeersExtraRoutes(network string) (egressRoutes []models.EgressNetwork
 		return
 	}
 	for _, extPeer := range extPeers {
+		if len(extPeer.ExtraAllowedIPs) == 0 {
+			continue
+		}
 		egressRoutes = append(egressRoutes, getExtPeerEgressRoute(extPeer)...)
 	}
 	return

+ 7 - 8
logic/peers.go

@@ -215,16 +215,15 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
 				}
 			}
 
+			//1. check currHost has ipv4 endpoint and peerhost has ipv4 then set ipv4 endpoint for peer
+			// 2. check currHost has ipv6 endpoint and peerhost has ipv6 then set ipv6 endpoint for peer
+
 			//if host is ipv4 only or ipv4+ipv6, set the peer endpoint to ipv4 address, if host is ipv6 only, set the peer endpoint to ipv6 address
-			peerEndpoint := peerHost.EndpointIP
-			if ipv4 := host.EndpointIP.To4(); ipv4 != nil {
+			var peerEndpoint net.IP
+			if host.EndpointIP != nil && peerHost.EndpointIP != nil {
 				peerEndpoint = peerHost.EndpointIP
-			} else {
-				//if peer host's ipv6 address is empty, it means that peer is an IPv4 only host
-				//IPv4 only host could not communicate with IPv6 only host
-				if peerHost.EndpointIPv6 != nil && peerHost.EndpointIPv6.String() != "" {
-					peerEndpoint = peerHost.EndpointIPv6
-				}
+			} else if host.EndpointIPv6 != nil && peerHost.EndpointIPv6 != nil {
+				peerEndpoint = peerHost.EndpointIPv6
 			}
 
 			peerConfig.Endpoint = &net.UDPAddr{