/// Init and run a TcpEndpoint object.
/// You need send a socketaddr str and tcp send message's addr,
/// and receiver outside message addr.
Init and run a TcpEndpoint object.
You need send a socketaddr str and tcp send message's addr,
and receiver outside message addr.
Init and run a TcpEndpoint object . You need send a socketaddr str and tcp send message ' s addr and receiver outside message addr .
pub async fn start(
    bind_addr: SocketAddr,
    send: Sender<TransportRecvMessage>,
    recv: Receiver<TransportSendMessage>,
) -> tokio::io::Result<()> {
    let config = InternalConfig::try_from_config(Default::default()).unwrap();
    let mut builder = quinn::Endpoint::builder();
    let _ = builder.listen(config.server.clone());
    let (endpoint, mut incoming) = builder.bind(&bind_addr).unwrap();
    // TCP listen incoming.
    let out_send = send.clone();
    tokio::spawn(async move {
        loop {
            match incoming.next().await {
                Some(quinn_conn) => match quinn_conn.await {
                    Ok(conn) => {
                        let (self_sender, self_receiver) = new_endpoint_channel();
                        let (out_sender, out_receiver) = new_endpoint_channel();
                        tokio::spawn(process_stream(
                            conn,
                            out_sender,
                            self_receiver,
                            OutType::DHT(out_send.clone(), self_sender, out_receiver),
                            None,
                        ));
                    }
                    Err(err) => {
                        error!("An incoming failed because of an error: {:?}", err);
                    }
                },
                None => {
                    break;
                }
            }
        }
    });
    // TCP listen from outside.
    tokio::spawn(run_self_recv(endpoint, config.client, recv, send));
    Ok(())
}
pub async fn start ( bind_addr : SocketAddr , send : Sender < TransportRecvMessage > , recv : Receiver < TransportSendMessage > , ) -> tokio :: io :: Result < ( ) > { let config = InternalConfig :: try_from_config ( Default :: default ( ) ) . unwrap ( ) ; let mut builder = quinn :: Endpoint :: builder ( ) ; let _ = builder . listen ( config . server . clone ( ) ) ; let ( endpoint , mut incoming ) = builder . bind ( & bind_addr ) . unwrap ( ) ; // TCP listen incoming. let out_send = send . clone ( ) ; tokio :: spawn ( async move { loop { match incoming . next ( ) . await { Some ( quinn_conn ) => match quinn_conn . await { Ok ( conn ) => { let ( self_sender , self_receiver ) = new_endpoint_channel ( ) ; let ( out_sender , out_receiver ) = new_endpoint_channel ( ) ; tokio :: spawn ( process_stream ( conn , out_sender , self_receiver , OutType :: DHT ( out_send . clone ( ) , self_sender , out_receiver ) , None , ) ) ; } Err ( err ) => { error ! ( " " err ) ; } } , None => { break ; } } } } ) ; // TCP listen from outside. tokio :: spawn ( run_self_recv ( endpoint , config . client , recv , send ) ) ; Ok ( ( ) ) }
Init and run a TcpEndpoint object.
Init and run a TcpEndpoint object .
bind_addr
SocketAddr
send
Sender<TransportRecvMessage>
recv
Receiver<TransportSendMessage>