diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-05-08 17:31:36 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-05-08 17:31:36 -0300 |
| commit | 602af97c269bdc211cc7aeb34e436152053395cc (patch) | |
| tree | a76761eaee85550d5b16e228e8f2c75f4fd88c6f /include/NT.h | |
| parent | 4a14379e3fa49714d169b0a3aaa1ed2b38058196 (diff) | |
| download | RNT-602af97c269bdc211cc7aeb34e436152053395cc.tar.gz RNT-602af97c269bdc211cc7aeb34e436152053395cc.zip | |
restructure project
Diffstat (limited to '')
| -rw-r--r-- | include/NT.h (renamed from Runtime/NtContext.h) | 114 |
1 files changed, 67 insertions, 47 deletions
diff --git a/Runtime/NtContext.h b/include/NT.h index 4e28f9f..a24d9d4 100644 --- a/Runtime/NtContext.h +++ b/include/NT.h @@ -4,10 +4,14 @@ #include <vector> #include <string> -#ifdef NT_EXPORTS +#if defined(_WIN32) && defined(NT_CONSOLE_APP) +#define NT_API +#elif defined(_WIN32) && defined(NT_EXPORTS) #define NT_API __declspec(dllexport) -#else +#elif defined(_WIN32) #define NT_API __declspec(dllimport) +#else +#define NT_API #endif enum OBJECT_TYPE { @@ -37,12 +41,13 @@ enum AUTH_METHOD { namespace nt { - class NT_API ObjectManager - { - public: - class IObject { - virtual ~IObject() {} - }; + class NT_API ObjectManager + { + public: + class IObject { + public: + virtual ~IObject() = default; + }; class Multigroup : IObject {}; class Relation : IObject {}; class Tuple : IObject {}; @@ -66,25 +71,26 @@ namespace nt // TODO: Treat as a list for now, but ideally it's a tree struct registry* next; }; - struct registry** registry; + struct registry** entries; // Looks into this registry and attempts to retrieve the entry - struct registry* Find(const std::vector<std::string> object_path){} - }; + struct registry* Find(const std::vector<std::string> object_path) { return nullptr; } + }; class NT_API PermissionsManager { public: // For validating connections at login - std::set<AUTH_CLAIM> Firewall(AUTH_METHOD method) {} - // For validating permission to an object - const bool Access(const std::vector<std::string> object_path, const void* connection_context) { - // Checks the security descriptor on the head of the object we find in the ObjectManager::registry - // Then additionally check other metadata yet to be defined in the connection_context, - // like user group, policy, etc. - // Yet to decide if this should be summoned at every attempt to get ahold of an object, - // that might produce significant overhead. How can we solve this? - } - }; + std::set<AUTH_CLAIM> Firewall(AUTH_METHOD method) { return {}; } + // For validating permission to an object + const bool Access(const ObjectManager::registry* object, const void* connection_context) { + // Checks the security descriptor on the head of the object we find in the ObjectManager::registry + // Then additionally check other metadata yet to be defined in the connection_context, + // like user group, policy, etc. + // Yet to decide if this should be summoned at every attempt to get ahold of an object, + // that might produce significant overhead. How can we solve this? + return object != nullptr && connection_context != nullptr; + } + }; class NT_API NamespaceReferenceManager { @@ -98,8 +104,9 @@ namespace nt { public: // Looks into the methods of the object type and asserts if it can be opened - const bool CanOpen(struct ObjectManager::registry* object) {} - }; + const bool CanOpen(ObjectManager::registry* object) { return object != nullptr; } + const bool CanClose(ObjectManager::registry* object) { return object != nullptr; } + }; class NT_API LifecycleManager { @@ -107,7 +114,7 @@ namespace nt // If object is not being monitored already, monitors the lifecycle by updating the handle count. // Maybe also look at the reference count and kill some categories of disposable objects no longer referenced by other objects, like transactions. // Think of other use cases later. - void Monitor(struct ObjectManager::registry* object) {} + void Monitor(ObjectManager::registry* object) {} // Serializes contention for the change of a mutable reference. // This can be used in, for example, the HEAD of a branch to serialize the access. // If the object does not causes contention, like a relation (since they are immutable, just like multigroups, all snapshots) @@ -116,10 +123,10 @@ namespace nt // for example: the HEAD of a branch, namespace collisions (creating two branches with the same name, or two multigroups with the same name from the same state, etc), // multi-branch atomic commits (which I wish to not have as it damages isolation), // garbage collection of old state (as in, we want to delete an old-enough history to save up space), etc. - const bool Contention(struct ObjectManager::registry* object){} + const bool Contention(ObjectManager::registry* object){ return object != nullptr; } // The inverse of `Monitor`, stops monitoring. // Maybe garbage collect here also if the counters goes to zero. - void Unmonitor(struct ObjectManager::registry* object) {} + void Unmonitor(ObjectManager::registry* object) {} }; class NT_API HandlerManager @@ -128,36 +135,49 @@ namespace nt // This is supposed to represent an authorized access to a certain object in the registry // This increases the handle count in the object manager // We should consider adding on the object manager a vector of all the handles that refer to an object - struct handle {}; - void DeallocateHandle(struct handle* handle) {} - struct handle Open(std::vector<std::string> object_path, void* connection_context) { - struct ObjectManager::registry* retrieved_object = ObjectManager::Find((const std::vector<std::string>)object_path); - if (PermissionsManager::Access(retrieved_object, (const void*)connection_context) - && IdentityManager::CanOpen(retrieved_object) - && LifecycleManager::Contention(retrieved_object)) { - // Starts monitoring this guy - LifecycleManager::Monitor(retrieved_object); - return {}; // Return a successful handle + struct handle { + ObjectManager::registry* object = nullptr; + void* connection_context = nullptr; + }; + void DeallocateHandle(struct handle* handle) {} + struct handle Open(std::vector<std::string> object_path, void* connection_context) { + ObjectManager objects; + PermissionsManager permissions; + IdentityManager identities; + LifecycleManager lifecycles; + ObjectManager::registry* retrieved_object = objects.Find((const std::vector<std::string>)object_path); + if (permissions.Access(retrieved_object, (const void*)connection_context) + && identities.CanOpen(retrieved_object) + && lifecycles.Contention(retrieved_object)) { + // Starts monitoring this guy + lifecycles.Monitor(retrieved_object); + return { retrieved_object, connection_context }; // Return a successful handle } else { // Return something more algebraic instead of null or an int return {}; }; } - bool Close(struct handle *handle) { - // Somehow grab the object pointer and connection (maybe drop it...) from the handle - struct ObjectManager::registry* object = handle->object; - void* connection_context = handle->connection_context; - // Checking for permissions here may be relevant. - // What if we have a handle but no permission? Spooky - if (PermissionsManager::Access(object, connection_context) - && IdentityManager::CanClose(object) + bool Close(struct handle *handle) { + if (handle == nullptr) { + return false; + } + PermissionsManager permissions; + IdentityManager identities; + LifecycleManager lifecycles; + // Somehow grab the object pointer and connection (maybe drop it...) from the handle + ObjectManager::registry* object = handle->object; + void* connection_context = handle->connection_context; + // Checking for permissions here may be relevant. + // What if we have a handle but no permission? Spooky + if (permissions.Access(object, connection_context) + && identities.CanClose(object) // TODO: I think that in this case we do not need to worry about contention. // But be careful to evaluate this scenario later. //&& LifecycleManager::Contention(retrieved_object) - ) { - // Stops monitoring this guy - LifecycleManager::Unmonitor(object); + ) { + // Stops monitoring this guy + lifecycles.Unmonitor(object); DeallocateHandle(handle); return true; // Return a successful handle } |
