MCPcopy Create free account
hub / github.com/chrxh/alien / downloadResource

Method downloadResource

source/Network/NetworkService.cpp:556–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

554}
555
556bool NetworkService::downloadResource(std::string& mainData, std::string& auxiliaryData, std::string& statistics, std::string const& simId)
557{
558 try {
559 if (auto cachedEntry = _downloadCache.find(simId)) {
560 log(Priority::Important, "network: get resource with id=" + simId + " from download cache");
561 mainData = cachedEntry->content;
562 auxiliaryData = cachedEntry->auxiliaryData;
563 statistics = cachedEntry->statistics;
564 incDownloadCounter(simId);
565 return true;
566 } else {
567 log(Priority::Important, "network: download resource with id=" + simId);
568
569 httplib::SSLClient client(_serverAddress);
570 configureClient(client);
571
572 httplib::Params params;
573 params.emplace("id", simId);
574 {
575
576 for (int chunkIndex = 0; chunkIndex < 6; ++chunkIndex) {
577 auto paramsClone = params;
578 paramsClone.emplace("chunkIndex", std::to_string(chunkIndex));
579 auto result = executeRequest([&] { return client.Get("/alien-server/downloadcontent.php", paramsClone, {}); });
580 if (result->body.empty()) {
581 break;
582 }
583 mainData.append(result->body);
584 }
585 }
586 {
587 auto result = executeRequest([&] { return client.Get("/alien-server/downloadsettings.php", params, {}); });
588 auxiliaryData = result->body;
589 }
590 {
591 auto result = executeRequest([&] { return client.Get("/alien-server/downloadstatistics.php", params, {}); });
592 statistics = result->body;
593 }
594 _downloadCache.insertOrAssign(simId, ResourceData{mainData, auxiliaryData, statistics});
595 return true;
596 }
597 } catch (...) {
598 logNetworkError();
599 return false;
600 }
601}
602
603void NetworkService::incDownloadCounter(std::string const& simId)
604{

Callers 1

processRequestMethod · 0.80

Calls 9

logFunction · 0.85
configureClientFunction · 0.85
to_stringFunction · 0.85
executeRequestFunction · 0.85
logNetworkErrorFunction · 0.85
findMethod · 0.80
appendMethod · 0.80
insertOrAssignMethod · 0.80
GetMethod · 0.45

Tested by

no test coverage detected