Fix: fakeip pool cycle used

This commit is contained in:
Dreamacro
2021-11-23 22:01:49 +08:00
parent b1bed7623d
commit 075d8ed094
5 changed files with 55 additions and 4 deletions

View File

@ -15,6 +15,7 @@ type store interface {
PutByHost(host string, ip net.IP)
GetByIP(ip net.IP) (string, bool)
PutByIP(ip net.IP, host string)
DelByIP(ip net.IP)
Exist(ip net.IP) bool
CloneTo(store)
}
@ -97,6 +98,9 @@ func (p *Pool) get(host string) net.IP {
p.offset = (p.offset + 1) % (p.max - p.min)
// Avoid infinite loops
if p.offset == current {
p.offset = (p.offset + 1) % (p.max - p.min)
ip := uintToIP(p.min + p.offset - 1)
p.store.DelByIP(ip)
break
}