pub async fn run<F>(mut self, adapter_fn: F) -> Self
    where
        F: Fn(ConnectionId, Vec<u8>, bool) -> S + Send + 'static,
    {
        let (read_half, write_half) = self.socket.take().unwrap().into_split();

        // should run until either inbound closes or is notified from outbound
        let inbound_future = Self::run_inbound(
            read_half,
            self.local_destination_address.clone(),
            self.remote_source_address.clone(),
            self.connection_id,
            self.mix_sender.clone(),
            adapter_fn,
        );

        let outbound_future = Self::run_outbound(
            write_half,
            self.local_destination_address.clone(),
            self.remote_source_address.clone(),
            self.mix_receiver.take().unwrap(),
            self.connection_id,
        );

        // TODO: this shouldn't really have to spawn tasks inside "library" code, but
        // if we used join directly, stuff would have been executed on the same thread
        // (it's not bad, but an unnecessary slowdown)
        let handle_inbound = tokio::spawn(inbound_future);
        let handle_outbound = tokio::spawn(outbound_future);

        let (inbound_result, outbound_result) =
            futures::future::join(handle_inbound, handle_outbound).await;

        if inbound_result.is_err() || outbound_result.is_err() {
            panic!("TODO: some future error?")
        }

        let read_half = inbound_result.unwrap();
        let (write_half, mix_receiver) = outbound_result.unwrap();

        self.socket = Some(write_half.reunite(read_half).unwrap());
        self.mix_receiver = Some(mix_receiver);
        self
    }
// The `adapter_fn` is used to transform whatever was read into appropriate
// request/response as required by entity running particular side of the proxy.
The `adapter_fn` is used to transform whatever was read into appropriate
request/response as required by entity running particular side of the proxy.
The ` adapter_fn ` is used to transform whatever was read into appropriate request / response as required by entity running particular side of the proxy .
pub async fn run<F>(mut self, adapter_fn: F) -> Self
    where
        F: Fn(ConnectionId, Vec<u8>, bool) -> S + Send + 'static,
    {
        let (read_half, write_half) = self.socket.take().unwrap().into_split();
        // should run until either inbound closes or is notified from outbound
        let inbound_future = Self::run_inbound(
            read_half,
            self.local_destination_address.clone(),
            self.remote_source_address.clone(),
            self.connection_id,
            self.mix_sender.clone(),
            adapter_fn,
        );
        let outbound_future = Self::run_outbound(
            write_half,
            self.local_destination_address.clone(),
            self.remote_source_address.clone(),
            self.mix_receiver.take().unwrap(),
            self.connection_id,
        );
        // TODO: this shouldn't really have to spawn tasks inside "library" code, but
        // if we used join directly, stuff would have been executed on the same thread
        // (it's not bad, but an unnecessary slowdown)
        let handle_inbound = tokio::spawn(inbound_future);
        let handle_outbound = tokio::spawn(outbound_future);
        let (inbound_result, outbound_result) =
            futures::future::join(handle_inbound, handle_outbound).await;
        if inbound_result.is_err() || outbound_result.is_err() {
            panic!("TODO: some future error?")
        }
        let read_half = inbound_result.unwrap();
        let (write_half, mix_receiver) = outbound_result.unwrap();
        self.socket = Some(write_half.reunite(read_half).unwrap());
        self.mix_receiver = Some(mix_receiver);
        self
    }
pub async fn run < F > ( mut self , adapter_fn : F ) -> Self where F : Fn ( ConnectionId , Vec < u8 > , bool ) -> S + Send + ' static , { let ( read_half , write_half ) = self . socket . take ( ) . unwrap ( ) . into_split ( ) ; // should run until either inbound closes or is notified from outbound let inbound_future = Self :: run_inbound ( read_half , self . local_destination_address . clone ( ) , self . remote_source_address . clone ( ) , self . connection_id , self . mix_sender . clone ( ) , adapter_fn , ) ; let outbound_future = Self :: run_outbound ( write_half , self . local_destination_address . clone ( ) , self . remote_source_address . clone ( ) , self . mix_receiver . take ( ) . unwrap ( ) , self . connection_id , ) ; // TODO: this shouldn't really have to spawn tasks inside "library" code, but // if we used join directly, stuff would have been executed on the same thread // (it's not bad, but an unnecessary slowdown) let handle_inbound = tokio :: spawn ( inbound_future ) ; let handle_outbound = tokio :: spawn ( outbound_future ) ; let ( inbound_result , outbound_result ) = futures :: future :: join ( handle_inbound , handle_outbound ) . await ; if inbound_result . is_err ( ) || outbound_result . is_err ( ) { panic ! ( " " ) } let read_half = inbound_result . unwrap ( ) ; let ( write_half , mix_receiver ) = outbound_result . unwrap ( ) ; self . socket = Some ( write_half . reunite ( read_half ) . unwrap ( ) ) ; self . mix_receiver = Some ( mix_receiver ) ; self }
The `adapter_fn` is used to transform whatever was read into appropriate
request/response as required by entity running particular side of the proxy.
The ` adapter_fn ` is used to transform whatever was read into appropriate request / response as required by entity running particular side of the proxy .
mut self
adapter_fn
F