From 229049b281a011a87dfd34e53f926318363b8b31 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Mon, 13 Aug 2018 02:35:05 -0700 Subject: [PATCH] Back out "[flipper] Wait for server when requesting certificate files" Summary: This breaks in open source due to a missing rsocket symbol and blocks our legocastle task. Closes https://github.com/facebook/flipper/issues/224 Original commit changeset: e782b303b5e4 Reviewed By: jknoxville, danielbuechele Differential Revision: D9289450 fbshipit-source-id: b780c300394f5793e95ef2fb6b0e6ba0150caf9a --- xplat/Sonar/SonarWebSocketImpl.cpp | 41 ++++-------------------------- xplat/Sonar/SonarWebSocketImpl.h | 1 - 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/xplat/Sonar/SonarWebSocketImpl.cpp b/xplat/Sonar/SonarWebSocketImpl.cpp index 618c93e49..0b9cd9704 100644 --- a/xplat/Sonar/SonarWebSocketImpl.cpp +++ b/xplat/Sonar/SonarWebSocketImpl.cpp @@ -255,51 +255,20 @@ void SonarWebSocketImpl::requestSignedCertFromSonar() { folly::dynamic message = folly::dynamic::object("method", "signCertificate")( "csr", csr.c_str())("destination", absoluteFilePath("").c_str()); - auto gettingCert = sonarState_->start("Getting cert from desktop"); - - sonarEventBase_->add([this, message, gettingCert]() { + auto sendingCSR = sonarState_->start("Send CSR to desktop"); + sonarEventBase_->add([this, message, sendingCSR]() { client_->getRequester() - ->requestResponse(rsocket::Payload(folly::toJson(message))) - ->subscribe([this, gettingCert](rsocket::Payload p) { - gettingCert->complete(); - SONAR_LOG("Certificate exchange complete."); + ->fireAndForget(rsocket::Payload(folly::toJson(message))) + ->subscribe([this, sendingCSR]() { + sendingCSR->complete(); // Disconnect after message sending is complete. // This will trigger a reconnect which should use the secure channel. - // TODO: Connect immediately, without waiting for reconnect client_ = nullptr; - }, - [this, message](folly::exception_wrapper e) { - e.handle( - [&](rsocket::ErrorWithPayload& errorWithPayload) { - std::string errorMessage = errorWithPayload.payload.moveDataToString(); - - if (errorMessage.compare("not implemented")) { - SONAR_LOG(("Desktop failed to provide certificates. Error from sonar desktop:\n" + errorMessage).c_str()); - } else { - sendLegacyCertificateRequest(message); - } - }, - [e](...) { - SONAR_LOG(("Error during certificate exchange:" + e.what()).c_str()); - } - ); }); }); failedConnectionAttempts_ = 0; } -void SonarWebSocketImpl::sendLegacyCertificateRequest(folly::dynamic message) { - // Desktop is using an old version of Flipper. - // Fall back to fireAndForget, instead of requestResponse. - auto sendingRequest = sonarState_->start("Sending fallback certificate request"); - client_->getRequester() - ->fireAndForget(rsocket::Payload(folly::toJson(message))) - ->subscribe([this, sendingRequest]() { - sendingRequest->complete(); - client_ = nullptr; - }); -} - std::string SonarWebSocketImpl::loadStringFromFile(std::string fileName) { if (!fileExists(fileName)) { return ""; diff --git a/xplat/Sonar/SonarWebSocketImpl.h b/xplat/Sonar/SonarWebSocketImpl.h index 6a76eaddb..b1547a94d 100644 --- a/xplat/Sonar/SonarWebSocketImpl.h +++ b/xplat/Sonar/SonarWebSocketImpl.h @@ -65,7 +65,6 @@ class SonarWebSocketImpl : public SonarWebSocket { void requestSignedCertFromSonar(); bool ensureSonarDirExists(); bool isRunningInOwnThread(); - void sendLegacyCertificateRequest(folly::dynamic message); }; } // namespace sonar