package delivery import ( "encoding/json" "fmt" "git.novox.be/novox/mesh-sdk/go/catalogue" ) // The private network's names as its manifest says them, written here as well as in overlay (Name, Requirement, // Addressing, TheNetwork), which delivery does not import so its many readers do not reach the network's generator; // a test keeps them agreeing. const ( overlayName = "mesh-wireguard" overlayRequirement = "private-network" overlayAddressing = "mesh-addressing" overlayTheNetwork = "the-private-network" ) // overlayManifest is overlay.Manifest(): the module the mesh provides for itself. func overlayManifest() map[string]any { return map[string]any{ "module": overlayName, "version": "1", "computed": overlayName, "provides": []string{overlayRequirement, overlayAddressing}, "claims": []map[string]any{{"name": overlayTheNetwork, "scope": "node"}}, } } // The modules the mesh provides itself (issue 1126): no repository holds them, so the indexer reads none; their // manifests come with mesh-sdk, built in code, and always win over any other. Today the private network alone // (overlay's mesh-wireguard), built by nobody and run inside each node's own composition. One predicate for every part that judges // or composes a placement: CheckPlacements, the seat's holder, the composer's input (frombus) and the grants part. // ProvidedModules is every module the mesh provides itself, sorted. func ProvidedModules() []string { return []string{overlayName} } // ProvidedByMesh says whether the mesh provides module itself, so a placement may name it with no repository holding it. func ProvidedByMesh(module string) bool { return module == overlayName } // ProvidedManifest is a provided module's manifest, as its readers parse it, and its raw JSON; an error for a module the // mesh does not provide or a manifest its own reader refuses. func ProvidedManifest(module string) (catalogue.Manifest, []byte, error) { if !ProvidedByMesh(module) { return catalogue.Manifest{}, nil, fmt.Errorf("delivery: the mesh provides no module %s", module) } raw, err := json.Marshal(overlayManifest()) if err != nil { return catalogue.Manifest{}, nil, err } // Decoded as every reader decodes a manifest (novox/hq ADR 0578 ยง3); its judgement is the indexer's. m, err := catalogue.Decode(raw) if err != nil { return catalogue.Manifest{}, raw, fmt.Errorf("delivery: the manifest mesh-sdk provides for %s does not decode: %w", module, err) } return m, raw, nil }