diff --git a/native/android/app/src/main/java/app/comm/android/fbjni/NetworkModule.java b/native/android/app/src/main/java/app/comm/android/fbjni/NetworkModule.java index 14bebce74..f54db7f0b 100644 --- a/native/android/app/src/main/java/app/comm/android/fbjni/NetworkModule.java +++ b/native/android/app/src/main/java/app/comm/android/fbjni/NetworkModule.java @@ -1,3 +1,5 @@ package app.comm.android.fbjni; -public class NetworkModule { public static native void sendPong(); } +public class NetworkModule { + public static native void sendPong(); +} diff --git a/scripts/get_clang_paths.js b/scripts/get_clang_paths.js index 89b74c59e..3391d74e2 100644 --- a/scripts/get_clang_paths.js +++ b/scripts/get_clang_paths.js @@ -1,60 +1,60 @@ // @flow const clangPaths = [ { path: 'native/cpp/CommonCpp', extensions: ['h', 'cpp'], excludes: ['_generated'], }, { - path: 'services/tunnelbroker/docker-server/contents/server/src', + path: 'services/tunnelbroker/src', extensions: ['cpp', 'h'], }, { - path: 'services/backup/docker-server/contents/server/src', + path: 'services/tunnelbroker/test', extensions: ['cpp', 'h'], }, { - path: 'services/backup/docker-server/contents/server/test', + path: 'services/backup/src', extensions: ['cpp', 'h'], }, { - path: 'services/backup/docker-server/contents/server/dev', + path: 'services/backup/test', extensions: ['cpp', 'h'], }, { - path: 'services/blob/docker-server/contents/server/src', + path: 'services/blob/src', extensions: ['cpp', 'h'], }, { - path: 'services/blob/docker-server/contents/server/test', + path: 'services/blob/test', extensions: ['cpp', 'h'], }, { path: 'native/android/app/src/cpp', extensions: ['cpp', 'h'], }, { path: 'native/ios/Comm', extensions: ['h', 'm', 'mm'], }, { path: 'native/ios/CommTests', extensions: ['mm'], }, { path: 'native/ios/NotificationService', extensions: ['h', 'm', 'mm'], }, { path: 'native/android/app/src/main/java/app/comm', extensions: ['java'], excludes: ['generated'], }, ]; function getClangPaths() { return clangPaths.map(pathItem => pathItem.path); } module.exports = { getClangPaths, clangPaths }; diff --git a/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h b/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h index 85ae54215..066d76110 100644 --- a/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h +++ b/services/blob/src/Reactors/server/base-reactors/ServerBidiReactorBase.h @@ -1,126 +1,126 @@ #pragma once #include +#include #include #include #include -#include namespace comm { namespace network { namespace reactor { struct ServerBidiReactorStatus { grpc::Status status; bool sendLastResponse; ServerBidiReactorStatus( grpc::Status status = grpc::Status::OK, bool sendLastResponse = false) : status(status), sendLastResponse(sendLastResponse) { } }; template class ServerBidiReactorBase : public grpc::ServerBidiReactor { Request request; Response response; std::atomic finished = false; protected: ServerBidiReactorStatus status; bool readingAborted = false; public: ServerBidiReactorBase(); void OnDone() override; void OnReadDone(bool ok) override; void OnWriteDone(bool ok) override; void terminate(ServerBidiReactorStatus status); virtual std::unique_ptr handleRequest(Request request, Response *response) = 0; virtual void initialize(){}; virtual void validate(){}; virtual void doneCallback(){}; virtual void terminateCallback(){}; }; template ServerBidiReactorBase::ServerBidiReactorBase() { this->initialize(); this->StartRead(&this->request); } template void ServerBidiReactorBase::OnDone() { this->doneCallback(); // This looks weird but apparently it is okay to do this. More information: // https://phabricator.ashoat.com/D3246#87890 delete this; } template void ServerBidiReactorBase::terminate( ServerBidiReactorStatus status) { this->status = status; try { this->terminateCallback(); this->validate(); } catch (std::runtime_error &e) { this->status = ServerBidiReactorStatus( grpc::Status(grpc::StatusCode::INTERNAL, e.what())); } if (this->finished) { return; } if (this->status.sendLastResponse) { this->StartWriteAndFinish( &this->response, grpc::WriteOptions(), this->status.status); } else { this->Finish(this->status.status); } this->finished = true; } template void ServerBidiReactorBase::OnReadDone(bool ok) { if (!ok) { this->readingAborted = true; // Ending a connection on the other side results in the `ok` flag being set // to false. It makes it impossible to detect a failure based just on the // flag. We should manually check if the data we received is valid this->terminate(ServerBidiReactorStatus(grpc::Status::OK)); return; } try { this->response = Response(); std::unique_ptr status = this->handleRequest(this->request, &this->response); if (status != nullptr) { this->terminate(*status); return; } this->StartWrite(&this->response); } catch (std::runtime_error &e) { this->terminate(ServerBidiReactorStatus( grpc::Status(grpc::StatusCode::INTERNAL, e.what()))); } } template void ServerBidiReactorBase::OnWriteDone(bool ok) { if (!ok) { this->terminate(ServerBidiReactorStatus( grpc::Status(grpc::StatusCode::ABORTED, "write failed"))); return; } this->StartRead(&this->request); } } // namespace reactor } // namespace network } // namespace comm diff --git a/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h b/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h index 94d1cfe3a..49efb664a 100644 --- a/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h +++ b/services/blob/src/Reactors/server/base-reactors/ServerReadReactorBase.h @@ -1,97 +1,97 @@ #pragma once #include +#include #include #include #include -#include namespace comm { namespace network { namespace reactor { template class ServerReadReactorBase : public grpc::ServerReadReactor { Request request; std::atomic finished = false; void terminate(grpc::Status status); protected: Response *response; grpc::Status status; public: ServerReadReactorBase(Response *response); void OnDone() override; void OnReadDone(bool ok) override; virtual std::unique_ptr readRequest(Request request) = 0; virtual void initialize(){}; virtual void validate(){}; virtual void doneCallback(){}; virtual void terminateCallback(){}; }; template void ServerReadReactorBase::terminate(grpc::Status status) { this->status = status; try { this->terminateCallback(); this->validate(); } catch (std::runtime_error &e) { this->status = grpc::Status(grpc::StatusCode::INTERNAL, e.what()); } if (!this->status.ok()) { std::cout << "error: " << this->status.error_message() << std::endl; } if (this->finished) { return; } this->Finish(this->status); this->finished = true; } template ServerReadReactorBase::ServerReadReactorBase( Response *response) : response(response) { this->initialize(); this->StartRead(&this->request); } template void ServerReadReactorBase::OnDone() { this->doneCallback(); // This looks weird but apparently it is okay to do this. More information: // https://phabricator.ashoat.com/D3246#87890 delete this; } template void ServerReadReactorBase::OnReadDone(bool ok) { if (!ok) { // Ending a connection on the other side results in the `ok` flag being set // to false. It makes it impossible to detect a failure based just on the // flag. We should manually check if the data we received is valid this->terminate(grpc::Status::OK); return; } try { std::unique_ptr status = this->readRequest(this->request); if (status != nullptr) { this->terminate(*status); return; } } catch (std::runtime_error &e) { this->terminate(grpc::Status(grpc::StatusCode::INTERNAL, e.what())); return; } this->StartRead(&this->request); } } // namespace reactor } // namespace network } // namespace comm diff --git a/services/tunnelbroker/src/Constants.h b/services/tunnelbroker/src/Constants.h index 92e14ba04..5b9da6f5a 100644 --- a/services/tunnelbroker/src/Constants.h +++ b/services/tunnelbroker/src/Constants.h @@ -1,56 +1,55 @@ #pragma once #include #include #include namespace comm { namespace network { // AWS DynamoDB const std::string DEVICE_SESSIONS_TABLE_NAME = "tunnelbroker-device-session"; const std::string DEVICE_SESSIONS_VERIFICATION_MESSAGES_TABLE_NAME = "tunnelbroker-verification-message"; const std::string DEVICE_PUBLIC_KEY_TABLE_NAME = "tunnelbroker-public-key"; const std::string MESSAGES_TABLE_NAME = "tunnelbroker-message"; // Sessions const size_t SIGNATURE_REQUEST_LENGTH = 64; const size_t SESSION_ID_LENGTH = 64; const size_t SESSION_RECORD_TTL = 30 * 24 * 3600; // 30 days const size_t SESSION_SIGN_RECORD_TTL = 24 * 3600; // 24 hours const std::regex SESSION_ID_FORMAT_REGEX( "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"); // gRPC Server const std::string SERVER_LISTEN_ADDRESS = "0.0.0.0:50051"; // AMQP (RabbitMQ) const std::string AMQP_FANOUT_EXCHANGE_NAME = "allBrokers"; // message TTL const size_t AMQP_MESSAGE_TTL = 300 * 1000; // 5 min // queue TTL in case of no consumers (tunnelbroker is down) const size_t AMQP_QUEUE_TTL = 24 * 3600 * 1000; // 24 hours // routing message headers name const std::string AMQP_HEADER_FROM_DEVICEID = "fromDeviceID"; const std::string AMQP_HEADER_TO_DEVICEID = "toDeviceID"; const std::string AMQP_HEADER_MESSAGEID = "messageID"; -const int64_t AMQP_SHORTEST_RECONNECTION_ATTEMPT_INTERVAL = - 1000 * 60; // 1 min +const int64_t AMQP_SHORTEST_RECONNECTION_ATTEMPT_INTERVAL = 1000 * 60; // 1 min // DeviceID const size_t DEVICEID_CHAR_LENGTH = 64; const std::regex DEVICEID_FORMAT_REGEX( "^(ks|mobile|web):[a-zA-Z0-9]{" + std::to_string(DEVICEID_CHAR_LENGTH) + "}$"); // Config const std::string CONFIG_FILE_PATH = std::string(std::getenv("HOME")) + "/tunnelbroker/tunnelbroker.ini"; // DeliveryBroker const size_t DELIVERY_BROKER_MAX_QUEUE_SIZE = 100; } // namespace network } // namespace comm diff --git a/services/tunnelbroker/test/TunnelBrokerTest.cpp b/services/tunnelbroker/test/TunnelBrokerTest.cpp index 8a04edc0b..d5239a302 100644 --- a/services/tunnelbroker/test/TunnelBrokerTest.cpp +++ b/services/tunnelbroker/test/TunnelBrokerTest.cpp @@ -1,21 +1,20 @@ #include -class TunnelBrokerTest : public testing::Test -{ +class TunnelBrokerTest : public testing::Test { protected: virtual void SetUp() { //... } virtual void TearDown() { //... } }; TEST_F(TunnelBrokerTest, passingTest) { EXPECT_TRUE(true); } TEST_F(TunnelBrokerTest, failingTest) { // EXPECT_TRUE(false); }