|
@@ -208,7 +208,6 @@ func UpdateHostNetwork(h *models.Host, network string, add bool) (*models.Node,
|
|
|
} else {
|
|
|
return nil, errors.New("host already part of network " + network)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
if !add {
|
|
@@ -362,13 +361,13 @@ func GetRelatedHosts(hostID string) []models.Host {
|
|
|
// with the same endpoint have different listen ports
|
|
|
// in the case of 64535 hosts or more with same endpoint, ports will not be changed
|
|
|
func CheckHostPorts(h *models.Host) {
|
|
|
- portsInUse := make(map[int]bool)
|
|
|
+ portsInUse := make(map[int]bool, 0)
|
|
|
hosts, err := GetAllHosts()
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
for _, host := range hosts {
|
|
|
- if host.ID == h.ID {
|
|
|
+ if host.ID.String() == h.ID.String() {
|
|
|
//skip self
|
|
|
continue
|
|
|
}
|
|
@@ -380,12 +379,18 @@ func CheckHostPorts(h *models.Host) {
|
|
|
}
|
|
|
// iterate until port is not found or max iteration is reached
|
|
|
for i := 0; portsInUse[h.ListenPort] && i < maxPort-minPort+1; i++ {
|
|
|
- updatePort(&h.ListenPort)
|
|
|
+ h.ListenPort++
|
|
|
+ if h.ListenPort > maxPort {
|
|
|
+ h.ListenPort = minPort
|
|
|
+ }
|
|
|
}
|
|
|
// allocate h.ListenPort so it is unavailable to h.ProxyListenPort
|
|
|
portsInUse[h.ListenPort] = true
|
|
|
for i := 0; portsInUse[h.ProxyListenPort] && i < maxPort-minPort+1; i++ {
|
|
|
- updatePort(&h.ProxyListenPort)
|
|
|
+ h.ProxyListenPort++
|
|
|
+ if h.ProxyListenPort > maxPort {
|
|
|
+ h.ProxyListenPort = minPort
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -409,10 +414,3 @@ func GetHostByNodeID(id string) *models.Host {
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
-
|
|
|
-func updatePort(p *int) {
|
|
|
- *p++
|
|
|
- if *p > maxPort {
|
|
|
- *p = minPort
|
|
|
- }
|
|
|
-}
|