Ejemplo n.º 1
0
func (p *InstancePortTable) nextPort(host net.IP, from port.Port) port.HostPort {
	key := port.HostPort{host.String(), 0}
	for port := from; ; port++ {
		key.Port = port
		if _, ok := p.reserved[key]; !ok {
			p.reserved[key] = true
			return key
		}
		if port > 65535 {
			port = 40000
		}
	}
	panic("Unable to locate a valid port")
}
Ejemplo n.º 2
0
func (p *InstancePortTable) nextHost(host net.IP, from port.Port) port.HostPort {
	key := port.HostPort{host.String(), from}
	for {
		if _, ok := p.reserved[key]; !ok {
			p.reserved[key] = true
			return key
		}
		last := len(host) - 1
		host[last]++
		if host[last] == 255 {
			host[last-1]++
			host[last] = 1
		}
		key.Host = host.String()
	}
	panic("Unable to locate a valid host")
}