diff --git a/core/archipelago/src/mesh/protocol.rs b/core/archipelago/src/mesh/protocol.rs index 9df5cc28..ccb23835 100644 --- a/core/archipelago/src/mesh/protocol.rs +++ b/core/archipelago/src/mesh/protocol.rs @@ -222,6 +222,10 @@ pub fn build_send_text(dest_pubkey_prefix: &[u8; 6], msg: &[u8]) -> Result Result> { if msg.len() > MAX_MESSAGE_LEN { anyhow::bail!( @@ -230,7 +234,12 @@ pub fn build_send_channel_text(channel: u8, msg: &[u8]) -> Result> { MAX_MESSAGE_LEN ); } - let mut data = vec![CMD_SEND_CHANNEL_TXT_MSG, channel]; + let timestamp = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_secs() as u32) + .unwrap_or(0); + let mut data = vec![CMD_SEND_CHANNEL_TXT_MSG, 0x00, channel]; + data.extend_from_slice(×tamp.to_le_bytes()); data.extend_from_slice(msg); Ok(encode_frame(&data)) } @@ -697,10 +706,13 @@ mod tests { #[test] fn test_build_send_channel_text() -> Result<()> { - let frame = build_send_channel_text(0, b"test")?; + let frame = build_send_channel_text(2, b"test")?; + // Frame: [marker][len_lo][len_hi][cmd][txt_type][channel][ts(4)][text] assert_eq!(frame[3], CMD_SEND_CHANNEL_TXT_MSG); - assert_eq!(frame[4], 0); // channel 0 - assert_eq!(&frame[5..], b"test"); + assert_eq!(frame[4], 0); // txt_type + assert_eq!(frame[5], 2); // channel idx + // frame[6..10] = timestamp, non-deterministic + assert_eq!(&frame[10..], b"test"); Ok(()) }