Peer Manager
Summary
The PeerManager
is the component of the system that knows about peers. It
has a Connector
to the ConnectionManager
and requests the creation and
removal of connections that are associated with a peer. The PeerManager
keeps track of reference counts of the peers, as well as metadata such as its
ID, a list of endpoints and which endpoint is currently active.
Dependencies
Sequence Diagrams
Connecting to a new Peer
The PeerManagerConnector
can be used by other components to request a
connection to a peer. For example, the AdminService
can request a connection
is created to a peer that is a member of a received circuit proposal.
- The Splinter REST API receives a circuit proposal that includes a peer that is not connected.
- The
AdminService
requests aPeerRef
for that peer using thePeerManagerConnector
. ThePeerRef
is held on to by theAdminService
. - The
PeerManager
requests a connection is created for the peer’s endpoint using the connection managerConnector
. - A
PeerRef
for the requested peer is returned from thePeerManagerConnector
. - The connection is successful and is passed to the
Authorizer
. - The peer completes authorization.
- After authorization the connection is passed to the
ConnectionMatrix
by theConnectionManager
by using theConnectionMatrixLifecycle
. - The
ConnectionManager
sends a Connected notification for the endpoint to the subscribers. - The
PeerManager
handles the notification by updating the peer’s status toPeerStatus::Connected
in thePeerMap
and sends a Connected notification for the peer to subscribers. - The
AdminService
receives the Connected notification. At this point the peer can be treated as connected. TheAdminService
can start sending messages to the peer with aNetworkSender
, starting with agreeing on the protocol version.
Reconnecting to Peer
The PeerManager
also monitors notifications from the ConnectionManager
. If a
connection disconnects, the PeerManager
will wait for a specified number of
reconnection attempts and if the connection does not reconnect the peers other
endpoints are tried. If successful, the peers active endpoint is replaced.
There is only ever one connection per peer active at a time.
Reconnecting to Peer’s active endpoint
-
ConnectionManager
sends a heartbeat message to its managed connections. - If the heartbeat fails, the failed connection’s state is set to reconnecting.
- The
ConnectionManager
sends a Disconnected endpoint notification to subscribers. - The
PeerManager
updates the associated peer’s status toPeerStatus::Disconnected
. - The
PeerManager
sends a Disconnected peer notification to subscribers. - The
AdminService
removes the peer’s agreed upon protocol version and resets any pending proposals that includes that peer. - The
ConnectionManager
retries to reconnect to the disconnected connection’s endpoint. - If the reconnection fails, the
ConnectionManager
sends a NonFatalConnectionError to subscribers with the number of failed attempts. - Once the connection is successful, the connection must reauthorize.
- The
ConnectionMatrix
updates the old connection. - The Connection Manager sends an endpoint Connected notification out to subscribers.
- The
PeerManager
updates the associated peer’s status toPeerStatus::Connected
. - The
PeerManager
sends a peer Connected notification to subscribers. - The
AdminService
can now send messages and restart protocol version agreement.
Reconnecting to peer with a new endpoint
-
ConnectionManager
sends a heartbeat to its managed connection. - If the heartbeat fails, the connection’s state is set to reconnecting.
- The
ConnectionManager
sends a disconnected endpoint notification to subscribers. - The
PeerManager
updates the associated peer’s status toPeerStatus::Disconnected
. - The
PeerManager
sends a disconnected peer notification to subscribers. - The
AdminService
removes the peers agreed upon protocol version and resets any pending proposal. - The
ConnectionManager
retries to reconnect to the disconnected connection’s endpoint - If the reconnection fails, the
ConnectionManager
sends NonFatalConnectionError to subscribers with the number of failed attempts. - Once the connection for a peer has reached the max number of retries and the
peer has other possible endpoint, the
PeerManager
will request a connection is created for a different endpoint. - The connection is successful and passed to the
Authorizers
. - The peer completes authorization.
- After authorization the connection is passed to the
ConnectionMatrix
. - A Connected notification is sent to subscribers for the endpoint.
- PeerManager handles the notification by updating the peer’s active endpoint
and status to
PeerStatus::Connected
in thePeerMap
. - The
PeerManager
requests that the peers old connection is removed. - The
PeerManager
sends a peer Connected notification to subscribers. - The
AdminService
can now send messages and restart protocol version agreement.