mirror of
https://github.com/danderson/netboot.git
synced 2025-12-06 18:11:42 +01:00
Removed goroutine that was used to periodically call ExpireIdentityAssociations.
ExpireIdentityAssociations is now being called synchronously, in the beginning of the ReserveAddresses() call.
This commit is contained in:
parent
b36c94fc0a
commit
3268bf94a3
@ -67,15 +67,6 @@ func NewRandomAddressPool(poolStartAddress net.IP, poolSize uint64, validLifetim
|
|||||||
ret.usedIps = make(map[uint64]struct{})
|
ret.usedIps = make(map[uint64]struct{})
|
||||||
ret.identityAssociationExpirations = newFifo()
|
ret.identityAssociationExpirations = newFifo()
|
||||||
ret.timeNow = func() time.Time { return time.Now() }
|
ret.timeNow = func() time.Time { return time.Now() }
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second * 10).C
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
<- ticker
|
|
||||||
ret.ExpireIdentityAssociations()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +75,8 @@ func (p *RandomAddressPool) ReserveAddresses(clientID []byte, interfaceIDs [][]b
|
|||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
|
|
||||||
|
p.expireIdentityAssociations()
|
||||||
|
|
||||||
ret := make([]*dhcp6.IdentityAssociation, 0, len(interfaceIDs))
|
ret := make([]*dhcp6.IdentityAssociation, 0, len(interfaceIDs))
|
||||||
rng := rand.New(rand.NewSource(p.timeNow().UnixNano()))
|
rng := rand.New(rand.NewSource(p.timeNow().UnixNano()))
|
||||||
|
|
||||||
@ -137,12 +130,9 @@ func (p *RandomAddressPool) ReleaseAddresses(clientID []byte, interfaceIDs [][]
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpireIdentityAssociations releases IP addresses in identity associations that reached the end of valid lifetime
|
// expireIdentityAssociations releases IP addresses in identity associations that reached the end of valid lifetime
|
||||||
// back into the address pool
|
// back into the address pool. Note it should be called from under the RandomAddressPool.lock.
|
||||||
func (p *RandomAddressPool) ExpireIdentityAssociations() {
|
func (p *RandomAddressPool) expireIdentityAssociations() {
|
||||||
p.lock.Lock()
|
|
||||||
defer p.lock.Unlock()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if p.identityAssociationExpirations.Size() < 1 { break }
|
if p.identityAssociationExpirations.Size() < 1 { break }
|
||||||
expiration := p.identityAssociationExpirations.Peek().(*associationExpiration)
|
expiration := p.identityAssociationExpirations.Peek().(*associationExpiration)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user