mirror of
https://github.com/threefoldtech/mycelium.git
synced 2026-05-14 19:35:10 +00:00
Close #174: Reduce size field in datapacket header
Reduce the size from 19 to 16 bits Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Size of data packets is limited to 65535 bytes.
|
||||
|
||||
### Fixed
|
||||
|
||||
- The feasibility distance of an existing source key is no longer incorrectly updated
|
||||
|
||||
+5
-5
@@ -13,7 +13,7 @@ The packet header has a fixed size of 36 bytes, with the following layout:
|
||||
0 1 2 3
|
||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
|Reserved | Length | Hop Limit |
|
||||
| Reserved | Length | Hop Limit |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| |
|
||||
+ +
|
||||
@@ -33,11 +33,11 @@ The packet header has a fixed size of 36 bytes, with the following layout:
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
```
|
||||
|
||||
The first 5 bits are reserved and must be set to 0.
|
||||
The first 8 bits are reserved and must be set to 0.
|
||||
|
||||
The next 19 bits are used to specify the length of the body. It is expected that
|
||||
the actual length of a packet does not exceed 256K right now, so the 19th bit is
|
||||
only needed because we have to account for some overhead related to the encryption.
|
||||
The next 16 bits are used to specify the length of the body. It is expected that
|
||||
the actual length of a packet does not exceed 65K right now, and overhead related
|
||||
to encryption should be handled by the client before sending the packet.
|
||||
|
||||
The next byte is the hop-limit. Every node decrements this value by 1 before sending
|
||||
the packet. If a node decrements this value to 0, the packet is discarded.
|
||||
|
||||
+3
-4
@@ -7,7 +7,7 @@ use tokio_util::codec::{Decoder, Encoder};
|
||||
const DATA_PACKET_HEADER_SIZE: usize = 4;
|
||||
|
||||
/// Mask to extract data length from
|
||||
const DATA_PACKET_LEN_MASK: u32 = (1 << 19) - 1;
|
||||
const DATA_PACKET_LEN_MASK: u32 = (1 << 16) - 1;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DataPacket {
|
||||
@@ -27,8 +27,7 @@ pub struct Codec {
|
||||
/// Data from the DataPacket header.
|
||||
#[derive(Clone, Copy)]
|
||||
struct HeaderValues {
|
||||
// At most 19 bits atm but that can't be properly expressed.
|
||||
len: u32,
|
||||
len: u16,
|
||||
hop_limit: u8,
|
||||
}
|
||||
|
||||
@@ -59,7 +58,7 @@ impl Decoder for Codec {
|
||||
let raw_header = src.get_u32();
|
||||
// Hop limit is the last 8 bits.
|
||||
let hop_limit = (raw_header & 0xFF) as u8;
|
||||
let data_len = (raw_header >> 8) & DATA_PACKET_LEN_MASK;
|
||||
let data_len = ((raw_header >> 8) & DATA_PACKET_LEN_MASK) as u16;
|
||||
let header_vals = HeaderValues {
|
||||
len: data_len,
|
||||
hop_limit,
|
||||
|
||||
Reference in New Issue
Block a user