zoukankan      html  css  js  c++  java
  • quic examples client server

    https://reposhub.com/rust/network-programming/cloudflare-quiche.html

    Building

    # 準備
    $ apt-get install cmake
    $ curl https://sh.rustup.rs -sSf | sh # 適宜PATH通してcargo使えるように
    
    $ git clone https://github.com/cloudflare/quiche.git
    $ cd ./quiche
    quiche$ git submodule update --init
    quiche$ cargo build --examples

    quiche requires Rust 1.39 or later to build. The latest stable Rust release can be installed using rustup.

    Once the Rust build environment is setup, the quiche source code can be fetched using git:

     $ git clone --recursive https://github.com/cloudflare/quiche

    and then built using cargo:

     $ cargo build --examples

    cargo can also be used to run the testsuite:

     $ cargo test

    Note that BoringSSL, which is used to implement QUIC's cryptographic handshake based on TLS, needs to be built and linked to quiche. This is done automatically when building quiche using cargo, but requires the cmakego and perl commands to be available during the build process. On Windows you also need NASM. The official BoringSSL documentation has more details.

    In alternative you can use your own custom build of BoringSSL by configuring the BoringSSL directory with the QUICHE_BSSL_PATH environment variable:

     $ QUICHE_BSSL_PATH="/path/to/boringssl" cargo build --examples



    root@ubuntu:~/quiche# cd examples/
    root@ubuntu:~/quiche/examples# cd ..
    root@ubuntu:~/quiche# cargo build --examples
       Compiling quiche v0.7.0 (/root/quiche)
        Finished dev [unoptimized + debuginfo] target(s) in 3.31s
    root@ubuntu:~/quiche# find ./ -name http3-server 
    ./target/debug/examples/http3-server

    server

    quiche$ quiche$ mkdir ./examples/root
    quiche$ echo 'It works!!' > ./examples/root/index.html
    
    quiche$ target/debug/examples/http3-server
    root@ubuntu:~/quiche/target/debug/examples# ./http3-server 
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TlsFail', examples/http3-server.rs:94:10
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    root@ubuntu:~/quiche/target/debug/examples# 

     

    90     let mut config = quiche::Config::new(quiche::PROTOCOL_VERSION).unwrap();
     91 
     92     config
     93         .load_cert_chain_from_pem_file("examples/cert.crt")
     94         .unwrap();
     95     config
     96         .load_priv_key_from_pem_file("examples/cert.key")
     97         .unwrap();
    client.d                   http3-client.d                   http3-server.d                   qpack_decode-f30e13401191c909.d  qpack-encode.d                   server-310b42a31ecb34f8.d
    root@ubuntu:~/quiche/target/debug/examples# cp http3-server ~/quiche
    root@ubuntu:~/quiche/target/debug/examples# 

     

    client

    quiche$ target/debug/examples/http3-client https://localhost:4433/index.html --no-verify
    It works!!
    root@ubuntu:~/quiche/target/debug/examples# ./http3-client https://localhost:4433/index.html
    thread 'main' panicked at 'recv() failed: Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }', examples/http3-client.rs:183:21
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    root@ubuntu:~/quiche/target/debug/examples# 

    -    quiche_config *config = quiche_config_new(0xbabababa);
    +    quiche_config *config = quiche_config_new(QUICHE_PROTOCOL_VERSION);

    HTTP/3

    The quiche HTTP/3 module provides a high level API for sending and receiving HTTP requests and responses on top of the QUIC transport protocol.

    Have a look at the examples/ directory for more complete examples on how to use the quiche API, including examples on how to use quiche in C/C++ applications (see below for more information).

    Calling quiche from C/C++

    quiche exposes a thin C API on top of the Rust API that can be used to more easily integrate quiche into C/C++ applications (as well as in other languages that allow calling C APIs via some form of FFI). The C API follows the same design of the Rust one, modulo the constraints imposed by the C language itself.

    When running cargo build, a static library called libquiche.a will be built automatically alongside the Rust one. This is fully stand-alone and can be linked directly into C/C++ applications.

    Building

    quiche requires Rust 1.39 or later to build. The latest stable Rust release can be installed using rustup.

    Once the Rust build environment is setup, the quiche source code can be fetched using git:

     $ git clone --recursive https://github.com/cloudflare/quiche

    and then built using cargo:

     $ cargo build --examples

    cargo can also be used to run the testsuite:

     $ cargo test

    Note that BoringSSL, which is used to implement QUIC's cryptographic handshake based on TLS, needs to be built and linked to quiche. This is done automatically when building quiche using cargo, but requires the cmakego and perl commands to be available during the build process. On Windows you also need NASM. The official BoringSSL documentation has more details.

    In alternative you can use your own custom build of BoringSSL by configuring the BoringSSL directory with the QUICHE_BSSL_PATH environment variable:

    $ QUICHE_BSSL_PATH="/path/to/boringssl" cargo build --examples


    Here are logs: server

    ~/.../quiche/examples >>> ./server 127.0.0.1 1234                                           
    stateless retry
    sent 93 bytes
    recv would block
    new connection
    quiche: bed00effe987dca943b3a186386830a7 rx pkt Initial version=ff00001d dcid=c4c07e8f8588b0f65febb00f9c62d991 scid=57fb5bcfc3946bf7cd5800bb49a75417 token=7175696368650200ed7f7f0000010000000000000000c4c07e8f8588b0f65febb00f9c62d991 len=1120 pn=1
    quiche: bed00effe987dca943b3a186386830a7 rx frm CRYPTO off=0 len=512
    quiche::tls: checking peer ALPN Ok("hq-29") against Ok("hq-29")
    quiche::tls: bed00effe987dca943b3a186386830a7 write message lvl=Initial len=90
    quiche::tls: bed00effe987dca943b3a186386830a7 set write secret lvl=Handshake
    quiche::tls: bed00effe987dca943b3a186386830a7 write message lvl=Handshake len=1178
    quiche::tls: bed00effe987dca943b3a186386830a7 set write secret lvl=OneRTT
    quiche::tls: bed00effe987dca943b3a186386830a7 set read secret lvl=Handshake
    quiche: bed00effe987dca943b3a186386830a7 rx frm PADDING len=587
    recv 1200 bytes
    recv would block
    quiche: bed00effe987dca943b3a186386830a7 tx pkt Initial version=ff00001d dcid=57fb5bcfc3946bf7cd5800bb49a75417 scid=bed00effe987dca943b3a186386830a7 len=116 pn=0
    quiche: bed00effe987dca943b3a186386830a7 tx frm ACK delay=1118 blocks=[1..1]
    quiche: bed00effe987dca943b3a186386830a7 tx frm CRYPTO off=0 len=90
    quiche::recovery: bed00effe987dca943b3a186386830a7 timer=999.850593ms latest_rtt=0ns srtt=None min_rtt=0ns rttvar=0ns loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=159 app_limited=true congestion_recovery_start_time=None delivered=0 delivered_time=162.421µs recent_delivered_packet_sent_time=163.121µs app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    sent 159 bytes
    quiche: bed00effe987dca943b3a186386830a7 tx pkt Handshake version=ff00001d dcid=57fb5bcfc3946bf7cd5800bb49a75417 scid=bed00effe987dca943b3a186386830a7 len=1154 pn=0
    quiche: bed00effe987dca943b3a186386830a7 tx frm CRYPTO off=0 len=1134
    quiche::recovery: bed00effe987dca943b3a186386830a7 timer=999.711623ms latest_rtt=0ns srtt=None min_rtt=0ns rttvar=0ns loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=1355 app_limited=true congestion_recovery_start_time=None delivered=0 delivered_time=296.695µs recent_delivered_packet_sent_time=297.22µs app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    sent 1196 bytes
    quiche: bed00effe987dca943b3a186386830a7 tx pkt Handshake version=ff00001d dcid=57fb5bcfc3946bf7cd5800bb49a75417 scid=bed00effe987dca943b3a186386830a7 len=64 pn=1
    quiche: bed00effe987dca943b3a186386830a7 tx frm CRYPTO off=1134 len=44
    quiche::recovery: bed00effe987dca943b3a186386830a7 timer=999.600422ms latest_rtt=0ns srtt=None min_rtt=0ns rttvar=0ns loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=1461 app_limited=true congestion_recovery_start_time=None delivered=0 delivered_time=410.724µs recent_delivered_packet_sent_time=411.244µs app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    sent 106 bytes
    done writing
    quiche: bed00effe987dca943b3a186386830a7 rx pkt Handshake version=ff00001d dcid=bed00effe987dca943b3a186386830a7 scid=57fb5bcfc3946bf7cd5800bb49a75417 len=21 pn=0
    quiche: bed00effe987dca943b3a186386830a7 rx frm CONNECTION_CLOSE err=8 frame=0 reason=[]
    quiche: bed00effe987dca943b3a186386830a7 dropped epoch 0 state
    recv 61 bytes
    recv would block
    done writing
    quiche: bed00effe987dca943b3a186386830a7 draining timeout expired
    timeout
    done writing
    connection closed, recv=2 sent=3 lost=0 rtt=500000000ns cwnd=14520
    

    client

    ~/.../quiche/examples >>> ./client 127.0.0.1 1234             
    quiche::tls: 57fb5bcfc3946bf7cd5800bb49a75417 write message lvl=Initial len=512
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx pkt Initial version=ff00001d dcid=c4c07e8f8588b0f65febb00f9c62d991 scid=57fb5bcfc3946bf7cd5800bb49a75417 len=1157 pn=0
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx frm CRYPTO off=0 len=512
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx frm PADDING len=625
    quiche::recovery: 57fb5bcfc3946bf7cd5800bb49a75417 timer=999.544142ms latest_rtt=0ns srtt=None min_rtt=0ns rttvar=0ns loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=1200 app_limited=true congestion_recovery_start_time=None delivered=0 delivered_time=472.271µs recent_delivered_packet_sent_time=472.809µs app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    sent 1200 bytes
    done writing
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 rx pkt Retry version=ff00001d dcid=57fb5bcfc3946bf7cd5800bb49a75417 scid=c4c07e8f8588b0f65febb00f9c62d991 token=7175696368650200ed7f7f0000010000000000000000c4c07e8f8588b0f65febb00f9c62d991
    recv 93 bytes
    recv would block
    done reading
    quiche::tls: 57fb5bcfc3946bf7cd5800bb49a75417 write message lvl=Initial len=512
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx pkt Initial version=ff00001d dcid=c4c07e8f8588b0f65febb00f9c62d991 scid=57fb5bcfc3946bf7cd5800bb49a75417 token=7175696368650200ed7f7f0000010000000000000000c4c07e8f8588b0f65febb00f9c62d991 len=1119 pn=1
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx frm CRYPTO off=0 len=512
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx frm PADDING len=587
    quiche::recovery: 57fb5bcfc3946bf7cd5800bb49a75417 timer=999.582502ms latest_rtt=0ns srtt=None min_rtt=0ns rttvar=0ns loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=1200 app_limited=true congestion_recovery_start_time=None delivered=0 delivered_time=1.48449ms recent_delivered_packet_sent_time=1.48498ms app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    sent 1200 bytes
    done writing
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 rx pkt Initial version=ff00001d dcid=57fb5bcfc3946bf7cd5800bb49a75417 scid=bed00effe987dca943b3a186386830a7 token= len=117 pn=0
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 rx frm ACK delay=1118 blocks=[1..1]
    quiche::recovery: 57fb5bcfc3946bf7cd5800bb49a75417 packet newly acked 1
    quiche::recovery: 57fb5bcfc3946bf7cd5800bb49a75417 timer=none latest_rtt=10.321509ms srtt=Some(10.321509ms) min_rtt=10.321509ms rttvar=5.160754ms loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=0 app_limited=true congestion_recovery_start_time=None delivered=1200 delivered_time=157.869µs recent_delivered_packet_sent_time=11.539471ms app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 rx frm CRYPTO off=0 len=90
    quiche::tls: 57fb5bcfc3946bf7cd5800bb49a75417 set write secret lvl=Handshake
    quiche::tls: 57fb5bcfc3946bf7cd5800bb49a75417 set read secret lvl=Handshake
    recv 159 bytes
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 rx pkt Handshake version=ff00001d dcid=57fb5bcfc3946bf7cd5800bb49a75417 scid=bed00effe987dca943b3a186386830a7 len=1155 pn=0
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 rx frm CRYPTO off=0 len=1134
    failed to process packet
    recv 106 bytes
    recv would block
    done reading
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx pkt Handshake version=ff00001d dcid=bed00effe987dca943b3a186386830a7 scid=57fb5bcfc3946bf7cd5800bb49a75417 len=20 pn=0
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 tx frm CONNECTION_CLOSE err=8 frame=0 reason=[]
    quiche::recovery: 57fb5bcfc3946bf7cd5800bb49a75417 timer=44.094416ms latest_rtt=10.321509ms srtt=Some(10.321509ms) min_rtt=10.321509ms rttvar=5.160754ms loss_time=[None, None, None] loss_probes=[0, 0, 0] cwnd=14520 ssthresh=18446744073709551615 bytes_in_flight=61 app_limited=true congestion_recovery_start_time=None delivered=1200 delivered_time=1.560008ms recent_delivered_packet_sent_time=12.941538ms app_limited_at_pkt=0  hystart=window_end=None last_round_min_rtt=None current_round_min_rtt=None rtt_sample_count=0 lss_start_time=None  
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 dropped epoch 0 state
    sent 61 bytes
    done writing
    timeout
    done writing
    quiche: 57fb5bcfc3946bf7cd5800bb49a75417 draining timeout expired
    timeout
    done writing
    connection closed, recv=1 sent=3 lost=0 rtt=10321509ns
  • 相关阅读:
    C++使用GDI+实现图片格式转换
    易语言调用C++写的DLL
    【PE】手动给PE文件添加一段代码MessageBoxA
    SHGetSpecialFolderLocation获取开始文件夹
    MySQL导入导出数据
    MySQL5.7修改密码
    Elasticsearch 基于external的乐观锁的版本控制
    Elasticsearch修改字段类型 (_reindex)
    es 迁移数据, 重建索引
    SHELL
  • 原文地址:https://www.cnblogs.com/dream397/p/14583563.html
Copyright © 2011-2022 走看看