Skip to content

Commit

Permalink
fix: apply Autocrypt headers if timestamp is unchanged
Browse files Browse the repository at this point in the history
If two messages arrive with the same timestamp,
the one that arrived later should be preferred.
  • Loading branch information
link2xt committed Feb 20, 2024
1 parent 06e79e8 commit b4e9a97
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/peerstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl Peerstate {
return;
}

if message_time > self.last_seen {
if message_time >= self.last_seen {
self.last_seen = message_time;
self.last_seen_autocrypt = message_time;
if (header.prefer_encrypt == EncryptPreference::Mutual
Expand All @@ -360,7 +360,7 @@ impl Peerstate {
return;
}

if message_time > self.gossip_timestamp {
if message_time >= self.gossip_timestamp {
self.gossip_timestamp = message_time;
if self.gossip_key.as_ref() != Some(&gossip_header.public_key) {
self.gossip_key = Some(gossip_header.public_key.clone());
Expand Down Expand Up @@ -995,7 +995,7 @@ mod tests {
assert_eq!(peerstate.prefer_encrypt, EncryptPreference::Reset);

// Same header will be applied in the future.
peerstate.apply_header(&header, 400);
peerstate.apply_header(&header, 300);
assert_eq!(peerstate.prefer_encrypt, EncryptPreference::Mutual);
}
}

0 comments on commit b4e9a97

Please sign in to comment.