EntropyEngine::Networking::PropertyRegistry
EntropyEngine::Networking::PropertyRegistry
Section titled “EntropyEngine::Networking::PropertyRegistry”Thread-safe global property registry. More…
#include <PropertyRegistry.h>
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~PropertyRegistry() =default | |
| bool | validateType(PropertyHash hash, PropertyType expectedType) const Validate property type (hash → type check). |
| Result< void > | validatePropertyValue(PropertyHash hash, const PropertyValue & value) const Validate property value type (SECURITY CRITICAL). |
| bool | unregisterProperty(PropertyHash hash) Unregister a single property. |
| std::vector< PropertyHash > | unregisterEntity(uint64_t entityId) Unregister all properties for an entity. |
| size_t | size() const Get total number of registered properties. |
| Result< void > | registerProperty(PropertyMetadata metadata) Register a property in the registry. |
| PropertyRegistry & | operator=(const PropertyRegistry & ) =delete |
| PropertyRegistry & | operator=(PropertyRegistry && ) =delete |
| std::optional< PropertyMetadata > | lookup(PropertyHash hash) const Lookup property metadata by hash. |
| bool | isRegistered(PropertyHash hash) const Check if a property is registered. |
| std::vector< PropertyHash > | getEntityProperties(uint64_t entityId) const Get all property hashes for an entity. |
| std::vector< PropertyMetadata > | getAllProperties() const Get all registered properties (for debugging). |
| bool | empty() const Check if registry is empty. |
| void | clear() Clear all registrations. |
| PropertyRegistry() =default | |
| PropertyRegistry(const PropertyRegistry & ) =delete | |
| PropertyRegistry(PropertyRegistry && ) =delete |
Public Attributes
Section titled “Public Attributes”| Name | |
|---|---|
| size_t | MAX_TOTAL_PROPERTIES |
| size_t | MAX_PROPERTIES_PER_ENTITY |
| size_t | MAX_NAME_LENGTH |
Detailed Description
Section titled “Detailed Description”class EntropyEngine::Networking::PropertyRegistry;Thread-safe global property registry.
The PropertyRegistry is Canvas’s single source of truth for all properties. One instance on the server tracks ALL properties across ALL entities.
Registration is idempotent: re-registering the same property (same hash + metadata) updates the timestamp and returns success. This allows clients to re-register on reconnection without errors.
SECURITY: Always call validatePropertyValue() before applying property updates. This prevents bad actors from crashing the server by sending wrong types.
Thread Safety: All methods are thread-safe using shared_mutex (multiple readers, single writer).
PropertyRegistry registry;
// Register property once when entity createdauto typeHash = transformSchema.typeHash; // From ComponentSchemaauto hash = computePropertyHash(42, typeHash, "position");PropertyMetadata meta{hash, 42, typeHash, "position", PropertyType::Vec3, now};auto result = registry.registerProperty(meta);
// SECURITY: Validate on every updatePropertyValue incomingValue = getFromNetwork();auto validation = registry.validatePropertyValue(hash, incomingValue);if (validation.success()) { applyUpdate(hash, incomingValue); // Safe} else { LOG_ERROR("Rejected malicious update: " + validation.errorMessage);}
// Cleanup when entity destroyedauto removedHashes = registry.unregisterEntity(42);Public Functions Documentation
Section titled “Public Functions Documentation”function ~PropertyRegistry
Section titled “function ~PropertyRegistry”~PropertyRegistry() =defaultfunction validateType
Section titled “function validateType”bool validateType( PropertyHash hash, PropertyType expectedType) constValidate property type (hash → type check).
Parameters:
- hash Property hash
- expectedType Expected type
Return: true if property exists and type matches, false otherwise
Checks that the registered property has the expected type.
@threadsafety Thread-safe (read lock)
function validatePropertyValue
Section titled “function validatePropertyValue”Result< void > validatePropertyValue( PropertyHash hash, const PropertyValue & value) constValidate property value type (SECURITY CRITICAL).
Parameters:
- hash Property hash
- value Property value to validate
Return: Result indicating success or error
Validates that a property value’s type matches the registered type. ALWAYS call this before applying property updates to prevent bad actors from crashing the server with type confusion attacks.
Returns error if:
- Property not registered (UnknownProperty)
- Type mismatch (TypeMismatch)
@threadsafety Thread-safe (read lock)
// SECURE: Validate before applyingauto validation = registry.validatePropertyValue(hash, value);if (validation.success()) { applyUpdate(hash, value);} else { LOG_ERROR("Rejected: " + validation.errorMessage);}
// INSECURE: NEVER do this!// applyUpdate(hash, value); // ← Can crash from type mismatch!function unregisterProperty
Section titled “function unregisterProperty”bool unregisterProperty( PropertyHash hash)Unregister a single property.
Parameters:
- hash Property hash to unregister
Return: true if property was removed, false if not found
Removes a single property registration.
@threadsafety Thread-safe (write lock)
function unregisterEntity
Section titled “function unregisterEntity”std::vector< PropertyHash > unregisterEntity( uint64_t entityId)Unregister all properties for an entity.
Parameters:
- entityId Entity to unregister
Return: Vector of removed property hashes
Removes all property registrations for the given entity. Used when an entity is destroyed to clean up the registry.
Returns a vector of all removed property hashes. Callers can use this to remove corresponding data from ECS, network buffers, etc.
@threadsafety Thread-safe (write lock)
function size
Section titled “function size”size_t size() constGet total number of registered properties.
Return: Property count
@threadsafety Thread-safe (read lock)
function registerProperty
Section titled “function registerProperty”Result< void > registerProperty( PropertyMetadata metadata)Register a property in the registry.
Parameters:
- metadata Property metadata (includes hash)
Return: Result indicating success or error
Registers a property instance with its metadata. This is idempotent: re-registering the same property (same hash + metadata) updates the timestamp and returns success.
Returns error if:
- Hash collision (same hash, different metadata)
- Invalid metadata (empty componentType or propertyName)
- Invalid type (PropertyType enum out of range)
@threadsafety Thread-safe (write lock)
function operator=
Section titled “function operator=”PropertyRegistry & operator=( const PropertyRegistry &) =deletefunction operator=
Section titled “function operator=”PropertyRegistry & operator=( PropertyRegistry &&) =deletefunction lookup
Section titled “function lookup”std::optional< PropertyMetadata > lookup( PropertyHash hash) constLookup property metadata by hash.
Parameters:
- hash Property hash
Return: Optional metadata if found, nullopt otherwise
@threadsafety Thread-safe (read lock)
function isRegistered
Section titled “function isRegistered”bool isRegistered( PropertyHash hash) constCheck if a property is registered.
Parameters:
- hash Property hash
Return: true if registered, false otherwise
@threadsafety Thread-safe (read lock)
function getEntityProperties
Section titled “function getEntityProperties”std::vector< PropertyHash > getEntityProperties( uint64_t entityId) constGet all property hashes for an entity.
Parameters:
- entityId Entity ID
Return: Vector of property hashes (empty if entity not found)
Returns a vector of all property hashes registered for the given entity. Useful for debugging and entity inspection.
@threadsafety Thread-safe (read lock)
function getAllProperties
Section titled “function getAllProperties”std::vector< PropertyMetadata > getAllProperties() constGet all registered properties (for debugging).
Return: Vector of all property metadata
Returns a vector of all property metadata in the registry. Warning: This copies the entire registry - expensive for large registries.
@threadsafety Thread-safe (read lock)
function empty
Section titled “function empty”bool empty() constCheck if registry is empty.
Return: true if no properties registered
@threadsafety Thread-safe (read lock)
function clear
Section titled “function clear”void clear()Clear all registrations.
Removes all properties from the registry.
@threadsafety Thread-safe (write lock)
function PropertyRegistry
Section titled “function PropertyRegistry”PropertyRegistry() =defaultfunction PropertyRegistry
Section titled “function PropertyRegistry”PropertyRegistry( const PropertyRegistry &) =deletefunction PropertyRegistry
Section titled “function PropertyRegistry”PropertyRegistry( PropertyRegistry &&) =deletePublic Attributes Documentation
Section titled “Public Attributes Documentation”variable MAX_TOTAL_PROPERTIES
Section titled “variable MAX_TOTAL_PROPERTIES”static size_t MAX_TOTAL_PROPERTIES = 1'000'000;variable MAX_PROPERTIES_PER_ENTITY
Section titled “variable MAX_PROPERTIES_PER_ENTITY”static size_t MAX_PROPERTIES_PER_ENTITY = 1000;variable MAX_NAME_LENGTH
Section titled “variable MAX_NAME_LENGTH”static size_t MAX_NAME_LENGTH = 256;Updated on 2026-01-26 at 17:14:35 -0500