mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-11-01 04:32:40 +08:00 
			
		
		
		
	fetch related hosts on relay creation to enable proxy
This commit is contained in:
		| @@ -295,3 +295,26 @@ func GetHostNetworks(hostID string) []string { | ||||
| 	} | ||||
| 	return nets | ||||
| } | ||||
|  | ||||
| // GetRelatedHosts - fetches related hosts of a given host | ||||
| func GetRelatedHosts(hostID string) []models.Host { | ||||
| 	relatedHosts := []models.Host{} | ||||
| 	networks := GetHostNetworks(hostID) | ||||
| 	networkMap := make(map[string]struct{}) | ||||
| 	for _, network := range networks { | ||||
| 		networkMap[network] = struct{}{} | ||||
| 	} | ||||
| 	hosts, err := GetAllHosts() | ||||
| 	if err == nil { | ||||
| 		for _, host := range hosts { | ||||
| 			networks := GetHostNetworks(host.ID.String()) | ||||
| 			for _, network := range networks { | ||||
| 				if _, ok := networkMap[network]; ok { | ||||
| 					relatedHosts = append(relatedHosts, host) | ||||
| 					break | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return relatedHosts | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Abhishek Kondur
					Abhishek Kondur