pub trait DaemonPlugin:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &'static str;
fn payload_kinds(&self) -> &'static [&'static str];
fn handle_payload<'life0, 'life1, 'async_trait>(
&'life0 self,
src: NodeId,
kind: &'life1 str,
body: Bytes,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn start<'async_trait>(
self: Arc<Self>,
ctx: PluginContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait;
fn on_peer_forgotten<'life0, 'async_trait>(
&'life0 self,
peer: NodeId,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
In-process plugin contract.
One instance per plugin per daemon. The daemon takes
Arc<dyn DaemonPlugin>, calls Self::start once, then routes
inbound payloads matching Self::payload_kinds through
Self::handle_payload. On clean shutdown, Self::shutdown is
called once.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable identifier — used for log spans and (by convention) as a prefix for the plugin’s payload kinds.
Sourcefn payload_kinds(&self) -> &'static [&'static str]
fn payload_kinds(&self) -> &'static [&'static str]
Stable list of PluginPayload.kind values this plugin claims.
The daemon dispatches inbound payloads by matching kind
against each registered plugin in order; the first match wins.
Sourcefn handle_payload<'life0, 'life1, 'async_trait>(
&'life0 self,
src: NodeId,
kind: &'life1 str,
body: Bytes,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle_payload<'life0, 'life1, 'async_trait>(
&'life0 self,
src: NodeId,
kind: &'life1 str,
body: Bytes,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Handle an inbound ControlFrame::PluginPayload whose kind
appeared in Self::payload_kinds.
Sourcefn start<'async_trait>(
self: Arc<Self>,
ctx: PluginContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
fn start<'async_trait>(
self: Arc<Self>,
ctx: PluginContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
Spawn whatever long-running tasks the plugin needs. Returns
once startup is complete; long-running work should be on
detached tokio::spawn handles tied to ctx.cancel.
Sourcefn on_peer_forgotten<'life0, 'async_trait>(
&'life0 self,
peer: NodeId,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_peer_forgotten<'life0, 'async_trait>(
&'life0 self,
peer: NodeId,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Notification: the daemon dropped this peer’s identity from the
keystore (e.g. via peers.forget). Plugins typically wipe any
per-peer state of their own here. Failure is logged but does
not block other plugins from being notified.