MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / startReceiver

Method startReceiver

3ds/source/transfer.cpp:580–628  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

578}
579
580bool Transfer::startReceiver(std::string& outError)
581{
582 if (!Server::isRunning()) {
583 outError = "HTTP server not available.";
584 return false;
585 }
586
587 {
588 std::lock_guard<std::mutex> lock(g_receiverMutex);
589 if (g_receiverRunning) {
590 return true;
591 }
592 }
593
594 g_failedAuthAttempts.store(0);
595 int pin = generatePin();
596 std::string token = StringUtils::format("%04d", pin);
597 std::string ip = Server::getAddress();
598 setReceiverNotice("");
599 setReceiverCompletedName("");
600 g_receiverCompleted.store(false);
601 size_t pos = ip.find("://");
602 if (pos != std::string::npos) {
603 ip = ip.substr(pos + 3);
604 }
605 pos = ip.find(":");
606 if (pos != std::string::npos) {
607 ip = ip.substr(0, pos);
608 }
609
610 // Publish token/ip/port before the handler is reachable, so an upload that
611 // arrives the instant it registers validates against the real token.
612 {
613 std::lock_guard<std::mutex> lock(g_receiverMutex);
614 g_token = token;
615 g_receiverIp = ip;
616 g_receiverPort = TRANSFER_PORT;
617 }
618
619 Server::registerHandler("/transfer/info", handleInfo);
620 Server::registerUploadHandler("/transfer/upload", TEMP_UPLOAD, handleUpload);
621
622 {
623 std::lock_guard<std::mutex> lock(g_receiverMutex);
624 g_receiverRunning = true;
625 }
626
627 return true;
628}
629
630void Transfer::stopReceiver(void)
631{

Callers

nothing calls this directly

Calls 5

generatePinFunction · 0.85
storeMethod · 0.80
findMethod · 0.80
setReceiverNoticeFunction · 0.70
setReceiverCompletedNameFunction · 0.70

Tested by

no test coverage detected