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

Method ProcessPacket

src/ServerUDPSocket.cpp:106–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104
105
106void CServerUDPSocket::ProcessPacket(CMemFile& packet, uint8 opcode, uint32 ip, uint16 port)
107{
108 CServer* update = theApp->serverlist->GetServerByIPUDP(ip, port, true);
109 unsigned size = packet.GetLength();
110
111 theStats::AddDownOverheadOther(size);
112 AddDebugLogLineN( logServerUDP,
113 CFormat( "Received UDP server packet from %s:%u, opcode (0x%x)") %
114 Uint32toStringIP(ip) % port % opcode );
115
116 try {
117 // Imported: OP_GLOBSEARCHRES, OP_GLOBFOUNDSOURCES & OP_GLOBSERVSTATRES
118 // This makes Server UDP Flags to be set correctly so we use less bandwidth on asking servers for sources
119 // Also we process Search results and Found sources correctly now on 16.40 behaviour.
120 switch(opcode){
121 case OP_GLOBSEARCHRES: {
122
123 // process all search result packets
124
125 do{
126 theApp->searchlist->ProcessUDPSearchAnswer(packet, true, ip, port - 4);
127
128 if (packet.GetPosition() + 2 < size) {
129 // An additional packet?
130 uint8 protocol = packet.ReadUInt8();
131 uint8 new_opcode = packet.ReadUInt8();
132
133 if (protocol != OP_EDONKEYPROT || new_opcode != OP_GLOBSEARCHRES) {
134 AddDebugLogLineC( logServerUDP,
135 "Server search reply got additional bogus bytes." );
136 break;
137 } else {
138 AddDebugLogLineN( logServerUDP,
139 "Got server search reply with additional packet." );
140 }
141 }
142
143 } while (packet.GetPosition()+2 < size);
144
145 break;
146 }
147 case OP_GLOBFOUNDSOURCES:{
148 // process all source packets
149 do {
150 CMD4Hash fileid = packet.ReadHash();
151 if (CPartFile* file = theApp->downloadqueue->GetFileByID(fileid)) {
152 file->AddSources(packet, ip, port-4, SF_REMOTE_SERVER, false);
153 } else {
154 AddDebugLogLineC( logServerUDP, "Sources received for unknown file" );
155 // skip sources for that file
156 uint8 count = packet.ReadUInt8();
157 packet.Seek(count*(4+2), wxFromCurrent);
158 }
159
160 if (packet.GetPosition()+2 < size) {
161 // An additional packet?
162 uint8 protocol = packet.ReadUInt8();
163 uint8 new_opcode = packet.ReadUInt8();

Callers

nothing calls this directly

Calls 15

CFormatClass · 0.85
Uint32toStringIPFunction · 0.85
GetTickCount64Function · 0.85
GetRandomUint16Function · 0.85
GetServerByIPUDPMethod · 0.80
ReadUInt8Method · 0.80
SeekMethod · 0.80
ReadUInt32Method · 0.80
GetChallengeMethod · 0.80
SetChallengeMethod · 0.80

Tested by

no test coverage detected