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

Method ProcessPacket

src/ClientUDPSocket.cpp:140–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

138
139
140void CClientUDPSocket::ProcessPacket(uint8_t* packet, int16 size, int8 opcode, uint32 host, uint16 port)
141{
142 switch (opcode) {
143 case OP_REASKCALLBACKUDP: {
144 AddDebugLogLineN( logClientUDP, "Client UDP socket; OP_REASKCALLBACKUDP" );
145 theStats::AddDownOverheadOther(size);
146 CUpDownClient* buddy = theApp->clientlist->GetBuddy();
147 if( buddy ) {
148 if( size < 17 || buddy->GetSocket() == NULL ) {
149 break;
150 }
151 if (!md4cmp(packet, buddy->GetBuddyID())) {
152 /*
153 The packet has an initial 16 bytes key for the buddy.
154 This is currently unused, so to make the transformation
155 we discard the first 10 bytes below and then overwrite
156 the other 6 with ip/port.
157 */
158 CMemFile mem_packet(packet+10,size-10);
159 // Change the ip and port while leaving the rest untouched
160 mem_packet.Seek(0,wxFromStart);
161 mem_packet.WriteUInt32(host);
162 mem_packet.WriteUInt16(port);
163 CPacket* response = new CPacket(mem_packet, OP_EMULEPROT, OP_REASKCALLBACKTCP);
164 AddDebugLogLineN( logClientUDP, "Client UDP socket: send OP_REASKCALLBACKTCP" );
165 theStats::AddUpOverheadFileRequest(response->GetPacketSize());
166 buddy->GetSocket()->SendPacket(response);
167 }
168 }
169 break;
170 }
171 case OP_REASKFILEPING: {
172 AddDebugLogLineN( logClientUDP, "Client UDP socket: OP_REASKFILEPING" );
173 theStats::AddDownOverheadFileRequest(size);
174
175 CMemFile data_in(packet, size);
176 CMD4Hash reqfilehash = data_in.ReadHash();
177 CKnownFile* reqfile = theApp->sharedfiles->GetFileByID(reqfilehash);
178 bool bSenderMultipleIpUnknown = false;
179 CUpDownClient* sender = theApp->uploadqueue->GetWaitingClientByIP_UDP(host, port, true, &bSenderMultipleIpUnknown);
180
181 if (!reqfile) {
182 CPacket* response = new CPacket(OP_FILENOTFOUND,0,OP_EMULEPROT);
183 theStats::AddUpOverheadFileRequest(response->GetPacketSize());
184 if (sender) {
185 SendPacket(response, host, port, sender->ShouldReceiveCryptUDPPackets(), sender->GetUserHash().GetHash(), false, 0);
186 } else {
187 SendPacket(response, host, port, false, NULL, false, 0);
188 }
189
190 break;
191 }
192
193 if (sender){
194 sender->CheckForAggressive();
195
196 //Make sure we are still thinking about the same file
197 if (reqfilehash == sender->GetUploadFileID()) {

Callers

nothing calls this directly

Calls 15

md4cmpFunction · 0.85
CFormatClass · 0.85
Uint32toStringIPFunction · 0.85
GetBuddyMethod · 0.80
GetSocketMethod · 0.80
GetBuddyIDMethod · 0.80
SeekMethod · 0.80
WriteUInt32Method · 0.80
WriteUInt16Method · 0.80
GetPacketSizeMethod · 0.80

Tested by

no test coverage detected