async fn attack_target(
        &self,
        target: Target,
    ) -> Box<dyn SingleAttackResult> {
        let start = Instant::now();
        let resp = tokio::time::timeout(
            Duration::from_millis(self.timeout_ms),
            tokio::net::TcpStream::connect(target.ip_or_url),
        )
        .await;

        match resp {
            Ok(res) => match res {
                Ok(_) => {
                    let duration_ms = start.elapsed().as_millis();
                    return Box::new(TcpAttackResult {
                        target_down: false,
                        duration_ms,
                    });
                }
                Err(_) => {
                    let duration_ms = start.elapsed().as_millis();
                    return Box::new(TcpAttackResult {
                        target_down: true,
                        duration_ms,
                    });
                }
            },
            Err(_) => Box::new(TcpAttackResult {
                target_down: true,
                duration_ms: start.elapsed().as_millis(),
            }),
        }
    }
// establishes a tcp connection.
// syn-flooding does not work in this case, because there is no way to estimate the time the target needed to respond.
establishes a tcp connection.
syn-flooding does not work in this case, because there is no way to estimate the time the target needed to respond.
establishes a tcp connection . syn - flooding does not work in this case because there is no way to estimate the time the target needed to respond .
async fn attack_target(
        &self,
        target: Target,
    ) -> Box<dyn SingleAttackResult> {
        let start = Instant::now();
        let resp = tokio::time::timeout(
            Duration::from_millis(self.timeout_ms),
            tokio::net::TcpStream::connect(target.ip_or_url),
        )
        .await;
        match resp {
            Ok(res) => match res {
                Ok(_) => {
                    let duration_ms = start.elapsed().as_millis();
                    return Box::new(TcpAttackResult {
                        target_down: false,
                        duration_ms,
                    });
                }
                Err(_) => {
                    let duration_ms = start.elapsed().as_millis();
                    return Box::new(TcpAttackResult {
                        target_down: true,
                        duration_ms,
                    });
                }
            },
            Err(_) => Box::new(TcpAttackResult {
                target_down: true,
                duration_ms: start.elapsed().as_millis(),
            }),
        }
    }
async fn attack_target ( & self , target : Target , ) -> Box < dyn SingleAttackResult > { let start = Instant :: now ( ) ; let resp = tokio :: time :: timeout ( Duration :: from_millis ( self . timeout_ms ) , tokio :: net :: TcpStream :: connect ( target . ip_or_url ) , ) . await ; match resp { Ok ( res ) => match res { Ok ( _ ) => { let duration_ms = start . elapsed ( ) . as_millis ( ) ; return Box :: new ( TcpAttackResult { target_down : false , duration_ms , } ) ; } Err ( _ ) => { let duration_ms = start . elapsed ( ) . as_millis ( ) ; return Box :: new ( TcpAttackResult { target_down : true , duration_ms , } ) ; } } , Err ( _ ) => Box :: new ( TcpAttackResult { target_down : true , duration_ms : start . elapsed ( ) . as_millis ( ) , } ) , } }
establishes a tcp connection.
establishes a tcp connection .
&self
target
Target
&self
target
Target