MCPcopy Create free account
hub / github.com/coder/coder / storeBinding

Method storeBinding

enterprise/tailnet/pgcoord.go:646–672  ·  view source on GitHub ↗

storeBinding stores the latest binding, where we interpret kind == DISCONNECTED as removing the binding. This keeps the map from growing without bound.

(bnd binding)

Source from the content-addressed store, hash-verified

644// storeBinding stores the latest binding, where we interpret kind == DISCONNECTED as removing the binding. This keeps the map
645// from growing without bound.
646func (b *binder) storeBinding(bnd binding) bool {
647 b.mu.Lock()
648 defer b.mu.Unlock()
649
650 switch bnd.kind {
651 case proto.CoordinateResponse_PeerUpdate_NODE:
652 old, ok := b.latest[bnd.bKey]
653 if ok && old.kind == proto.CoordinateResponse_PeerUpdate_NODE &&
654 nodesEqual(old.node, bnd.node) {
655 return false
656 }
657 b.latest[bnd.bKey] = bnd
658 case proto.CoordinateResponse_PeerUpdate_DISCONNECTED:
659 delete(b.latest, bnd.bKey)
660 case proto.CoordinateResponse_PeerUpdate_LOST:
661 // We need to coalesce with the previously stored node, since it
662 // must be non-nil in the database.
663 old, ok := b.latest[bnd.bKey]
664 if !ok {
665 // Lost before we ever got a node update. No action.
666 return false
667 }
668 bnd.node = old.node
669 b.latest[bnd.bKey] = bnd
670 }
671 return true
672}
673
674// nodesEqual compares two proto.Node messages, ignoring the AsOf
675// timestamp which changes on every node build even when nothing else

Callers 2

Test_storeBindingFunction · 0.95
handleBindingsMethod · 0.95

Calls 3

nodesEqualFunction · 0.85
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

Test_storeBindingFunction · 0.76