| 378 | return Host->Send(connection, data.Release(), PP_SYSTEM, tos, netlibaColor); |
| 379 | } |
| 380 | void ProcessIncomingPackets() { |
| 381 | TVector<TGUID, TCustomAllocator<TGUID>> failedRequests; |
| 382 | for (;;) { |
| 383 | TAutoPtr<TUdpRequest> req = Host->GetRequest(); |
| 384 | if (req.Get() == nullptr) |
| 385 | break; |
| 386 | |
| 387 | TBlockChainIterator reqData(req->Data->GetChain()); |
| 388 | char pktType; |
| 389 | reqData.Read(&pktType, 1); |
| 390 | switch (pktType) { |
| 391 | case PKT_REQUEST: |
| 392 | case PKT_LOCAL_REQUEST: { |
| 393 | TGUID reqId; |
| 394 | reqData.Read(&reqId, sizeof(reqId)); |
| 395 | |
| 396 | //printf("recv PKT_REQUEST or PKT_LOCAL_REQUEST\n"); |
| 397 | TInRequestHash::iterator z = InRequests.find(reqId); |
| 398 | if (z != InRequests.end()) { |
| 399 | // oops, this request already exists! |
| 400 | // might happen if request can be stored in single packet |
| 401 | // and this packet had source IP broken during transmission and managed to pass crc checks |
| 402 | // since we already reported wrong source address for this request to the user |
| 403 | // the best thing we can do is to stop the program to avoid further complications |
| 404 | // but we just report the accident to stderr |
| 405 | fprintf(stderr, "Jackpot, same request %s received twice from %s and earlier from %s\n", |
| 406 | GetGuidAsString(reqId).c_str(), GetAddressAsString(z->second.Connection->GetAddress()).c_str(), |
| 407 | GetAddressAsString(req->Connection->GetAddress()).c_str()); |
| 408 | } else { |
| 409 | InRequests[reqId] = TInRequestState(req->Connection); |
| 410 | //printf("InReq %s PKT_REQUEST recv ... -> S_WAITING\n", GetGuidAsString(res->ReqId).c_str()); |
| 411 | |
| 412 | CacheConnection(req->Connection); |
| 413 | |
| 414 | TUdpHttpRequest* res = new TUdpHttpRequest; |
| 415 | res->ReqId = reqId; |
| 416 | res->PeerAddress = req->Connection->GetAddress(); |
| 417 | res->DataHolder = req; |
| 418 | UserQueues->AddRequest(res); |
| 419 | } |
| 420 | } break; |
| 421 | case PKT_PING: { |
| 422 | //printf("recv PKT_PING\n"); |
| 423 | TGUID guid; |
| 424 | reqData.Read(&guid, sizeof(guid)); |
| 425 | bool ok = InRequests.find(guid) != InRequests.end(); |
| 426 | TAutoPtr<TRopeDataPacket> ms = new TRopeDataPacket; |
| 427 | ms->Write((char)PKT_PING_RESPONSE); |
| 428 | ms->Write(guid); |
| 429 | ms->Write(ok); |
| 430 | SendWithSystemPriority(req->Connection, ms.Release(), TTos(), DEFAULT_NETLIBA_COLOR); |
| 431 | //printf("InReq %s PKT_PING recv Sending PKT_PING_RESPONSE\n", GetGuidAsString(guid).c_str()); |
| 432 | //printf("got PKT_PING, responding %d\n", (int)ok); |
| 433 | } break; |
| 434 | case PKT_PING_RESPONSE: { |
| 435 | //printf("recv PKT_PING_RESPONSE\n"); |
| 436 | TGUID guid; |
| 437 | bool ok; |
nothing calls this directly
no test coverage detected