Skip to content

SubSocket: connection state hooks for publisher lifecycle events #209

Description

@Karrq

Problem

The SubSocket driver manages publisher connection state internally (Active/Inactive transitions, backoff retries, reconnection). These transitions are invisible to consumers - there's no way to react when a publisher disconnects or reconnects.

Proposal

Add a connection state hook to SubSocket, similar to the existing ConnectionHook. This hook would fire on publisher state transitions in the driver.

pub trait SubConnectionStateHook<A>: Send + Sync + 'static {
    fn on_connected(&self, addr: &A);
    fn on_reconnected(&self, addr: &A);
    fn on_disconnected(&self, addr: &A);
    fn on_terminated(&self, addr: &A);
}
let sub = SubSocket::new(transport)
    .with_connection_hook(attest_hook)
    .with_state_hook(my_state_hook);

The driver already has the information to fire these - the transitions happen in poll_publishers (Active → Inactive) and on_connection (Inactive → Active). Distinguishing on_connected from on_reconnected requires tracking whether a publisher was previously Active.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions