pub fn handle_incoming_data(
        &mut self,
        socket: &mut dyn Socket,
        data: &[u8],
    ) -> Result<Option<TParam::TReceive>> {
        let packet: Packet<_> = bincode::deserialize(data)?;
        Ok(match packet {
            Packet::Ping {
                last_send_message_id,
            } => {
                self.resolve_incoming_ping(last_send_message_id);
                send_packet_to::<TParam::TSend>(
                    self.peer_addr,
                    socket,
                    &Packet::Pong {
                        last_send_message_id: self.send.next_message_id,
                    },
                )?;
                None
            }
            Packet::RequestPacket { id } => {
                if let Some(packet) = self.send.unconfirmed_message_cache.get_mut(&id) {
                    packet.last_emit = Instant::now();
                    send_packet_to(self.peer_addr, socket, &packet.packet)?;
                } else {
                    send_packet_to::<TParam::TSend>(
                        self.peer_addr,
                        socket,
                        &Packet::PacketNotFound { id },
                    )?;
                }
                None
            }
            Packet::ConfirmPacket { id } => {
                self.send.unconfirmed_message_cache.remove(&id);
                None
            }
            Packet::PacketNotFound { id } => {
                self.receive.missing_message_id_list.retain(|i| i.id != id);
                None
            }
            Packet::Pong {
                last_send_message_id,
            } => {
                self.resolve_incoming_ping(last_send_message_id);
                None
            }
            Packet::Data { message_id, data } => {
                if let Some(message_id) = message_id {
                    self.request_message_up_to(message_id.get() - 1);
                    send_packet_to::<TParam::TSend>(
                        self.peer_addr,
                        socket,
                        &Packet::ConfirmPacket { id: message_id },
                    )?;
                }
                self.receive.last_message_id = message_id;
                Some(data)
            }
        })
    }
/// Handles incoming data. This will perform internal logic to make sure data is being transmitted correctly,
/// and requests missing packets.
///
/// Any actual data that was received, will be returned from this function.
Handles incoming data. This will perform internal logic to make sure data is being transmitted correctly,
and requests missing packets.

Any actual data that was received, will be returned from this function.
Handles incoming data . This will perform internal logic to make sure data is being transmitted correctly and requests missing packets . Any actual data that was received will be returned from this function .
pub fn handle_incoming_data(
        &mut self,
        socket: &mut dyn Socket,
        data: &[u8],
    ) -> Result<Option<TParam::TReceive>> {
        let packet: Packet<_> = bincode::deserialize(data)?;
        Ok(match packet {
            Packet::Ping {
                last_send_message_id,
            } => {
                self.resolve_incoming_ping(last_send_message_id);
                send_packet_to::<TParam::TSend>(
                    self.peer_addr,
                    socket,
                    &Packet::Pong {
                        last_send_message_id: self.send.next_message_id,
                    },
                )?;
                None
            }
            Packet::RequestPacket { id } => {
                if let Some(packet) = self.send.unconfirmed_message_cache.get_mut(&id) {
                    packet.last_emit = Instant::now();
                    send_packet_to(self.peer_addr, socket, &packet.packet)?;
                } else {
                    send_packet_to::<TParam::TSend>(
                        self.peer_addr,
                        socket,
                        &Packet::PacketNotFound { id },
                    )?;
                }
                None
            }
            Packet::ConfirmPacket { id } => {
                self.send.unconfirmed_message_cache.remove(&id);
                None
            }
            Packet::PacketNotFound { id } => {
                self.receive.missing_message_id_list.retain(|i| i.id != id);
                None
            }
            Packet::Pong {
                last_send_message_id,
            } => {
                self.resolve_incoming_ping(last_send_message_id);
                None
            }
            Packet::Data { message_id, data } => {
                if let Some(message_id) = message_id {
                    self.request_message_up_to(message_id.get() - 1);
                    send_packet_to::<TParam::TSend>(
                        self.peer_addr,
                        socket,
                        &Packet::ConfirmPacket { id: message_id },
                    )?;
                }
                self.receive.last_message_id = message_id;
                Some(data)
            }
        })
    }
pub fn handle_incoming_data ( & mut self , socket : & mut dyn Socket , data : & [ u8 ] , ) -> Result < Option < TParam :: TReceive > > { let packet : Packet < _ > = bincode :: deserialize ( data ) ? ; Ok ( match packet { Packet :: Ping { last_send_message_id , } => { self . resolve_incoming_ping ( last_send_message_id ) ; send_packet_to :: < TParam :: TSend > ( self . peer_addr , socket , & Packet :: Pong { last_send_message_id : self . send . next_message_id , } , ) ? ; None } Packet :: RequestPacket { id } => { if let Some ( packet ) = self . send . unconfirmed_message_cache . get_mut ( & id ) { packet . last_emit = Instant :: now ( ) ; send_packet_to ( self . peer_addr , socket , & packet . packet ) ? ; } else { send_packet_to :: < TParam :: TSend > ( self . peer_addr , socket , & Packet :: PacketNotFound { id } , ) ? ; } None } Packet :: ConfirmPacket { id } => { self . send . unconfirmed_message_cache . remove ( & id ) ; None } Packet :: PacketNotFound { id } => { self . receive . missing_message_id_list . retain ( | i | i . id != id ) ; None } Packet :: Pong { last_send_message_id , } => { self . resolve_incoming_ping ( last_send_message_id ) ; None } Packet :: Data { message_id , data } => { if let Some ( message_id ) = message_id { self . request_message_up_to ( message_id . get ( ) - 1 ) ; send_packet_to :: < TParam :: TSend > ( self . peer_addr , socket , & Packet :: ConfirmPacket { id : message_id } , ) ? ; } self . receive . last_message_id = message_id ; Some ( data ) } } ) }
Handles incoming data.
Handles incoming data .
&mut self
socket
&mut dyn Socket
data
&[u8]
&mut self
socket
&mut dyn Socket
data
&[u8]