bidirectional ip reflection for listener address discovery
This commit is contained in:
@@ -1166,12 +1166,27 @@ pub const NetworkManager = struct {
|
||||
// Free the encrypted data, keep decrypted
|
||||
self.allocator.free(msg_data);
|
||||
|
||||
// Create properly sized slice (plaintext is a slice into decrypt_buf)
|
||||
const decrypted = self.allocator.alloc(u8, plaintext.len) catch {
|
||||
// FIX: The sender includes a 4-byte length header in the plaintext (for
|
||||
// non-encrypted framing compatibility). Strip it here since ReceiveBuffer
|
||||
// already handles framing for the encrypted packet.
|
||||
if (plaintext.len < 4) {
|
||||
self.allocator.free(decrypt_buf);
|
||||
continue;
|
||||
}
|
||||
const inner_len = std.mem.readInt(u32, plaintext[0..4], .big);
|
||||
if (inner_len > plaintext.len - 4) {
|
||||
std.log.warn("Decrypted message inner length mismatch: {} > {}", .{ inner_len, plaintext.len - 4 });
|
||||
self.allocator.free(decrypt_buf);
|
||||
continue;
|
||||
}
|
||||
const payload = plaintext[4 .. 4 + inner_len];
|
||||
|
||||
// Create properly sized slice
|
||||
const decrypted = self.allocator.alloc(u8, payload.len) catch {
|
||||
self.allocator.free(decrypt_buf);
|
||||
continue;
|
||||
};
|
||||
@memcpy(decrypted, plaintext);
|
||||
@memcpy(decrypted, payload);
|
||||
self.allocator.free(decrypt_buf);
|
||||
|
||||
break :blk decrypted;
|
||||
|
||||
Reference in New Issue
Block a user