Skip to content

Commit

Permalink
add congestion ctrl params to conn config (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkaufmann authored Mar 21, 2023
1 parent f22f0c3 commit e0ba703
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "utp-rs"
version = "0.1.0-alpha.1"
version = "0.1.0-alpha.2"
edition = "2021"
authors = ["Jacob Kaufmann"]
description = "uTorrent transport protocol"
Expand Down
8 changes: 4 additions & 4 deletions src/congestion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use std::cmp;
use std::collections::{BinaryHeap, HashMap};
use std::time::{Duration, Instant};

const DEFAULT_TARGET_MICROS: u32 = 100_000;
const DEFAULT_INITIAL_TIMEOUT: Duration = Duration::from_secs(1);
const DEFAULT_MIN_TIMEOUT: Duration = Duration::from_millis(500);
const DEFAULT_MAX_PACKET_SIZE_BYTES: u32 = 2048;
pub(crate) const DEFAULT_TARGET_MICROS: u32 = 100_000;
pub(crate) const DEFAULT_INITIAL_TIMEOUT: Duration = Duration::from_secs(1);
pub(crate) const DEFAULT_MIN_TIMEOUT: Duration = Duration::from_millis(500);
pub(crate) const DEFAULT_MAX_PACKET_SIZE_BYTES: u32 = 1024;
const DEFAULT_GAIN: f32 = 1.0;
const DEFAULT_DELAY_WINDOW: Duration = Duration::from_secs(120);

Expand Down
11 changes: 9 additions & 2 deletions src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ pub struct ConnectionConfig {
pub max_conn_attempts: usize,
pub max_idle_timeout: Duration,
pub initial_timeout: Duration,
pub min_timeout: Duration,
pub target_delay: Duration,
}

impl Default for ConnectionConfig {
fn default() -> Self {
Self {
max_packet_size: 1024,
max_conn_attempts: 3,
max_idle_timeout: Duration::from_secs(10),
initial_timeout: Duration::from_millis(500),
max_packet_size: congestion::DEFAULT_MAX_PACKET_SIZE_BYTES as u16,
initial_timeout: congestion::DEFAULT_INITIAL_TIMEOUT,
min_timeout: congestion::DEFAULT_MIN_TIMEOUT,
target_delay: Duration::from_micros(congestion::DEFAULT_TARGET_MICROS.into()),
}
}
}
Expand All @@ -91,6 +95,9 @@ impl From<ConnectionConfig> for congestion::Config {
fn from(value: ConnectionConfig) -> Self {
Self {
max_packet_size_bytes: u32::from(value.max_packet_size),
initial_timeout: value.initial_timeout,
min_timeout: value.min_timeout,
target_delay_micros: value.target_delay.as_micros() as u32,
..Default::default()
}
}
Expand Down

0 comments on commit e0ba703

Please sign in to comment.