From 846d1977300e175f25b1ea68ff9aa504f5f50129 Mon Sep 17 00:00:00 2001 From: mikera Date: Thu, 21 Dec 2023 11:32:59 +0000 Subject: [PATCH] More CNS refactoring towards separate node ownership --- convex-core/src/main/cvx/convex/registry.cvx | 38 ++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/convex-core/src/main/cvx/convex/registry.cvx b/convex-core/src/main/cvx/convex/registry.cvx index fbd5121ae..13fcaba06 100644 --- a/convex-core/src/main/cvx/convex/registry.cvx +++ b/convex-core/src/main/cvx/convex/registry.cvx @@ -49,14 +49,20 @@ ;;;;;;;;;;;;;; Convex Name System root +;; Map of `node key` -> `segment symbol` -> `[path trust-monitor meta]` +;; Node key is implementation defined in general, but for main rgistry uses: +;; nil for CNS root +;; vector of segment strings for child paths (def cns-database ^{:private? true} - ;; Map of `node key` -> `segment symbol` -> `[path trust-monitor meta]` - ;; Node key is implementation defined in general, but for main rgistry uses:: - ;; nil for CNS root - ;; vector of segment strings for child paths + {}) +;; Controllers for each CNS node managed under this actor +;; Default root is controlled by INIT account +(def cns-owners + {[] #1}) + (defn cns-control ^{:callable? true @@ -111,8 +117,26 @@ (defn cns-read ^{:callable? true :doc {:description "Reads a CNS record from this Actor (as a CNS node). Assumes a record key passed in *scope*." - :examples [{:code "(call [*registry* [\"convex\"]] (cns-read))"}] + :examples [{:code "(call [cns-node cns-key] (cns-read \\\"my-name\\\"))"}] :signature [{:params [sym]}]}} - [sym] - ()) + [pname] + (get-in cns-database [*scope* pname])) + +(defn cns-write + ^{:callable? true + :doc {:description "Writes a CNS record from this Actor (as a CNS node). Assumes a record key passed in *scope*." + :examples [{:code "(call [cns-node cns-key] (cns-write \"my-name\" new-record))"}] + :signature [{:params [sym]}]}} + [pname addr cont meta] + (let [sm (get cns-database *scope*)] + (or (string? pname) (fail :ARGUMENT "CNS path element must be a string")) + (or sm (error :STATE "CNS Node key not valid")) + (if-let [rec (get sm sym)] + (do ;; This is an existing record, so check record controller + (or (trust/trusted? (get rec 1) *caller* :update) (fail :TRUST "No permission to update CNS record")) + (set-in! cns-database [*scope* pname] [addr cont meta])) + (do ;; This is a new record, so check create permission TODO use per-node monitor? + (or (trust/trusted? (get cns-owners *scope*) *caller* :create pname) (fail :TRUST "No permission to create CNS record")) + ) + )))