Summary: NOTE: Second push of the same commit. The original was reverted because of an incompatibility with the rsocket version used in the OSS build, which is now fixed. [Step 2 of a protocol change between desktop app and agent] The flipper agent periodically tries to connect. When it doesn't have the required certs, instead of trying to connect, it requests them from the desktop. After requesting, it just continues the loop, trying to request. The problem with that is a) the desktop can take longer than one cycle to generate and provide the certs, meaning the agent will make overlapping requests, causing confusion and it to take longer than necessary. b) the desktop can take less time than a retry cycle, but the agent will still wait before trying to connect. Fixing a) by making the agent wait for a response from the desktop before continuing attempting to reconnect. This means on the next connection attempt, it's guaranteed that the desktop is finished processing the CSR. b) remains unfixed for now, but can be dealt with separately. This changes the agent to use requestResponse, instead of fireAndForget and wait for a response from Flipper before continuing. Also added a fallback to detect old versions of Flipper/Sonar and use the oldFireAndForget method in those cases. Reviewed By: danielbuechele Differential Revision: D9315946 fbshipit-source-id: 8058f7d43690ba609f16a61c0a9b40991e9e83cc
73 lines
1.7 KiB
C++
73 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2018-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
* file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Sonar/SonarInitConfig.h>
|
|
#include <Sonar/SonarWebSocket.h>
|
|
#include <Sonar/SonarState.h>
|
|
#include <folly/Executor.h>
|
|
#include <folly/io/async/EventBase.h>
|
|
#include <rsocket/RSocket.h>
|
|
#include <mutex>
|
|
|
|
namespace facebook {
|
|
namespace sonar {
|
|
|
|
class ConnectionEvents;
|
|
class Responder;
|
|
|
|
class SonarWebSocketImpl : public SonarWebSocket {
|
|
friend ConnectionEvents;
|
|
friend Responder;
|
|
|
|
public:
|
|
SonarWebSocketImpl(SonarInitConfig config, std::shared_ptr<SonarState> state);
|
|
|
|
~SonarWebSocketImpl();
|
|
|
|
void start() override;
|
|
|
|
void stop() override;
|
|
|
|
bool isOpen() const override;
|
|
|
|
void setCallbacks(Callbacks* callbacks) override;
|
|
|
|
void sendMessage(const folly::dynamic& message) override;
|
|
|
|
void reconnect();
|
|
|
|
private:
|
|
bool isOpen_ = false;
|
|
Callbacks* callbacks_;
|
|
DeviceData deviceData_;
|
|
std::shared_ptr<SonarState> sonarState_;
|
|
|
|
folly::EventBase* sonarEventBase_;
|
|
folly::EventBase* connectionEventBase_;
|
|
std::unique_ptr<rsocket::RSocketClient> client_;
|
|
bool connectionIsTrusted_;
|
|
int failedConnectionAttempts_ = 0;
|
|
|
|
void startSync();
|
|
void doCertificateExchange();
|
|
void connectSecurely();
|
|
std::string loadCSRFromFile();
|
|
std::string loadStringFromFile(std::string fileName);
|
|
std::string absoluteFilePath(const char* relativeFilePath);
|
|
bool isCertificateExchangeNeeded();
|
|
void requestSignedCertFromSonar();
|
|
bool ensureSonarDirExists();
|
|
bool isRunningInOwnThread();
|
|
void sendLegacyCertificateRequest(folly::dynamic message);
|
|
};
|
|
|
|
} // namespace sonar
|
|
} // namespace facebook
|