예제 #1
0
파일: ports.go 프로젝트: roacobb/geard
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")
}
예제 #2
0
파일: ports.go 프로젝트: roacobb/geard
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")
}