NetrexMC / RakNet

RakNet implementation in Rust
Apache License 2.0
44 stars 12 forks source link

bug: Client doesn't discover MTU size #46

Closed john-bv closed 1 year ago

john-bv commented 1 year ago

Currently, rak_rs does not attempt to discover MTU size from the client. Currently, we time out the client if the server doesn't send a OpenConnectReply however this behavior is wrong, we need to continuously send a OpenConnectRequest until the server accepts the MTU size.

Implementation example:

// discover MTU
let mut mtu = MAX_MTU;
let mut connect_request = OpenConnectRequest {
    protocol: 11,
    mtu_size: mtu
};
for i in (MIN_MTU_SIZE...mtu).rev() {
    // attempt to send request
    if !send_packet(&socket, connect_request.into()).await {
        // error sending
    }

    let reply = expect_reply!(socket.clone(), OpenConnectReply::id());

    if reply.is_none() {
        // try again, unless...
        if i == MIN_MTU_SIZE {
            return Err(HandshakeStatus::Failed);
        }
    }

    // we got a reply!
    break;
}
john-bv commented 1 year ago

This issue will be fixed in 0.3.1 (v3 after master merge)

john-bv commented 1 year ago

Resolved as of: 8faf09dc44af9e142cc7987f6e56f186fe04bfcb