Skip to content

Commit a1d2997

Browse files
committed
libn/d/overlay: inline secMapWalk into only caller
func (*driver) secMapWalk is a curious beast. It is named walk, yet it also mutates the collection being iterated over. It returns an error, but that error is always nil. It takes a callback that can break iteration, yet the only caller makes no use of that affordance. Its utility is limited and the abstraction hinders readability more than it helps. Open-code the d.secMap.nodes loop into func (*driver) updateKeys(), the only caller. Signed-off-by: Cory Snider <[email protected]>
1 parent 74713e1 commit a1d2997

1 file changed

Lines changed: 8 additions & 18 deletions

File tree

libnetwork/drivers/overlay/encryption.go

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,6 @@ func buildAeadAlgo(k *key, s int) *netlink.XfrmStateAlgo {
451451
}
452452
}
453453

454-
func (d *driver) secMapWalk(f func(netip.Addr, []spi) ([]spi, bool)) error {
455-
d.secMap.mu.Lock()
456-
for rIP, node := range d.secMap.nodes {
457-
idxs, stop := f(rIP, node.spi)
458-
if idxs != nil {
459-
d.secMap.nodes[rIP] = encrNode{idxs, node.count}
460-
}
461-
if stop {
462-
break
463-
}
464-
}
465-
d.secMap.mu.Unlock()
466-
return nil
467-
}
468-
469454
func (d *driver) setKeys(keys []*key) error {
470455
// Remove any stale policy, state
471456
clearEncryptionStates()
@@ -521,9 +506,14 @@ func (d *driver) updateKeys(newKey, primary, pruneKey *key) error {
521506
return types.InvalidParameterErrorf("attempting to both make a key (index %d) primary and delete it", priIdx)
522507
}
523508

524-
d.secMapWalk(func(rIP netip.Addr, spis []spi) ([]spi, bool) {
525-
return updateNodeKey(lIP.AsSlice(), aIP.AsSlice(), rIP.AsSlice(), spis, d.keys, newIdx, priIdx, delIdx), false
526-
})
509+
d.secMap.mu.Lock()
510+
for rIP, node := range d.secMap.nodes {
511+
idxs := updateNodeKey(lIP.AsSlice(), aIP.AsSlice(), rIP.AsSlice(), node.spi, d.keys, newIdx, priIdx, delIdx)
512+
if idxs != nil {
513+
d.secMap.nodes[rIP] = encrNode{idxs, node.count}
514+
}
515+
}
516+
d.secMap.mu.Unlock()
527517

528518
// swap primary
529519
if priIdx != -1 {

0 commit comments

Comments
 (0)