Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing configuration point shipper_throttle_packet_delay_ms #87

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Config {
//0 = OFF (don't run GC)
//Default is 10000 (10 seconds)
pub gc_period_ms: u32,
pub shipper_throttle_packet_delay_ms: u32,
}

impl Default for Config {
Expand All @@ -61,6 +62,7 @@ impl Default for Config {
watched_directory: None,
disk_usage: 1024 * 1024,
gc_period_ms: 10_000,
shipper_throttle_packet_delay_ms: 0,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions myceli/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ impl<T: Transport + Send + 'static> Listener<T> {
shipper_timeout_duration: u64,
shipper_window_size: u32,
block_size: u32,
shipper_packet_delay_ms: u32,
) -> Result<()> {
// First setup the shipper and its pieces
let (shipper_sender, shipper_receiver) = mpsc::channel();
Expand All @@ -67,6 +68,7 @@ impl<T: Transport + Send + 'static> Listener<T> {
initial_connected,
block_size,
shipper_radio,
shipper_packet_delay_ms
)
.expect("Shipper creation failed");
shipper.receive_msg_loop();
Expand Down
2 changes: 1 addition & 1 deletion myceli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() -> Result<()> {
.expect("Listener creation failed");
println!("pid={}", std::process::id());
listener
.start(cfg.retry_timeout_duration, cfg.window_size, cfg.block_size)
.start(cfg.retry_timeout_duration, cfg.window_size, cfg.block_size,cfg.shipper_throttle_packet_delay_ms)
.expect("Error encountered in listener operation");
Ok(())
}
8 changes: 8 additions & 0 deletions myceli/src/shipper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Shipper<T> {
connected: Arc<Mutex<bool>>,
// Radio address
radio_address: Option<String>,
packet_delay_ms: u32,
}

impl<T: Transport + Send + 'static> Shipper<T> {
Expand All @@ -67,6 +68,7 @@ impl<T: Transport + Send + 'static> Shipper<T> {
connected: Arc<Mutex<bool>>,
block_size: u32,
radio_address: Option<String>,
packet_delay_ms: u32,
) -> Result<Shipper<T>> {
let storage = Storage::new(storage_provider, block_size);
Ok(Shipper {
Expand All @@ -79,6 +81,7 @@ impl<T: Transport + Send + 'static> Shipper<T> {
transport,
connected,
radio_address,
packet_delay_ms,
})
}

Expand Down Expand Up @@ -367,6 +370,9 @@ impl<T: Transport + Send + 'static> Shipper<T> {

info!("Transmitting {msg:?} to {_resolved_target_addr}");
self.transport.send(msg, target_addr)?;
if self.packet_delay_ms > 0 {
std::thread::sleep(Duration::from_millis(self.packet_delay_ms.into()));
}
Ok(())
}

Expand All @@ -382,6 +388,7 @@ impl<T: Transport + Send + 'static> Shipper<T> {
block.cid.to_string()
);
self.transmit_msg(Message::data_block(transmission), target_addr)?;

}

Ok(())
Expand Down Expand Up @@ -517,6 +524,7 @@ mod tests {
Arc::new(Mutex::new(true)),
BLOCK_SIZE,
None,
0
)
.unwrap();
TestShipper {
Expand Down
2 changes: 1 addition & 1 deletion myceli/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn start_listener_thread(listen_addr: SocketAddr, db_path: ChildPath) {
let mut listener =
Listener::new(&listen_addr, db_path, transport, BLOCK_SIZE, None, 9).unwrap();
listener
.start(10, 2, BLOCK_SIZE)
.start(10, 2, BLOCK_SIZE, 0)
.expect("Error encountered in listener");
}

Expand Down