Files
flipper/xplat/Sonar/SonarWebSocketImpl.h
Pascal Hartig 229049b281 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
2018-08-13 02:41:49 -07:00

72 lines
1.6 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();
};
} // namespace sonar
} // namespace facebook