pub fn retransmit_tcp(
        &mut self,
        dst: SocketAddrV4,
        src: SocketAddrV4,
        sacks: Option<Vec<(u32, u32)>>,
    ) -> io::Result<()> {
        let state = self
            .get_state_mut(dst, src)
            .ok_or(io::Error::from(io::ErrorKind::NotFound))?;
        let sequence = state.cache().sequence();
        let recv_next = state.cache().recv_next();

        // Congestion control
        if let Some(cc) = &mut state.cc_mut() {
            cc.fast_retransmission();
        }

        // Find all disjointed ranges
        let mut ranges = Vec::new();
        ranges.push((sequence, recv_next));
        if let Some(sacks) = sacks {
            for sack in sacks {
                let mut temp_ranges = Vec::new();

                for range in ranges {
                    for temp_range in disjoint_u32_range(range, sack) {
                        temp_ranges.push(temp_range);
                    }
                }

                ranges = temp_ranges;
            }
        }
        let ranges = ranges;

        // Retransmit
        for range in &ranges {
            let size = range
                .1
                .checked_sub(range.0)
                .unwrap_or_else(|| range.1 + (u32::MAX - range.0)) as usize;
            let state = self
                .get_state(dst, src)
                .ok_or(io::Error::from(io::ErrorKind::NotFound))?;
            let payload = state.cache().get(range.0, size)?;
            if payload.len() > 0 {
                if range.1 == recv_next && state.cache_fin().is_some() {
                    // ACK/FIN
                    trace!(
                        "retransmit TCP ACK/FIN ({} Bytes) {} -> {} from {}",
                        payload.len(),
                        dst,
                        src,
                        sequence
                    );

                    // Send
                    self.send_tcp_ack(dst, src, range.0, payload.as_slice(), true)?;
                } else {
                    // ACK
                    trace!(
                        "retransmit TCP ACK ({} Bytes) {} -> {} from {}",
                        payload.len(),
                        dst,
                        src,
                        sequence
                    );

                    // Send
                    self.send_tcp_ack(dst, src, range.0, payload.as_slice(), false)?;
                }
            }
        }

        // Pure FIN
        let state = self
            .get_state(dst, src)
            .ok_or(io::Error::from(io::ErrorKind::NotFound))?;
        if ranges.len() == 0 && state.cache_fin().is_some() {
            // FIN
            trace!("retransmit TCP FIN {} -> {}", dst, src);

            // Send
            self.send_tcp_fin(dst, src)?;
        }

        Ok(())
    }
/// Retransmits TCP packets from the cache. This method is used for fast retransmission.
Retransmits TCP packets from the cache. This method is used for fast retransmission.
Retransmits TCP packets from the cache . This method is used for fast retransmission .
pub fn retransmit_tcp(
        &mut self,
        dst: SocketAddrV4,
        src: SocketAddrV4,
        sacks: Option<Vec<(u32, u32)>>,
    ) -> io::Result<()> {
        let state = self
            .get_state_mut(dst, src)
            .ok_or(io::Error::from(io::ErrorKind::NotFound))?;
        let sequence = state.cache().sequence();
        let recv_next = state.cache().recv_next();
        // Congestion control
        if let Some(cc) = &mut state.cc_mut() {
            cc.fast_retransmission();
        }
        // Find all disjointed ranges
        let mut ranges = Vec::new();
        ranges.push((sequence, recv_next));
        if let Some(sacks) = sacks {
            for sack in sacks {
                let mut temp_ranges = Vec::new();
                for range in ranges {
                    for temp_range in disjoint_u32_range(range, sack) {
                        temp_ranges.push(temp_range);
                    }
                }
                ranges = temp_ranges;
            }
        }
        let ranges = ranges;
        // Retransmit
        for range in &ranges {
            let size = range
                .1
                .checked_sub(range.0)
                .unwrap_or_else(|| range.1 + (u32::MAX - range.0)) as usize;
            let state = self
                .get_state(dst, src)
                .ok_or(io::Error::from(io::ErrorKind::NotFound))?;
            let payload = state.cache().get(range.0, size)?;
            if payload.len() > 0 {
                if range.1 == recv_next && state.cache_fin().is_some() {
                    // ACK/FIN
                    trace!(
                        "retransmit TCP ACK/FIN ({} Bytes) {} -> {} from {}",
                        payload.len(),
                        dst,
                        src,
                        sequence
                    );
                    // Send
                    self.send_tcp_ack(dst, src, range.0, payload.as_slice(), true)?;
                } else {
                    // ACK
                    trace!(
                        "retransmit TCP ACK ({} Bytes) {} -> {} from {}",
                        payload.len(),
                        dst,
                        src,
                        sequence
                    );
                    // Send
                    self.send_tcp_ack(dst, src, range.0, payload.as_slice(), false)?;
                }
            }
        }
        // Pure FIN
        let state = self
            .get_state(dst, src)
            .ok_or(io::Error::from(io::ErrorKind::NotFound))?;
        if ranges.len() == 0 && state.cache_fin().is_some() {
            // FIN
            trace!("retransmit TCP FIN {} -> {}", dst, src);
            // Send
            self.send_tcp_fin(dst, src)?;
        }
        Ok(())
    }
pub fn retransmit_tcp ( & mut self , dst : SocketAddrV4 , src : SocketAddrV4 , sacks : Option < Vec < ( u32 , u32 ) > > , ) -> io :: Result < ( ) > { let state = self . get_state_mut ( dst , src ) . ok_or ( io :: Error :: from ( io :: ErrorKind :: NotFound ) ) ? ; let sequence = state . cache ( ) . sequence ( ) ; let recv_next = state . cache ( ) . recv_next ( ) ; // Congestion control if let Some ( cc ) = & mut state . cc_mut ( ) { cc . fast_retransmission ( ) ; } // Find all disjointed ranges let mut ranges = Vec :: new ( ) ; ranges . push ( ( sequence , recv_next ) ) ; if let Some ( sacks ) = sacks { for sack in sacks { let mut temp_ranges = Vec :: new ( ) ; for range in ranges { for temp_range in disjoint_u32_range ( range , sack ) { temp_ranges . push ( temp_range ) ; } } ranges = temp_ranges ; } } let ranges = ranges ; // Retransmit for range in & ranges { let size = range . 1 . checked_sub ( range . 0 ) . unwrap_or_else ( | | range . 1 + ( u32 :: MAX - range . 0 ) ) as usize ; let state = self . get_state ( dst , src ) . ok_or ( io :: Error :: from ( io :: ErrorKind :: NotFound ) ) ? ; let payload = state . cache ( ) . get ( range . 0 , size ) ? ; if payload . len ( ) > 0 { if range . 1 == recv_next && state . cache_fin ( ) . is_some ( ) { // ACK/FIN trace ! ( " " payload len ( ) dst src sequence ) ; // Send self . send_tcp_ack ( dst , src , range . 0 , payload . as_slice ( ) , true ) ? ; } else { // ACK trace ! ( " " payload len ( ) dst src sequence ) ; // Send self . send_tcp_ack ( dst , src , range . 0 , payload . as_slice ( ) , false ) ? ; } } } // Pure FIN let state = self . get_state ( dst , src ) . ok_or ( io :: Error :: from ( io :: ErrorKind :: NotFound ) ) ? ; if ranges . len ( ) == 0 && state . cache_fin ( ) . is_some ( ) { // FIN trace ! ( " " dst src ) ; // Send self . send_tcp_fin ( dst , src ) ? ; } Ok ( ( ) ) }
Retransmits TCP packets from the cache.
Retransmits TCP packets from the cache .
&mut self
dst
SocketAddrV4
src
SocketAddrV4
sacks
Option<Vec<(u32, u32)>>
&mut self
dst
SocketAddrV4
src
SocketAddrV4
sacks
Option<Vec<(u32, u32)>>