Skip to content

EntropyEngine::Networking::PropertyRegistry

EntropyEngine::Networking::PropertyRegistry

Section titled “EntropyEngine::Networking::PropertyRegistry”

Thread-safe global property registry. More…

#include <PropertyRegistry.h>

Name
~PropertyRegistry() =default
boolvalidateType(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).
boolunregisterProperty(PropertyHash hash)
Unregister a single property.
std::vector< PropertyHash >unregisterEntity(uint64_t entityId)
Unregister all properties for an entity.
size_tsize() 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.
boolisRegistered(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).
boolempty() const
Check if registry is empty.
voidclear()
Clear all registrations.
PropertyRegistry() =default
PropertyRegistry(const PropertyRegistry & ) =delete
PropertyRegistry(PropertyRegistry && ) =delete
Name
size_tMAX_TOTAL_PROPERTIES
size_tMAX_PROPERTIES_PER_ENTITY
size_tMAX_NAME_LENGTH
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 created
auto typeHash = transformSchema.typeHash; // From ComponentSchema
auto hash = computePropertyHash(42, typeHash, "position");
PropertyMetadata meta{hash, 42, typeHash, "position", PropertyType::Vec3, now};
auto result = registry.registerProperty(meta);
// SECURITY: Validate on every update
PropertyValue 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 destroyed
auto removedHashes = registry.unregisterEntity(42);
~PropertyRegistry() =default
bool validateType(
PropertyHash hash,
PropertyType expectedType
) const

Validate 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)

Result< void > validatePropertyValue(
PropertyHash hash,
const PropertyValue & value
) const

Validate 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 applying
auto 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!
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)

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)

size_t size() const

Get total number of registered properties.

Return: Property count

@threadsafety Thread-safe (read lock)

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)

PropertyRegistry & operator=(
const PropertyRegistry &
) =delete
PropertyRegistry & operator=(
PropertyRegistry &&
) =delete
std::optional< PropertyMetadata > lookup(
PropertyHash hash
) const

Lookup property metadata by hash.

Parameters:

  • hash Property hash

Return: Optional metadata if found, nullopt otherwise

@threadsafety Thread-safe (read lock)

bool isRegistered(
PropertyHash hash
) const

Check if a property is registered.

Parameters:

  • hash Property hash

Return: true if registered, false otherwise

@threadsafety Thread-safe (read lock)

std::vector< PropertyHash > getEntityProperties(
uint64_t entityId
) const

Get 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)

std::vector< PropertyMetadata > getAllProperties() const

Get 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)

bool empty() const

Check if registry is empty.

Return: true if no properties registered

@threadsafety Thread-safe (read lock)

void clear()

Clear all registrations.

Removes all properties from the registry.

@threadsafety Thread-safe (write lock)

PropertyRegistry() =default
PropertyRegistry(
const PropertyRegistry &
) =delete
PropertyRegistry(
PropertyRegistry &&
) =delete
static size_t MAX_TOTAL_PROPERTIES = 1'000'000;
static size_t MAX_PROPERTIES_PER_ENTITY = 1000;
static size_t MAX_NAME_LENGTH = 256;

Updated on 2026-01-26 at 17:14:35 -0500