2.0 KiB
RegistryPlugin
Purpose
Integrates the registry system into a NetworkNode. RegistryPlugin implements NetworkPlugin and wires together the Registry, BinaryMessageEncoder, and RegistrySyncManager as a single cohesive unit. This plugin is the recommended way to add peer-registry capabilities to a node because it handles lifecycle ordering automatically.
Features
- Implements
NetworkPluginfor automatic lifecycle management - Exposes registry and encoder as public readonly properties
- Automatic sync management via node lifecycle hooks
- Configurable capacity at construction time
- Clean shutdown via
dispose() - Zero external dependencies beyond the network package
Usage
Basic Example
import { RegistryPlugin } from "@suaveplan/network-plugin-registry";
const plugin = new RegistryPlugin(32);
node.use(plugin);
Advanced Example
import { RegistryPlugin } from "@suaveplan/network-plugin-registry";
const plugin = new RegistryPlugin(16);
node.use(plugin);
plugin.registry.add(peer);
const bytes = plugin.encoder.encode(peer);
API Reference
name: "registry"— plugin identifierregistry: Registry— peer registryencoder: BinaryMessageEncoder— binary encoderinstall(node)— wire sync manager to busstart()— begin periodic syncstop()— stop periodic syncdispose()— clear registry and release sync manager
Implementation Notes
The plugin creates the registry and encoder eagerly in the constructor so they are immediately available for inspection or manual mutation before the node is started. The sync manager is created lazily during install() when the node (and its bus) becomes available. This separation allows tests to construct and exercise the registry without needing a full NetworkNode. Disposing the plugin clears all registry state and drops the sync manager reference, which is important for clean shutdown and test isolation. The plugin never restarts automatically after disposal; a new instance must be created if registry functionality is needed again.