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
911 stars 58 forks source link

OrderedReliableReceiver delivers messages out-of-order #199

Open dubrowgn opened 2 months ago

dubrowgn commented 2 months ago

OrderedReliableReceiver is implemented as ReliableMessageReceiver<OrderedArranger>. However, ReliableMessageReceiver erases the original message ids, and generates new ones in FIFO order.

See:

// reliable_message_receiver.rs
impl<A: ReceiverArranger> ReliableMessageReceiver<A> {
    ...

    fn push_message(...) {
        ...

        let first_index = self.current_index;
        self.current_index = self.current_index.wrapping_add(1);

        ...

        self.arranger
            .process(&mut self.incoming_messages, first_index, full_message);
    }

Each message is assigned a message id in order of being received. This new message id is being given to the arranger.

The original message id is being dropped:

// reliable_message_receiver.rs
impl<A: ReceiverArranger> ReliableMessageReceiver<A> {
    ...

    pub fn buffer_message(
        ...
        message_index: MessageIndex,
        message: MessageContainer,
    ) {
        self.reliable_receiver
            .buffer_message(message_index, message);
        let received_messages = self.reliable_receiver.receive_messages();
        for (_, received_message) in received_messages {
            self.push_message(message_kinds, entity_waitlist, converter, received_message)
        }
    }