Make packet duplication checking more intelligent by checking hashes

This commit is contained in:
MysterD 2021-08-25 18:05:36 -07:00
parent a081327ef1
commit 401e6169d5
4 changed files with 7 additions and 4 deletions

View file

@ -214,7 +214,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
snprintf(np->name, MAX_PLAYER_STRING, "%s", name);
network_player_update_model(0);
for (int j = 0; j < MAX_RX_SEQ_IDS; j++) { np->rxSeqIds[j] = 0; }
for (int j = 0; j < MAX_RX_SEQ_IDS; j++) { np->rxSeqIds[j] = 0; np->rxPacketHash[j] = 0; }
np->onRxSeqId = 0;
gNetworkPlayerLocal = np;
@ -272,7 +272,7 @@ u8 network_player_connected(enum NetworkPlayerType type, u8 globalIndex, u8 mode
network_player_update_model(i);
if (gNetworkType == NT_SERVER || type == NPT_SERVER) { gNetworkSystem->save_id(i, 0); }
for (int j = 0; j < MAX_SYNC_OBJECTS; j++) { gSyncObjects[j].rxEventId[i] = 0; }
for (int j = 0; j < MAX_RX_SEQ_IDS; j++) { np->rxSeqIds[j] = 0; }
for (int j = 0; j < MAX_RX_SEQ_IDS; j++) { np->rxSeqIds[j] = 0; np->rxPacketHash[j] = 0; }
np->onRxSeqId = 0;
if (type == NPT_SERVER) {
gNetworkPlayerServer = np;

View file

@ -39,6 +39,7 @@ struct NetworkPlayer {
bool localLevelMatch;
char name[MAX_PLAYER_STRING];
u16 rxSeqIds[MAX_RX_SEQ_IDS];
u16 rxPacketHash[MAX_RX_SEQ_IDS];
};
extern struct NetworkPlayer gNetworkPlayers[];

View file

@ -100,15 +100,17 @@ void packet_receive(struct Packet* p) {
// check if we've already seen this packet
if (p->localIndex != 0 && p->seqId != 0 && gNetworkPlayers[p->localIndex].connected) {
u32 packetHash = packet_hash(p);
struct NetworkPlayer* np = &gNetworkPlayers[p->localIndex];
for (int i = 0; i < MAX_RX_SEQ_IDS; i++) {
if (np->rxSeqIds[i] == p->seqId) {
if (np->rxSeqIds[i] == p->seqId && np->rxPacketHash[i] == packetHash) {
LOG_INFO("received duplicate packet");
return;
}
}
// remember seq id
np->rxSeqIds[np->onRxSeqId] = p->seqId;
np->rxPacketHash[np->onRxSeqId] = packetHash;
np->onRxSeqId++;
if (np->onRxSeqId >= MAX_RX_SEQ_IDS) { np->onRxSeqId = 0; }
}

View file

@ -162,8 +162,8 @@ void network_receive_level_macro(struct Packet* p) {
if (o->oSyncID != 0) {
struct SyncObject* so = &gSyncObjects[o->oSyncID];
if (so->o == o) {
LOG_INFO("rx macro deletion: sync object (id %d)", o->oSyncID);
network_forget_sync_object(so);
LOG_INFO("rx macro deletion: sync object");
}
}
}