aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/wire.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/wire.rs')
-rw-r--r--src/transport/wire.rs39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/transport/wire.rs b/src/transport/wire.rs
index 00bc739..3daba0d 100644
--- a/src/transport/wire.rs
+++ b/src/transport/wire.rs
@@ -14,7 +14,7 @@ use super::{EncodedMessage, MessageKind, ParsedMessage};
/// The wire format's version, the first byte of every payload. Bump it with every change
/// to a message type or a codec (`golden_bytes` fails then).
-pub(crate) const VERSION: u8 = 11;
+pub(crate) const VERSION: u8 = 12;
/// What the second byte of a payload says.
fn tag(kind: MessageKind) -> u8 {
@@ -81,9 +81,8 @@ pub(crate) fn encode(message: &ParsedMessage) -> Result<Vec<u8>, WireError> {
ParsedMessage::Who(proof) | ParsedMessage::Me(proof) => {
rmp_serde::encode::write(&mut payload, proof)?
}
- ParsedMessage::Ping(nonce) | ParsedMessage::Pong(nonce) => {
- rmp_serde::encode::write(&mut payload, nonce)?
- }
+ ParsedMessage::Ping(nonce) => rmp_serde::encode::write(&mut payload, nonce)?,
+ ParsedMessage::Pong { nonce, at } => rmp_serde::encode::write(&mut payload, &(nonce, at))?,
ParsedMessage::Links(request) => rmp_serde::encode::write(&mut payload, request)?,
ParsedMessage::LinksReply(reply) => rmp_serde::encode::write(&mut payload, reply)?,
}
@@ -117,7 +116,8 @@ pub(crate) fn decode(payload: &[u8]) -> Result<ParsedMessage, WireError> {
} else if is(MessageKind::Ping) {
ParsedMessage::Ping(rmp_serde::from_slice(body)?)
} else if is(MessageKind::Pong) {
- ParsedMessage::Pong(rmp_serde::from_slice(body)?)
+ let (nonce, at) = rmp_serde::from_slice(body)?;
+ ParsedMessage::Pong { nonce, at }
} else if is(MessageKind::Links) {
ParsedMessage::Links(rmp_serde::from_slice(body)?)
} else if is(MessageKind::LinksReply) {
@@ -419,7 +419,10 @@ pub(crate) fn samples() -> Vec<ParsedMessage> {
ParsedMessage::Who(proof.clone()),
ParsedMessage::Me(proof),
ParsedMessage::Ping(7),
- ParsedMessage::Pong(u64::MAX),
+ ParsedMessage::Pong {
+ nonce: u64::MAX,
+ at: crate::clock::UnixMillis(5),
+ },
ParsedMessage::Links(crate::transport::LinksRequest {
epoch,
epoch_seq: 1,
@@ -615,7 +618,7 @@ mod tests {
});
assert_eq!(
hex(&encode(&hello).unwrap()),
- format!("0b0097a5737761726d{epoch_hex}01c403010203c3{}07", run("04"))
+ format!("0c0097a5737761726d{epoch_hex}01c403010203c3{}07", run("04"))
);
let reply = ParsedMessage::HelloReply(HelloReply {
@@ -635,7 +638,7 @@ mod tests {
assert_eq!(
hex(&encode(&reply).unwrap()),
format!(
- "0b0199a5737761726d9192a17091a161{epoch_hex}01c400c2{}05{}",
+ "0c0199a5737761726d9192a17091a161{epoch_hex}01c400c2{}05{}",
run("04"),
run("06")
)
@@ -651,7 +654,7 @@ mod tests {
});
assert_eq!(
hex(&encode(&status).unwrap()),
- format!("0b03969290c400{epoch_hex}01c3c2c2")
+ format!("0c03969290c400{epoch_hex}01c3c2c2")
);
let who = ParsedMessage::Who(IdentityProof {
@@ -660,7 +663,7 @@ mod tests {
});
assert_eq!(
hex(&encode(&who).unwrap()),
- format!("0b0692c420{}c440{}", "08".repeat(32), "09".repeat(64))
+ format!("0c0692c420{}c440{}", "08".repeat(32), "09".repeat(64))
);
let ParsedMessage::Me(proof) = decode(
&encode(&ParsedMessage::Me(IdentityProof {
@@ -674,14 +677,16 @@ mod tests {
};
assert_eq!((proof.key, proof.signature), ([8; 32], [9; 64]));
- assert_eq!(hex(&encode(&ParsedMessage::Ping(7)).unwrap()), "0b0807");
- assert_eq!(
- hex(&encode(&ParsedMessage::Pong(u64::MAX)).unwrap()),
- "0b09cfffffffffffffffff"
- );
- let ParsedMessage::Pong(nonce) = decode(&[VERSION, 9, 0x2a]).unwrap() else {
+ assert_eq!(hex(&encode(&ParsedMessage::Ping(7)).unwrap()), "0c0807");
+ let pong = ParsedMessage::Pong {
+ nonce: u64::MAX,
+ at: crate::clock::UnixMillis(5),
+ };
+ assert_eq!(hex(&encode(&pong).unwrap()), "0c0992cfffffffffffffffff05");
+ let ParsedMessage::Pong { nonce, at } = decode(&[VERSION, 9, 0x92, 0x2a, 0x07]).unwrap()
+ else {
panic!("not a PONG");
};
- assert_eq!(nonce, 42);
+ assert_eq!((nonce, at.as_u64()), (42, 7));
}
}