Extend 'Lookup' to multi-subnet

This commit is contained in:
Bryan Boreham committed 2015-06-10 17:21:16 +01:00
1 parent d18ccac43b
commit 2a00b0092d
3 files changed
+28 -6

No files matched your search

+6 -5
View File
@@ -200,13 +200,14 @@ func (alloc *Allocator) Allocate(ident string, subnet address.CIDR, cancelChan <
return result.addr, result.err
}
func (alloc *Allocator) Lookup(ident string) (address.Address, error) {
func (alloc *Allocator) Lookup(ident string, subnet address.CIDR) (address.Address, error) {
resultChan := make(chan allocateResult)
alloc.actionChan <- func() {
addr, found := alloc.owned[ident]
if found {
resultChan <- allocateResult{addr: addr[0]}
return
for _, addr := range alloc.owned[ident] {
if subnet.Contains(addr) {
resultChan <- allocateResult{addr: addr}
return
}
}
resultChan <- allocateResult{err: fmt.Errorf("lookup: no address found")}
}