naia-lib / naia

a cross-platform (including Wasm!) networking library built in Rust. Intended to make multiplayer game development dead-simple & lightning-fast
Apache License 2.0
878 stars 58 forks source link

Server continues to try to pair with rejected client? #95

Open brandon-reinhart opened 2 years ago

brandon-reinhart commented 2 years ago

If we force an auth failure, the server will continue to send heartbeats to the client for some time. The client doesn't know what to do with these:

2022-09-23T14:52:23.130602Z  INFO webrtc_unreliable_client::webrtc::peer_connection: ICE connection state changed: connected    
2022-09-23T14:52:23.132988Z  INFO webrtc_unreliable_client::webrtc::peer_connection: peer connection state changed: connected
2022-09-23T14:52:24.087938Z  INFO jernau::networking::client::events: Client was rejected!
2022-09-23T14:52:27.733648Z  WARN webrtc_unreliable_client::webrtc::crates::sctp::association::association_internal: [] unable to parse SCTP packet heartbeat should only have HEARTBEAT param
[ repeat this heartbeat warn on client until the server closes the connection ]

After a bit, the server times out the connection, but then tries to begin a new channel connection. This doesn't work because the client is no longer engaged:

2022-09-23T14:52:23.132703Z  INFO webrtc_unreliable::client: DTLS handshake finished for remote 192.168.1.190:64607
2022-09-23T14:52:23.887893Z  INFO jernau::networking::server::events: auth event!
2022-09-23T14:52:23.888111Z  INFO jernau::networking::server::events: rejected!
2022-09-23T14:52:24.136325Z  INFO jernau::networking::server::events: auth event!
2022-09-23T14:52:24.136591Z  INFO jernau::networking::server::events: rejected!
[ heart beats are still sent here ]
2022-09-23T14:53:00.981007Z  INFO webrtc_unreliable::server: connection timeout for client 192.168.1.190:64607
2022-09-23T14:53:00.981312Z  INFO webrtc_unreliable::server: client 192.168.1.190:64607 removed
2022-09-23T14:53:02.717221Z  INFO webrtc_unreliable::server: beginning client data channel connection with 192.168.1.190:64607
2022-09-23T14:53:41.281051Z  INFO webrtc_unreliable::server: connection timeout for client 192.168.1.190:64607
2022-09-23T14:53:41.281332Z  INFO webrtc_unreliable::server: client 192.168.1.190:64607 removed
2022-09-23T14:53:43.203230Z  INFO webrtc_unreliable::server: beginning client data channel connection with 192.168.1.190:64607

I would expect that a rejection would close to the connection, not send heartbeats, and not attempt to renegotiate with a rejected client.

connorcarpenter commented 1 year ago

Yep currently naia works by establishing it's own protocol on top of an established WebRTC data channel. This is not ideal. Authentication should happen before WebRTC establishes a connection, not after. Thank you for the heads up on this :+1: