tweaks and checked arithmetic
This commit is contained in:
@@ -145,12 +145,21 @@ where
|
||||
let mut chunk_size = self.frame_size();
|
||||
|
||||
if input_options.routing_security() {
|
||||
chunk_size =
|
||||
chunk_size * self.nb_frames() - <Self as RoutingSecurity<_, _, _>>::OVERHEAD_SIZE;
|
||||
// SAFETY : While this CAN technically fail, it means that something is wrong in the code and it's pointless to continue anyway
|
||||
#[allow(clippy::expect_used)]
|
||||
let pre_security_chunk_size = (chunk_size * self.nb_frames())
|
||||
.checked_sub(<Self as RoutingSecurity<_, _, _>>::OVERHEAD_SIZE)
|
||||
.expect("not enough room in a packet for routing security overhead");
|
||||
chunk_size = pre_security_chunk_size;
|
||||
}
|
||||
|
||||
if input_options.reliability() {
|
||||
chunk_size -= <Self as Reliability<_, _, _>>::OVERHEAD_SIZE;
|
||||
// SAFETY : While this CAN technically fail, it means that something is wrong in the code and it's pointless to continue anyway
|
||||
#[allow(clippy::expect_used)]
|
||||
let pre_reliability_chunk_size = chunk_size
|
||||
.checked_sub(<Self as Reliability<_, _, _>>::OVERHEAD_SIZE)
|
||||
.expect("not enough room in a packet for reliability overhead");
|
||||
chunk_size = pre_reliability_chunk_size;
|
||||
}
|
||||
|
||||
chunk_size
|
||||
|
||||
@@ -121,12 +121,20 @@ where
|
||||
Ts: Clone,
|
||||
NdId: Clone,
|
||||
{
|
||||
// IMPORTANT NOTE : This fn can be not constant to allow e.g. flexible MTU
|
||||
// However, every possible value must be able to accomodate the different overhead.
|
||||
// If it doesn't, the pipeline becomes unusable
|
||||
fn packet_size(&self) -> usize;
|
||||
|
||||
fn frame_size(&self) -> usize {
|
||||
// SAFETY : While this CAN technically fail, it means that something is wrong in the code and it's pointless to continue anyway
|
||||
#[allow(clippy::expect_used)]
|
||||
self.packet_size()
|
||||
- <Self as Transport<Ts, Pkt, NdId>>::OVERHEAD_SIZE
|
||||
- <Self as Framing<Ts, Opts, NdId>>::OVERHEAD_SIZE
|
||||
.checked_sub(
|
||||
<Self as Transport<Ts, Pkt, NdId>>::OVERHEAD_SIZE
|
||||
+ <Self as Framing<Ts, Opts, NdId>>::OVERHEAD_SIZE,
|
||||
)
|
||||
.expect("packet_size smaller than transport + framing overhead")
|
||||
}
|
||||
|
||||
fn wire_wrap(
|
||||
|
||||
@@ -38,6 +38,7 @@ pub type PipelinePayload<Ts, Opts, NdId> = PipelineData<Ts, Vec<u8>, Opts, NdId>
|
||||
/// pipeline. It is produced by [`clients::traits::Chunking`] and propagated
|
||||
/// unchanged (or with the timestamp transformed) through every subsequent
|
||||
/// pipeline stage until the packet is sent on the wire.
|
||||
#[derive(Clone)]
|
||||
pub struct TimedData<Ts, D> {
|
||||
pub timestamp: Ts,
|
||||
pub data: D,
|
||||
@@ -108,6 +109,7 @@ impl<Ts, D> TimedData<Ts, D> {
|
||||
/// [`Framing`]: crate::common::traits::Framing
|
||||
/// [`Transport`]: crate::common::traits::Transport
|
||||
/// [`InputOptions`]: crate::clients::InputOptions
|
||||
#[derive(Clone)]
|
||||
pub struct PipelineData<Ts, D, Opts, NdId> {
|
||||
pub data: TimedData<Ts, D>,
|
||||
pub options: Opts,
|
||||
|
||||
@@ -33,7 +33,7 @@ cargo run --bin mix-client -- --src 6 --dst 7
|
||||
|
||||
Generates a `topology.json` file describing nodes and clients.
|
||||
|
||||
```
|
||||
```bash
|
||||
cargo run --bin nym-mix-sim -- init-topology [OPTIONS]
|
||||
```
|
||||
|
||||
@@ -49,7 +49,7 @@ Nodes are assigned sequential ports starting at `127.0.0.1:9000`. Clients get tw
|
||||
|
||||
Starts the simulation loop.
|
||||
|
||||
```
|
||||
```bash
|
||||
cargo run --bin nym-mix-sim -- run [OPTIONS]
|
||||
```
|
||||
|
||||
@@ -65,7 +65,7 @@ cargo run --bin nym-mix-sim -- run [OPTIONS]
|
||||
|
||||
Injects messages into a running simulation from stdin.
|
||||
|
||||
```
|
||||
```bash
|
||||
cargo run --bin mix-client -- --src <ID> --dst <ID> [--topology <PATH>]
|
||||
```
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ impl Directory {
|
||||
/// Look up a client by its [`ClientId`].
|
||||
///
|
||||
/// Returns `None` when `id` is not present in the directory
|
||||
pub fn client(&self, id: NodeId) -> Option<&SocketAddr> {
|
||||
pub fn client(&self, id: ClientId) -> Option<&SocketAddr> {
|
||||
self.clients.get(&id)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user