| 359 | } |
| 360 | |
| 361 | void 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 | |
| 414 | void CServerUDPSocket::SendQueue() |
nothing calls this directly
no test coverage detected