Commit 9ebe103a authored by Sven Liefgen's avatar Sven Liefgen
Browse files

Fixes

parent 2481de1f
Pipeline #4867 passed with stages
in 5 minutes and 45 seconds
......@@ -43,22 +43,36 @@ impl CodingConfiguration {
}
}
pub struct ParseCodingConfigurationError(String,);
type PCCE = ParseCodingConfigurationError;
use crate::defines::{K_START, N_START};
impl Default for CodingConfiguration {
fn default() -> Self {
Self::new(K_START, N_START, vec![N_START - K_START])
}
}
pub struct ParseCodingConfigurationError(&'static str);
use ParseCodingConfigurationError as PCCE;
impl FromStr for CodingConfiguration {
type Err = ParseCodingConfigurationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut cc = s.split(' ');
let k = cc.next().unwrap_or(PCCE("k not given")).parse().unrwap_or(PCCE("k not a number"))?;
let n = cc.next().unwrap_or(PCCE("n not given")).parse().unrwap_or(PCCE("n not a number"))?;
let n_cycle: Vec<_> = cc.map(|v| v.parse::<u8>().unwrap_or(PCCE("invalid token in cycle"))?).collect();
let k = cc
.next()
.ok_or(PCCE("k not given"))?
.parse()
.map_err(|_| PCCE("k not a number"))?;
let n = cc
.next()
.ok_or(PCCE("n not given"))?
.parse()
.map_err(|_| PCCE("n not a number"))?;
let n_cycle: Vec<_> = cc.map(|v| v.parse::<u8>().unwrap()).collect();
if n_cycle.iter().sum::<u8>() != n - k {
return ParseCodingConfigurationError("Cycle incorrect");
}
CodingConfiguration {
k, n, n_cycle
return Err(ParseCodingConfigurationError("Cycle incorrect"));
}
Ok(CodingConfiguration { k, n, n_cycle })
}
}
......@@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver as Queue, Sender};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant, SystemTime};
use std::time::{Duration, SystemTime};
use typenum::Bit;
use typenum::{False, True};
......@@ -28,7 +28,7 @@ use crate::block::Block;
use crate::channel_state_information::ChannelStateInformation;
use crate::coder::Coder;
use crate::coding_configuration::CodingConfiguration;
use crate::defines::{K_START, MAX_PAYLOAD_LENGTH, N_START, PACE_FILTER_LEN};
use crate::defines::{MAX_PAYLOAD_LENGTH, PACE_FILTER_LEN};
use crate::loss_statistics::LossStatistics;
use crate::pace::Pace;
use crate::packet::{
......@@ -310,15 +310,7 @@ impl<C: 'static + Coder> Socket<C> {
}
fn init_inner_socket(udp: RawSocket, socket: &mut Socket<C>) -> io::Result<InnerSocket<C>> {
let coding_configuration =
socket
.coding_configuration
.take()
.unwrap_or(CodingConfiguration::new(
K_START,
N_START,
vec![N_START - K_START],
));
let coding_configuration = socket.coding_configuration.take().unwrap_or_default();
Ok(InnerSocket {
socket: udp,
closing: AtomicBool::new(false),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment