Skip to content

Commit

Permalink
Revert "Drop stale packets. Makes it harder to establish connections"
Browse files Browse the repository at this point in the history
This reverts commit 545871b.
  • Loading branch information
BernardoGomesNegri committed Dec 15, 2024
1 parent 545871b commit d7227f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
21 changes: 4 additions & 17 deletions src/libretro/net/mp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using namespace MelonDsDs;

constexpr long RECV_TIMEOUT_MS = 25;
constexpr long STALE_PACKET_TIMEOUT_US = 16'000;

uint64_t swapToNetwork(uint64_t n) {
return swap_if_little64(n);
Expand All @@ -30,8 +29,7 @@ Packet::Packet(const void *data, uint64_t len, uint64_t timestamp, uint8_t aid,
_data((unsigned char*)data, (unsigned char*)data + len),
_timestamp(timestamp),
_aid(aid),
_isReply(isReply),
_recvTime(std::clock()){
_isReply(isReply){
}

std::vector<uint8_t> Packet::ToBuf() const {
Expand All @@ -45,10 +43,6 @@ std::vector<uint8_t> Packet::ToBuf() const {
return ret;
}

uint64_t Packet::TimeDeltaUs() const noexcept {
return (std::clock() - _recvTime) * 1'000'000 / CLOCKS_PER_SEC;
}

bool MpState::IsReady() const noexcept {
return _sendFn != nullptr && _pollFn != nullptr;
}
Expand All @@ -75,16 +69,9 @@ std::optional<Packet> MpState::NextPacket() noexcept {
if(receivedPackets.empty()) {
return std::nullopt;
} else {
while(!receivedPackets.empty()) {
Packet p = receivedPackets.front();
receivedPackets.pop();
if(STALE_PACKET_TIMEOUT_US != 0 && p.TimeDeltaUs() > STALE_PACKET_TIMEOUT_US) {
retro::info("Dropping stale packet, delta is {}", p.TimeDeltaUs());
continue;
}
return p;
}
return std::nullopt;
Packet p = receivedPackets.front();
receivedPackets.pop();
return p;
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/libretro/net/mp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <optional>
#include <vector>
#include <libretro.h>
#include <ctime>

namespace MelonDsDs {
// timestamp, aid, and isReply, respectively.
Expand All @@ -30,15 +29,13 @@ class Packet {
[[nodiscard]] uint64_t Length() const noexcept {
return _data.size();
};
[[nodiscard]] uint64_t TimeDeltaUs() const noexcept;

std::vector<uint8_t> ToBuf() const;
private:
uint64_t _timestamp;
uint8_t _aid;
bool _isReply;
std::vector<uint8_t> _data;
std::clock_t _recvTime;
};

class MpState {
Expand Down

0 comments on commit d7227f2

Please sign in to comment.