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
AdminServicerequests aPeerReffor that peer using thePeerManagerConnector. ThePeerRefis held on to by theAdminService. - The
PeerManagerrequests a connection is created for the peer’s endpoint using the connection managerConnector. - A
PeerReffor 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
ConnectionMatrixby theConnectionManagerby using theConnectionMatrixLifecycle. - The
ConnectionManagersends a Connected notification for the endpoint to the subscribers. - The
PeerManagerhandles the notification by updating the peer’s status toPeerStatus::Connectedin thePeerMapand sends a Connected notification for the peer to subscribers. - The
AdminServicereceives the Connected notification. At this point the peer can be treated as connected. TheAdminServicecan 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
-
ConnectionManagersends a heartbeat message to its managed connections. - If the heartbeat fails, the failed connection’s state is set to reconnecting.
- The
ConnectionManagersends a Disconnected endpoint notification to subscribers. - The
PeerManagerupdates the associated peer’s status toPeerStatus::Disconnected. - The
PeerManagersends a Disconnected peer notification to subscribers. - The
AdminServiceremoves the peer’s agreed upon protocol version and resets any pending proposals that includes that peer. - The
ConnectionManagerretries to reconnect to the disconnected connection’s endpoint. - If the reconnection fails, the
ConnectionManagersends a NonFatalConnectionError to subscribers with the number of failed attempts. - Once the connection is successful, the connection must reauthorize.
- The
ConnectionMatrixupdates the old connection. - The Connection Manager sends an endpoint Connected notification out to subscribers.
- The
PeerManagerupdates the associated peer’s status toPeerStatus::Connected. - The
PeerManagersends a peer Connected notification to subscribers. - The
AdminServicecan now send messages and restart protocol version agreement.
Reconnecting to peer with a new endpoint
-
ConnectionManagersends a heartbeat to its managed connection. - If the heartbeat fails, the connection’s state is set to reconnecting.
- The
ConnectionManagersends a disconnected endpoint notification to subscribers. - The
PeerManagerupdates the associated peer’s status toPeerStatus::Disconnected. - The
PeerManagersends a disconnected peer notification to subscribers. - The
AdminServiceremoves the peers agreed upon protocol version and resets any pending proposal. - The
ConnectionManagerretries to reconnect to the disconnected connection’s endpoint - If the reconnection fails, the
ConnectionManagersends 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
PeerManagerwill 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::Connectedin thePeerMap. - The
PeerManagerrequests that the peers old connection is removed. - The
PeerManagersends a peer Connected notification to subscribers. - The
AdminServicecan now send messages and restart protocol version agreement.