package resolution import ( mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) func providesAt(m mcat.Manifest, provision, scope string) bool { for _, o := range m.Provides { if o.Name == provision && o.At() == scope { return true } } return false } // HolderAmong is which of several providers of a provision holds the seat that delivers it. // // Found by the (node, module) pair, because a provider is identified by both (novox/hq to-be 23): // two modules on one node could both provide a provision, and only the one holding the seat // answers for it. Nothing when no seat delivers the provision, when nobody holds // it, or when the holder is not among the providers offered. // // **The first holder in the providers' own order** (novox/hq ADR 0223). A replicated seat has // several, and the answer must not depend on the order the mesh happened to resolve its machines // in: the providers come sorted by machine, so every consumer is bound to the same one. A seat with // one holder gets the same answer as before. func HolderAmong(provision string, providers []mcat.Provider, held []mcat.Held) (mcat.Provider, bool) { seat, delivered := mcat.SeatDelivering(provision) if !delivered { return mcat.Provider{}, false } for _, p := range providers { for _, h := range held { // Resolve the held claim to a seat rather than comparing names, so a record naming a // seat's former name still matches it after a rename (novox/hq ADR 0122). hs, ok := mcat.SeatNamed(h.Claim) if !ok || hs.Name != seat.Name || h.Scope != seat.Scope { continue } if p.Node == h.Node && p.Module == h.Module { return p, true } } } return mcat.Provider{}, false }