MCPcopy Create free account
hub / github.com/amule-project/amule / OnPacketReceived

Method OnPacketReceived

src/ServerUDPSocket.cpp:63–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61
62
63void CServerUDPSocket::OnPacketReceived(uint32 serverip, uint16 serverport, uint8_t* buffer, size_t length)
64{
65 wxCHECK_RET(length >= 2, "Invalid packet.");
66
67 size_t nPayLoadLen = length;
68 uint8_t* pBuffer = buffer;
69 CServer* pServer = theApp->serverlist->GetServerByIPUDP(serverip, serverport, true);
70 if (pServer && thePrefs::IsServerCryptLayerUDPEnabled() &&
71 ((pServer->GetServerKeyUDP() != 0 && pServer->SupportsObfuscationUDP()) || (pServer->GetCryptPingReplyPending() && pServer->GetChallenge() != 0)))
72 {
73 // eMule TODO
74 uint32 dwKey = 0;
75 if (pServer->GetCryptPingReplyPending() && pServer->GetChallenge() != 0 /* && pServer->GetPort() == ntohs(sockAddr.sin_port) - 12 */) {
76 dwKey = pServer->GetChallenge();
77 } else {
78 dwKey = pServer->GetServerKeyUDP();
79 }
80
81 wxASSERT( dwKey != 0 );
82 nPayLoadLen = CEncryptedDatagramSocket::DecryptReceivedServer(buffer, length, &pBuffer, dwKey, serverip);
83#ifdef __DEBUG__
84 if (nPayLoadLen == length) {
85 AddDebugLogLineN(logServerUDP, CFormat("Expected encrypted packet, but received unencrytped from server %s, UDPKey %u, Challenge: %u") % pServer->GetListName() % pServer->GetServerKeyUDP() % pServer->GetChallenge());
86 } else {
87 AddDebugLogLineN(logServerUDP, CFormat("Received encrypted packet from server %s, UDPKey %u, Challenge: %u") % pServer->GetListName() % pServer->GetServerKeyUDP() % pServer->GetChallenge());
88 }
89#endif
90 }
91
92 uint8 protocol = pBuffer[0];
93 uint8 opcode = pBuffer[1];
94
95 if (protocol == OP_EDONKEYPROT) {
96 CMemFile data(pBuffer + 2, nPayLoadLen - 2);
97 ProcessPacket(data, opcode, serverip, serverport);
98 } else {
99 AddDebugLogLineN(logServerUDP, CFormat("Received invalid packet, protocol (0x%x) and opcode (0x%x)") % protocol % opcode);
100
101 theStats::AddDownOverheadOther(length);
102 }
103}
104
105
106void CServerUDPSocket::ProcessPacket(CMemFile& packet, uint8 opcode, uint32 ip, uint16 port)

Callers

nothing calls this directly

Calls 6

CFormatClass · 0.85
GetServerByIPUDPMethod · 0.80
GetServerKeyUDPMethod · 0.80
GetChallengeMethod · 0.80

Tested by

no test coverage detected