aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-04-30 16:30:47 +0200
committerlonkaars <loek@pipeframe.xyz>2024-04-30 16:30:47 +0200
commit562964df547e9cdbb3ee32edae5592ab5a513b25 (patch)
tree6664707633f87ceb76e0d3b5c0fcdf0a1883d7ad /src
parent4732f4233313a4150370c0b866335ef4eca3a026 (diff)
tweak packet dumper
Diffstat (limited to 'src')
-rw-r--r--src/frontend/qt_sdl/LocalMP.cpp60
1 files changed, 40 insertions, 20 deletions
diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp
index b90ff05..cc42706 100644
--- a/src/frontend/qt_sdl/LocalMP.cpp
+++ b/src/frontend/qt_sdl/LocalMP.cpp
@@ -41,8 +41,11 @@
#include <pcap/pcap.h>
#include <time.h>
+#include <vector>
+#include <stdint.h>
pcap_dumper_t* dumper;
+unsigned long test_start = time(NULL);
using namespace melonDS;
using namespace melonDS::Platform;
@@ -76,15 +79,6 @@ struct MPPacketHeader
u64 Timestamp;
};
-struct MPSync
-{
- u32 Magic;
- u32 SenderID;
- u16 ClientMask;
- u16 Type;
- u64 Timestamp;
-};
-
QSharedMemory* MPQueue;
int InstanceID;
u32 PacketReadOffset;
@@ -399,11 +393,13 @@ void FIFORead(int fifo, void* buf, int len)
if (fifo == 0) PacketReadOffset = offset;
else ReplyReadOffset = offset;
- struct pcap_pkthdr p;
- p.len = len;
- p.caplen = len;
- gettimeofday(&p.ts, NULL);
- pcap_dump((u_char*) dumper, &p, (u_char*) buf);
+ // WIP: temporarily capture sent packets only, capture is done on both
+ // sides anyways, so who cares
+ // struct pcap_pkthdr p;
+ // p.len = len;
+ // p.caplen = len;
+ // gettimeofday(&p.ts, NULL);
+ // pcap_dump((u_char*) dumper, &p, (u_char*) buf);
}
void FIFOWrite(int fifo, void* buf, int len)
@@ -440,12 +436,6 @@ void FIFOWrite(int fifo, void* buf, int len)
if (fifo == 0) header->PacketWriteOffset = offset;
else header->ReplyWriteOffset = offset;
-
- struct pcap_pkthdr p;
- p.len = len;
- p.caplen = len;
- gettimeofday(&p.ts, NULL);
- pcap_dump((u_char*) dumper, &p, (u_char*) buf);
}
int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)
@@ -457,6 +447,17 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)
u16 mask = header->ConnectedBitmask;
+ // // packet dropping test
+ // unsigned long now = time(NULL);
+ // static bool first = true;
+ // bool dropping = false;
+ // if (now - test_start > 20 && InstanceID == 0) {
+ // if (first == true)
+ // printf("[INSTANCE %d] started dropping packets!\n", InstanceID);
+ // first = false;
+ // dropping = true;
+ // }
+
// TODO: check if the FIFO is full!
MPPacketHeader pktheader;
@@ -466,11 +467,30 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp)
pktheader.Length = len;
pktheader.Timestamp = timestamp;
+ std::vector<uint8_t> buf;
+
type &= 0xFFFF;
int nfifo = (type == 2) ? 1 : 0;
+ // NOTE: this is the ni-fi packet header, altering this header in any way
+ // seems to consistently trigger PACKET FIFO OVERFLOW errors
FIFOWrite(nfifo, &pktheader, sizeof(pktheader));
+ buf.insert(buf.end(), (uint8_t*) &pktheader, (uint8_t*) &pktheader + sizeof(pktheader));
if (len)
+ {
+ // // replace packet content with random noise while dropping
+ // if (dropping)
+ // for (size_t i = 0; i < len; i++)
+ // packet[i] = rand();
+
+ buf.insert(buf.end(), (uint8_t*) packet, (uint8_t*) packet + len);
FIFOWrite(nfifo, packet, len);
+ }
+
+ struct pcap_pkthdr p;
+ p.len = buf.size();
+ p.caplen = buf.size();
+ gettimeofday(&p.ts, NULL);
+ pcap_dump((u_char*) dumper, &p, buf.data());
if (type == 1)
{