enum PeerState {
None,
Connected(CancellationToken),
Reconnect(Peer),
Replace(Connection),
}Expand description
The states of a peer.
When a party is created there exists no peer yet. After a connection has
been accepted or a connect attempt succeeded, a peer task is created and
the state transitions to Connected. The cancellation token is used if
the peer task should stop in order to replace the peer’s connection. When
cancelled the next connection is stored in Replace and once the peer
task finishes and returns the peer, its connection is set and a new peer
task (with the same peer object) is spawned and the state transitions to
Connected again.
The Reconnect state is entered if the peer itself errors and its task
finishes. We keep the peer here until we have a new connection to resume.
Once a connect or accept task finishes we set the connection and spawn
a new peer task again.
Variants§
None
Initial state.
Connected(CancellationToken)
A peer task is running.
The cancellation token can be used to interrupt the peer. The task will end and the peer object is returned.
Reconnect(Peer)
A peer has errored and wants a fresh connection.
We store the peer here until a new connection is available.
Replace(Connection)
The server wants to replace a peer’s connection.
Only entered from Connected after the server has cancelled the
peer task. While waiting for the task to return the peer object
we park the connection here.