quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.76k stars 380 forks source link

Example server and client running error #1375

Closed StanLi-ops closed 2 years ago

StanLi-ops commented 2 years ago

When I execute the sample program, the following occurs.

server

[root@localhost quinn]# cargo run --example server ./ --listen 127.0.0.1:4433
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/examples/server ./ --listen '127.0.0.1:4433'`
listening on 127.0.0.1:4433
2022-06-21T09:47:55.193591Z ERROR server: connection failed: aborted by peer: the application or application protocol caused the connection to be closed during the handshake

client

[root@localhost quinn]# cargo run --example client https://127.0.0.1:4433/Cargo.toml
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/client 'https://127.0.0.1:4433/Cargo.toml'`
connecting to 127.0.0.1 at 127.0.0.1:4433
ERROR: failed to connect: the cryptographic handshake failed: error 42: presented server name type wasn't supported
[root@localhost quinn]#

When the ip and port are not configured, it can be executed normally.

server

[root@localhost quinn]# cargo run --example server ./
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/server ./`
listening on [::1]:4433

client

[root@localhost quinn]# cargo run --example client https://localhost:4433/Cargo.toml
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/client 'https://localhost:4433/Cargo.toml'`
connecting to localhost at [::1]:4433
connected at 15.295521ms
request sent at 23.614274ms
response received in 227.499µs - 944.3723 KiB/s
[workspace]
members = ["quinn", "quinn-proto", "quinn-udp", "bench", "perf", "fuzz"]
default-members = ["quinn", "quinn-proto", "quinn-udp", "bench", "perf"]

[profile.bench]
debug = true

[profile.release]
debug = true
[root@localhost quinn]# 

is this normal?

djc commented 2 years ago

I think the client is trying to tell you that you need to connect to a host name, not an IP address. This is a limitation in the underlying rustls library.

https://github.com/rustls/rustls/issues/184

StanLi-ops commented 2 years ago

I think the client is trying to tell you that you need to connect to a host name, not an IP address. This is a limitation in the underlying rustls library.

rustls/rustls#184

It seems that the "--listen" configuration in the server has no effect. The example only works fine with default values. After I use "--listen" to modify the ip and port of the server, the client cannot connect to the server normally whether it uses "localhost" or "127.0.0.1". like this:

[root@localhost quinn]# cargo run --example server ./ --listen 127.0.0.1:4433
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/server ./ --listen '127.0.0.1:4433'`
listening on 127.0.0.1:4433

[root@localhost quinn]# cargo run --example client https://localhost:4433/Cargo.toml
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/client 'https://localhost:4433/Cargo.toml'`
connecting to localhost at [::1]:4433
ERROR: failed to connect: timed out
[root@localhost quinn]#
[root@localhost quinn]# cargo run --example server ./ --listen 127.0.0.1:4433
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/server ./ --listen '127.0.0.1:4433'`
listening on 127.0.0.1:4433
2022-06-22T02:27:38.839686Z ERROR server: connection failed: aborted by peer: the application or application protocol caused the connection to be closed during the handshake

[root@localhost quinn]# cargo run --example client https://127.0.0.1:4433/Cargo.toml
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/examples/client 'https://127.0.0.1:4433/Cargo.toml'`
connecting to 127.0.0.1 at 127.0.0.1:4433
ERROR: failed to connect: the cryptographic handshake failed: error 42: presented server name type wasn't supported
[root@localhost quinn]#

If I want the server to listen on port 1167 instead of 4433, how can I get the example to work? The same goes for custom domains.

Ralith commented 2 years ago

You're telling the server to listen on an IPv4 address, and your environment is likely resolving "localhost" to an IPv6 address. Try listening on an IPv6 address.