Files
flipper/xplat/Sonar/SonarWebSocketImpl.h
Daniel Büchele fbbf8cf16b Initial commit 🎉
fbshipit-source-id: b6fc29740c6875d2e78953b8a7123890a67930f2
Co-authored-by: Sebastian McKenzie <sebmck@fb.com>
Co-authored-by: John Knox <jknox@fb.com>
Co-authored-by: Emil Sjölander <emilsj@fb.com>
Co-authored-by: Pritesh Nandgaonkar <prit91@fb.com>
2018-06-01 11:03:58 +01:00

68 lines
1.4 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 <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);
~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_;
folly::EventBase* worker_;
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();
};
} // namespace sonar
} // namespace facebook