diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.h b/services/backup/docker-server/contents/server/src/BackupServiceImpl.h --- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.h +++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.h @@ -8,31 +8,28 @@ namespace comm { namespace network { -class BackupServiceImpl final : public backup::BackupService::Service { +class BackupServiceImpl final : public backup::BackupService::CallbackService { public: BackupServiceImpl(); virtual ~BackupServiceImpl(); - grpc::Status CreateNewBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::CreateNewBackupResponse, - backup::CreateNewBackupRequest> *stream) override; - grpc::Status SendLog( - grpc::ServerContext *context, - grpc::ServerReader *reader, + grpc::ServerBidiReactor< + backup::CreateNewBackupRequest, + backup::CreateNewBackupResponse> * + CreateNewBackup(grpc::CallbackServerContext *context) override; + + grpc::ServerReadReactor *SendLog( + grpc::CallbackServerContext *context, google::protobuf::Empty *response) override; - grpc::Status RecoverBackupKey( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::RecoverBackupKeyResponse, - backup::RecoverBackupKeyRequest> *stream) override; - grpc::Status PullBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::PullBackupResponse, - backup::PullBackupRequest> *stream) override; + + grpc::ServerBidiReactor< + backup::RecoverBackupKeyRequest, + backup::RecoverBackupKeyResponse> * + RecoverBackupKey(grpc::CallbackServerContext *context) override; + + grpc::ServerBidiReactor + *PullBackup(grpc::CallbackServerContext *context) override; }; } // namespace network diff --git a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp --- a/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp +++ b/services/backup/docker-server/contents/server/src/BackupServiceImpl.cpp @@ -1,5 +1,9 @@ #include "BackupServiceImpl.h" +#include "AuthenticationManager.h" +#include "BidiReactorBase.h" +#include "ReadReactorBase.h" + #include namespace comm { @@ -13,35 +17,106 @@ Aws::ShutdownAPI({}); } -grpc::Status BackupServiceImpl::CreateNewBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::CreateNewBackupResponse, - backup::CreateNewBackupRequest> *stream) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); +grpc::ServerBidiReactor< + backup::CreateNewBackupRequest, + backup::CreateNewBackupResponse> * +BackupServiceImpl::CreateNewBackup(grpc::CallbackServerContext *context) { + class CreateNewBackupReactor : public BidiReactorBase< + backup::CreateNewBackupRequest, + backup::CreateNewBackupResponse> { + auth::AuthenticationManager authenticationManager; + + public: + std::unique_ptr handleRequest( + backup::CreateNewBackupRequest request, + backup::CreateNewBackupResponse *response) override { + if (this->authenticationManager.getState() != + auth::AuthenticationState::SUCCESS && + !request.has_authenticationrequestdata()) { + return std::make_unique( + grpc::StatusCode::INTERNAL, + "authentication has not been finished properly"); + } + if (this->authenticationManager.getState() == + auth::AuthenticationState::FAIL) { + return std::make_unique( + grpc::StatusCode::INTERNAL, "authentication failure"); + } + if (this->authenticationManager.getState() != + auth::AuthenticationState::SUCCESS) { + backup::FullAuthenticationResponseData authResponse = + this->authenticationManager.processRequest( + request.authenticationrequestdata()); + // warning: core dumps possible, in such a case, try making the response + // a member of CreateNewBackupReactor class + response->set_allocated_authenticationresponsedata(&authResponse); + return nullptr; + } + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new CreateNewBackupReactor(); } -grpc::Status BackupServiceImpl::SendLog( - grpc::ServerContext *context, - grpc::ServerReader *reader, +grpc::ServerReadReactor *BackupServiceImpl::SendLog( + grpc::CallbackServerContext *context, google::protobuf::Empty *response) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); + class SendLogReactor : public ReadReactorBase< + backup::SendLogRequest, + google::protobuf::Empty> { + public: + using ReadReactorBase:: + ReadReactorBase; + std::unique_ptr + readRequest(backup::SendLogRequest request) override { + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new SendLogReactor(response); } -grpc::Status BackupServiceImpl::RecoverBackupKey( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::RecoverBackupKeyResponse, - backup::RecoverBackupKeyRequest> *stream) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); +grpc::ServerBidiReactor< + backup::RecoverBackupKeyRequest, + backup::RecoverBackupKeyResponse> * +BackupServiceImpl::RecoverBackupKey(grpc::CallbackServerContext *context) { + class RecoverBackupKeyReactor : public BidiReactorBase< + backup::RecoverBackupKeyRequest, + backup::RecoverBackupKeyResponse> { + public: + std::unique_ptr handleRequest( + backup::RecoverBackupKeyRequest request, + backup::RecoverBackupKeyResponse *response) override { + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new RecoverBackupKeyReactor(); } -grpc::Status BackupServiceImpl::PullBackup( - grpc::ServerContext *context, - grpc::ServerReaderWriter< - backup::PullBackupResponse, - backup::PullBackupRequest> *stream) { - return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet"); +grpc::ServerBidiReactor * +BackupServiceImpl::PullBackup(grpc::CallbackServerContext *context) { + class PullBackupReactor : public BidiReactorBase< + backup::PullBackupRequest, + backup::PullBackupResponse> { + public: + std::unique_ptr handleRequest( + backup::PullBackupRequest request, + backup::PullBackupResponse *response) override { + // TODO handle request + return std::make_unique( + grpc::StatusCode::UNIMPLEMENTED, "unimplemented"); + } + }; + + return new PullBackupReactor(); } } // namespace network