# 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 `NetworkPlugin` for 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 ```ts import { RegistryPlugin } from "@suaveplan/network-plugin-registry"; const plugin = new RegistryPlugin(32); node.use(plugin); ``` ### Advanced Example ```ts 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 identifier - `registry: Registry` — peer registry - `encoder: BinaryMessageEncoder` — binary encoder - `install(node)` — wire sync manager to bus - `start()` — begin periodic sync - `stop()` — stop periodic sync - `dispose()` — 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.