The project provides a helper class for detection and notification about lost unreliable packets. This is an important part of many advanced synchronization strategies. For example, Eventual Consistency uses it.
For simplicity, the server supports only one client.
| Overview |
|---|
Detection works by adding that header to each sent packet:
ushort Local Sequence Idushort Last Remote Sequence Iduint Bitmask for a 32 previous remote sequence IdsThe workflow is like that:
AddPeer in helperAddHeaderForPeerIdEnqueueDataReadHeaderOfPeerId with itExecuteLostPacketsClearHeaderRemovePeerIf packet is considered as Lost it means that it was most likely lost. When packet is considered as Arrived, then it is arrived for sure.
ILossHandler.OnPacketLost will be called for each lost packet AND for each packet which was enqueued and still tracked when that peer got disconnected.
If LOSS_DETECTOR_DEBUG symbol is present, then all lost packet sequences will be outputted to the logger.
ILossHandler handler, ushort maxPeerCount, ushort ackWindow) - That implementation of ILossHandler will be called for each lost packet. MaxPeerCount - Max count of peers connected to that peer. AckWindow - Max count of local tracked packets per peer.ushort peerId) - Clears sequence number for that peerId.ushort peerId) - Enqueues each tracked packet for that peerId as being lost.ushort peerId, BitBuffer data) - Writes header information into BitBuffer for that peerId.ushort peerId, BitBuffer data) - Reads header from BitBuffer and detects if any tracked packet is ACKed or NACKed. In the case of ACK detector will free allocated memory. Returns True if sequenceId is greater than lastSequenceId for that peerId.ushort peerId, PacketData data) - Tries to put data into tracked packet queue for that peer. Returns False if the queue is already full. Probably you have not received packets from another peer for too long and should disconnect him.BitBuffer data) - Clears header from BitBuffer.If LOSS_DETECTOR_DEBUG symbol is present, then those methods are available too:
StringBuilder builder) - Writes full state of buffers for each peerId into StringBuilder.ushort peerId, StringBuilder builder) - Writes state of buffers for that peerId.Helper itself is transport-agnostic, but example project uses ENet
fholm - The Master of Networking - has helped a lot.