pub fn passive_open<T: NetworkBytes>(
        segment: &TcpSegment<T>,
        local_rwnd_size: u32,
        rto_period: NonZeroU64,
        rto_count_max: NonZeroU16,
    ) -> Result<Self, PassiveOpenError> {
        // We don't accepting anything other than a SYN segment here.
        if !is_valid_syn(segment) {
            return Err(PassiveOpenError::InvalidSyn);
        }

        // TODO: If we ever implement window scaling, change the part that computes
        // remote_rwnd_edge below.

        // We only care about the MSS option for now.
        let mss = parse_mss_option(segment)?;

        // This is going to get sent on the SYNACK.
        let ack_to_send = Wrapping(segment.sequence_number()) + Wrapping(1);

        // Let's pick the initial sequence number.
        let isn = Wrapping(xor_psuedo_rng_u32());
        let first_not_sent = isn + Wrapping(1);
        let remote_rwnd_edge = first_not_sent + Wrapping(u32::from(segment.window_size()));

        Ok(Connection {
            ack_to_send,
            highest_ack_received: isn,
            // The ISN is sent over the SYNACK, and this is the next sequence number.
            first_not_sent,
            local_rwnd_edge: ack_to_send + Wrapping(local_rwnd_size),
            // We have no information about this yet. It will get updated as the connection reaches
            // the ESTABLISHED state.
            remote_rwnd_edge,
            rto_start: 0,
            rto_period: rto_period.get(),
            rto_count: 0,
            rto_count_max: rto_count_max.get(),
            fin_received: None,
            send_fin: None,
            send_rst: None,
            mss,
            pending_ack: false,
            dup_ack: false,
            status_flags: ConnStatusFlags::SYN_RECEIVED,
        })
    }
/// Attempts to create a new `Connection` in response to an incoming `SYN` segment.
///
/// # Arguments
///
/// * `segment` - The incoming `SYN`.
/// * `local_rwnd_size` - Initial size of the local receive window.
/// * `rto_period` - How long the connection waits before a retransmission timeout fires for
///   the first segment which has not been acknowledged yet. This uses an opaque time unit.
/// * `rto_count_max` - How many consecutive timeout-based retransmission may occur before
///   the connection resets itself.
Attempts to create a new `Connection` in response to an incoming `SYN` segment.
Attempts to create a new ` Connection ` in response to an incoming ` SYN ` segment .
pub fn passive_open<T: NetworkBytes>(
        segment: &TcpSegment<T>,
        local_rwnd_size: u32,
        rto_period: NonZeroU64,
        rto_count_max: NonZeroU16,
    ) -> Result<Self, PassiveOpenError> {
        // We don't accepting anything other than a SYN segment here.
        if !is_valid_syn(segment) {
            return Err(PassiveOpenError::InvalidSyn);
        }
        // TODO: If we ever implement window scaling, change the part that computes
        // remote_rwnd_edge below.
        // We only care about the MSS option for now.
        let mss = parse_mss_option(segment)?;
        // This is going to get sent on the SYNACK.
        let ack_to_send = Wrapping(segment.sequence_number()) + Wrapping(1);
        // Let's pick the initial sequence number.
        let isn = Wrapping(xor_psuedo_rng_u32());
        let first_not_sent = isn + Wrapping(1);
        let remote_rwnd_edge = first_not_sent + Wrapping(u32::from(segment.window_size()));
        Ok(Connection {
            ack_to_send,
            highest_ack_received: isn,
            // The ISN is sent over the SYNACK, and this is the next sequence number.
            first_not_sent,
            local_rwnd_edge: ack_to_send + Wrapping(local_rwnd_size),
            // We have no information about this yet. It will get updated as the connection reaches
            // the ESTABLISHED state.
            remote_rwnd_edge,
            rto_start: 0,
            rto_period: rto_period.get(),
            rto_count: 0,
            rto_count_max: rto_count_max.get(),
            fin_received: None,
            send_fin: None,
            send_rst: None,
            mss,
            pending_ack: false,
            dup_ack: false,
            status_flags: ConnStatusFlags::SYN_RECEIVED,
        })
    }
pub fn passive_open < T : NetworkBytes > ( segment : & TcpSegment < T > , local_rwnd_size : u32 , rto_period : NonZeroU64 , rto_count_max : NonZeroU16 , ) -> Result < Self , PassiveOpenError > { // We don't accepting anything other than a SYN segment here. if ! is_valid_syn ( segment ) { return Err ( PassiveOpenError :: InvalidSyn ) ; } // TODO: If we ever implement window scaling, change the part that computes // remote_rwnd_edge below. // We only care about the MSS option for now. let mss = parse_mss_option ( segment ) ? ; // This is going to get sent on the SYNACK. let ack_to_send = Wrapping ( segment . sequence_number ( ) ) + Wrapping ( 1 ) ; // Let's pick the initial sequence number. let isn = Wrapping ( xor_psuedo_rng_u32 ( ) ) ; let first_not_sent = isn + Wrapping ( 1 ) ; let remote_rwnd_edge = first_not_sent + Wrapping ( u32 :: from ( segment . window_size ( ) ) ) ; Ok ( Connection { ack_to_send , highest_ack_received : isn , // The ISN is sent over the SYNACK, and this is the next sequence number. first_not_sent , local_rwnd_edge : ack_to_send + Wrapping ( local_rwnd_size ) , // We have no information about this yet. It will get updated as the connection reaches // the ESTABLISHED state. remote_rwnd_edge , rto_start : 0 , rto_period : rto_period . get ( ) , rto_count : 0 , rto_count_max : rto_count_max . get ( ) , fin_received : None , send_fin : None , send_rst : None , mss , pending_ack : false , dup_ack : false , status_flags : ConnStatusFlags :: SYN_RECEIVED , } ) }
Attempts to create a new `Connection` in response to an incoming `SYN` segment.
Attempts to create a new ` Connection ` in response to an incoming ` SYN ` segment .
segment
&TcpSegment<T>
local_rwnd_size
u32
rto_period
NonZeroU64
rto_count_max
NonZeroU16
segment
&TcpSegment<T>
local_rwnd_size
u32
rto_period
NonZeroU64
rto_count_max
NonZeroU16