Add state annotations in SonarWebSocketImpl
Summary: These will be displayed in the sonar diagnostics screen, for troubleshooting connection issues. Reviewed By: passy Differential Revision: D9117508 fbshipit-source-id: 6481f127b908fa539fe1fed1e268a28fa357d6f8
This commit is contained in:
committed by
Facebook Github Bot
parent
c7858c62f7
commit
195f87f5c9
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <Sonar/SonarStep.h>
|
||||||
|
|
||||||
class SonarStep;
|
class SonarStep;
|
||||||
class SonarStateUpdateListener;
|
class SonarStateUpdateListener;
|
||||||
|
|||||||
@@ -99,10 +99,11 @@ SonarWebSocketImpl::~SonarWebSocketImpl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SonarWebSocketImpl::start() {
|
void SonarWebSocketImpl::start() {
|
||||||
|
auto step = sonarState_->start("Start connection thread");
|
||||||
folly::makeFuture()
|
folly::makeFuture()
|
||||||
.via(sonarEventBase_->getEventBase())
|
.via(sonarEventBase_->getEventBase())
|
||||||
.delayed(std::chrono::milliseconds(0))
|
.delayed(std::chrono::milliseconds(0))
|
||||||
.thenValue([this](auto&&){ startSync(); });
|
.thenValue([this, step](auto&&){ step->complete(); startSync(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void SonarWebSocketImpl::startSync() {
|
void SonarWebSocketImpl::startSync() {
|
||||||
@@ -137,6 +138,7 @@ void SonarWebSocketImpl::doCertificateExchange() {
|
|||||||
"device", deviceData_.device)("app", deviceData_.app)));
|
"device", deviceData_.device)("app", deviceData_.app)));
|
||||||
address.setFromHostPort(deviceData_.host, insecurePort);
|
address.setFromHostPort(deviceData_.host, insecurePort);
|
||||||
|
|
||||||
|
auto connectingInsecurely = sonarState_->start("Connect insecurely");
|
||||||
connectionIsTrusted_ = false;
|
connectionIsTrusted_ = false;
|
||||||
client_ =
|
client_ =
|
||||||
rsocket::RSocket::createConnectedClient(
|
rsocket::RSocket::createConnectedClient(
|
||||||
@@ -148,6 +150,7 @@ void SonarWebSocketImpl::doCertificateExchange() {
|
|||||||
nullptr, // stats
|
nullptr, // stats
|
||||||
std::make_shared<ConnectionEvents>(this))
|
std::make_shared<ConnectionEvents>(this))
|
||||||
.get();
|
.get();
|
||||||
|
connectingInsecurely->complete();
|
||||||
|
|
||||||
ensureSonarDirExists();
|
ensureSonarDirExists();
|
||||||
requestSignedCertFromSonar();
|
requestSignedCertFromSonar();
|
||||||
@@ -172,6 +175,7 @@ void SonarWebSocketImpl::connectSecurely() {
|
|||||||
absoluteFilePath(PRIVATE_KEY_FILE).c_str());
|
absoluteFilePath(PRIVATE_KEY_FILE).c_str());
|
||||||
sslContext->authenticate(true, false);
|
sslContext->authenticate(true, false);
|
||||||
|
|
||||||
|
auto connectingSecurely = sonarState_->start("Connect securely");
|
||||||
connectionIsTrusted_ = true;
|
connectionIsTrusted_ = true;
|
||||||
client_ =
|
client_ =
|
||||||
rsocket::RSocket::createConnectedClient(
|
rsocket::RSocket::createConnectedClient(
|
||||||
@@ -185,6 +189,7 @@ void SonarWebSocketImpl::connectSecurely() {
|
|||||||
nullptr, // stats
|
nullptr, // stats
|
||||||
std::make_shared<ConnectionEvents>(this))
|
std::make_shared<ConnectionEvents>(this))
|
||||||
.get();
|
.get();
|
||||||
|
connectingSecurely->complete();
|
||||||
failedConnectionAttempts_ = 0;
|
failedConnectionAttempts_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +224,7 @@ void SonarWebSocketImpl::sendMessage(const folly::dynamic& message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SonarWebSocketImpl::isCertificateExchangeNeeded() {
|
bool SonarWebSocketImpl::isCertificateExchangeNeeded() {
|
||||||
|
auto step = sonarState_->start("Check required certificates are present");
|
||||||
if (failedConnectionAttempts_ >= 2) {
|
if (failedConnectionAttempts_ >= 2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -232,23 +238,29 @@ bool SonarWebSocketImpl::isCertificateExchangeNeeded() {
|
|||||||
if (caCert == "" || clientCert == "" || privateKey == "") {
|
if (caCert == "" || clientCert == "" || privateKey == "") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
step->complete();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SonarWebSocketImpl::requestSignedCertFromSonar() {
|
void SonarWebSocketImpl::requestSignedCertFromSonar() {
|
||||||
|
auto generatingCSR = sonarState_->start("Generate CSR");
|
||||||
generateCertSigningRequest(
|
generateCertSigningRequest(
|
||||||
deviceData_.appId.c_str(),
|
deviceData_.appId.c_str(),
|
||||||
absoluteFilePath(CSR_FILE_NAME).c_str(),
|
absoluteFilePath(CSR_FILE_NAME).c_str(),
|
||||||
absoluteFilePath(PRIVATE_KEY_FILE).c_str());
|
absoluteFilePath(PRIVATE_KEY_FILE).c_str());
|
||||||
|
generatingCSR->complete();
|
||||||
|
auto loadingCSR = sonarState_->start("Load CSR");
|
||||||
std::string csr = loadStringFromFile(absoluteFilePath(CSR_FILE_NAME));
|
std::string csr = loadStringFromFile(absoluteFilePath(CSR_FILE_NAME));
|
||||||
|
loadingCSR->complete();
|
||||||
|
|
||||||
folly::dynamic message = folly::dynamic::object("method", "signCertificate")(
|
folly::dynamic message = folly::dynamic::object("method", "signCertificate")(
|
||||||
"csr", csr.c_str())("destination", absoluteFilePath("").c_str());
|
"csr", csr.c_str())("destination", absoluteFilePath("").c_str());
|
||||||
sonarEventBase_->add([this, message]() {
|
auto sendingCSR = sonarState_->start("Send CSR to desktop");
|
||||||
|
sonarEventBase_->add([this, message, sendingCSR]() {
|
||||||
client_->getRequester()
|
client_->getRequester()
|
||||||
->fireAndForget(rsocket::Payload(folly::toJson(message)))
|
->fireAndForget(rsocket::Payload(folly::toJson(message)))
|
||||||
->subscribe([this]() {
|
->subscribe([this, sendingCSR]() {
|
||||||
|
sendingCSR->complete();
|
||||||
// Disconnect after message sending is complete.
|
// Disconnect after message sending is complete.
|
||||||
// This will trigger a reconnect which should use the secure channel.
|
// This will trigger a reconnect which should use the secure channel.
|
||||||
client_ = nullptr;
|
client_ = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user