Closed johanhelsing closed 1 year ago
Sending a checksum as part of any existing package (or a new one) and tracking/comparing received checksums with own checksums should neither be a big burden on network traffic nor require a lot of code changes. The biggest question for me is how to go about sending them, as messages are unreliable. Would it be enough to just get sporadic comparisons or do we want to compare every frame?
Sporadic checksums would probably be fine for my use-case. It would probably go a long way to to just print out the first known bad and the last known good frames.
We're adding options for configuring reliable channels in matchbox as well, so it would be possible to run it in reliable mode for debugging desync issues.
A first idea could look something like this:
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub(crate) struct ChecksumReport {
pub checksum: u32, // or whatever datatype we deem suitable
pub frame: Frame, // this is just a i32
}
Each endpoint could keep a history of recent checksums (like a Hashmap<Frame, u32>
or some queue) and then compare received checksums (sporadic) against their history (complete). In case of a detected desync, we send a GGRSEvent
out to the user that can be handled however they wish.
This way the clients are not guaranteed to agree on a detected mismatch, it might just be one client that detects it. But since this feature is probably just for debugging, this could be "good enough" already. The clients don't have to agree on the mismatch, as long as they properly disconnect from the session if they stop participating.
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
As a starting point, it would be good if there was an option on the p2p session similar to that on synctest session, that took checksums of the state and sent it to the other peers so they could compare.
Describe alternatives you've considered
Workaround: Implementing a checksum in game code and include it as part of the input struct.
Or: Just hope desyncs won't happen.
Additional context
Suggested by @Vrixyz :)