Module PocketMeshPeer.PeersConnections

Manages P2P connections and their state.

type t;
type connectionState;

Opaque variant type used internally to represent the current connection state. Use classifyConnectionState to get something to pattern-match on.

type taggedConnectionState =
| InitiatingConnection

Local peer in the role of initiator is trying to establish P2P connection with the peer and/or is waiting for its response.

| AcceptingConnection

Local peer has responded to the initiator and now is waiting for the other peer to finish the connection procedure.

| Connected

P2P connection is established.


Simplified representation of P2P connection state ideal for pattern-matching.

let classifyConnectionState: connectionState => taggedConnectionState;

Converts opaque internal representation of the P2P connection state into the simplified type suitable for pattern-matching.

let getPeerConnectionState: Peer.Id.t => t => option(connectionState);

getPeerConnectionState(p, t) returns state of P2P connection for a peer with ID p or returns None if there is no initiative to connect to p.

let fold: ('acc => Peer.Id.t => taggedConnectionState => 'acc) => 'acc => t => 'acc;

fold(f, acc, t) can be used to iterate through all peers with P2P connection initiative and accumulate a value with a starting value of acc.