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

Method SendPacket

src/ServerUDPSocket.cpp:361–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361void CServerUDPSocket::SendPacket(CPacket* packet, CServer* host, bool delPacket, bool rawpacket, uint16 port_offset)
362{
363 ServerUDPPacket item = { NULL, 0, 0, "" };
364
365 if (host->HasDynIP()) {
366 item.addr = host->GetDynIP();
367 } else {
368 item.ip = host->GetIP();
369 }
370
371 // 4 (default) for standard sending, 12 for obfuscated ping, that's all for now.
372 // Might be changed if encrypted below, so don't move it.
373 item.port = host->GetPort() + port_offset;
374
375 // We might need to encrypt the packet for this server.
376 if (!rawpacket && thePrefs::IsServerCryptLayerUDPEnabled() && host->GetServerKeyUDP() != 0 && host->SupportsObfuscationUDP()) {
377 uint16 uRawPacketSize = packet->GetPacketSize() + 2;
378 uint8_t* pRawPacket = new uint8_t[uRawPacketSize];
379 memcpy(pRawPacket, packet->GetUDPHeader(), 2);
380 memcpy(pRawPacket + 2, packet->GetDataBuffer(), packet->GetPacketSize());
381
382 uRawPacketSize = CEncryptedDatagramSocket::EncryptSendServer(&pRawPacket, uRawPacketSize, host->GetServerKeyUDP());
383 AddDebugLogLineN(logServerUDP, CFormat("Sending encrypted packet to server %s, UDPKey %u, port %u, original OPCode 0x%02x") % host->GetListName() % host->GetServerKeyUDP() % host->GetObfuscationPortUDP() % packet->GetOpCode());
384 item.port = host->GetObfuscationPortUDP();
385
386 CMemFile encryptedpacket(pRawPacket + 2, uRawPacketSize - 2);
387 item.packet = new CPacket(encryptedpacket, pRawPacket[0], pRawPacket[1]);
388 delete[] pRawPacket;
389
390 if (delPacket) {
391 delete packet;
392 }
393
394 } else {
395 AddDebugLogLineN(logServerUDP, CFormat("Sending regular packet to server %s, port %u (raw = %s), OPCode 0x%02x") % host->GetListName() % host->GetObfuscationPortUDP() % (rawpacket ? "True" : "False") % packet->GetOpCode());
396 if (delPacket) {
397 item.packet = packet;
398 } else {
399 item.packet = new CPacket(*packet);
400 }
401 }
402
403
404 m_queue.push_back(item);
405
406 // If there is more than one item in the queue,
407 // then we are already waiting for a dns query.
408 if (m_queue.size() == 1) {
409 SendQueue();
410 }
411}
412
413
414void CServerUDPSocket::SendQueue()

Callers

nothing calls this directly

Calls 12

CFormatClass · 0.85
HasDynIPMethod · 0.80
GetServerKeyUDPMethod · 0.80
GetPacketSizeMethod · 0.80
GetUDPHeaderMethod · 0.80
GetDataBufferMethod · 0.80
GetObfuscationPortUDPMethod · 0.80
GetIPMethod · 0.45
GetPortMethod · 0.45
GetOpCodeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected