Skip to content

Commit c94e82e

Browse files
committed
Add timestamp to MQTT UDP packet
1 parent f633424 commit c94e82e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

main/protocols/mqtt_protocol.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void MqttProtocol::SendAudio(const AudioStreamPacket& packet) {
129129

130130
std::string nonce(aes_nonce_);
131131
*(uint16_t*)&nonce[2] = htons(packet.payload.size());
132+
*(uint32_t*)&nonce[8] = htonl(packet.timestamp);
132133
*(uint32_t*)&nonce[12] = htonl(++local_sequence_);
133134

134135
std::string encrypted;
@@ -220,6 +221,7 @@ bool MqttProtocol::OpenAudioChannel() {
220221
ESP_LOGE(TAG, "Invalid audio packet type: %x", data[0]);
221222
return;
222223
}
224+
uint32_t timestamp = ntohl(*(uint32_t*)&data[8]);
223225
uint32_t sequence = ntohl(*(uint32_t*)&data[12]);
224226
if (sequence < remote_sequence_) {
225227
ESP_LOGW(TAG, "Received audio packet with old sequence: %lu, expected: %lu", sequence, remote_sequence_);
@@ -235,6 +237,7 @@ bool MqttProtocol::OpenAudioChannel() {
235237
auto nonce = (uint8_t*)data.data();
236238
auto encrypted = (uint8_t*)data.data() + aes_nonce_.size();
237239
AudioStreamPacket packet;
240+
packet.timestamp = timestamp;
238241
packet.payload.resize(decrypted_size);
239242
int ret = mbedtls_aes_crypt_ctr(&aes_ctx_, decrypted_size, &nc_off, nonce, stream_block, encrypted, (uint8_t*)packet.payload.data());
240243
if (ret != 0) {

0 commit comments

Comments
 (0)