Page MenuHomePhabricator

D3077.id9207.diff
No OneTemporary

D3077.id9207.diff

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
@@ -1,52 +1,37 @@
#pragma once
-#include "AwsStorageManager.h"
-#include "Tools.h"
-
#include "../_generated/backup.grpc.pb.h"
#include "../_generated/backup.pb.h"
-#include <aws/core/Aws.h>
-
#include <grpcpp/grpcpp.h>
-#include <memory>
-#include <string>
-#include <unordered_map>
-#include <vector>
-
namespace comm {
namespace network {
class BackupServiceImpl final : public backup::BackupService::Service {
- const std::string bucketName = "commapp-backup";
-
- std::unique_ptr<AwsStorageManager> storageManager;
-
- std::string generateObjectName(
- const std::string &userId,
- const OBJECT_TYPE objectType) const;
public:
BackupServiceImpl();
virtual ~BackupServiceImpl();
- grpc::Status ResetKey(
+ grpc::Status CreateNewBackup(
grpc::ServerContext *context,
- grpc::ServerReader<backup::ResetKeyRequest> *reader,
+ grpc::ServerReader<backup::CreateNewBackupRequest> *reader,
google::protobuf::Empty *response) override;
grpc::Status SendLog(
grpc::ServerContext *context,
- const backup::SendLogRequest *request,
+ grpc::ServerReader<backup::SendLogRequest> *reader,
google::protobuf::Empty *response) override;
grpc::Status PullBackupKey(
grpc::ServerContext *context,
- const backup::PullBackupKeyRequest *request,
- backup::PullBackupKeyResponse *response) override;
+ grpc::ServerReaderWriter<
+ backup::PullBackupKeyResponse,
+ backup::PullBackupKeyRequest> *stream) override;
grpc::Status PullCompaction(
grpc::ServerContext *context,
- const backup::PullCompactionRequest *request,
- grpc::ServerWriter<backup::PullCompactionResponse> *writer) override;
+ grpc::ServerReaderWriter<
+ backup::PullCompactionResponse,
+ backup::PullCompactionRequest> *stream) 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,176 +1,46 @@
#include "BackupServiceImpl.h"
-#include <iostream>
+#include <aws/core/Aws.h>
namespace comm {
namespace network {
-std::string BackupServiceImpl::generateObjectName(
- const std::string &userId,
- const OBJECT_TYPE objectType) const {
- if (objectType == OBJECT_TYPE::ENCRYPTED_BACKUP_KEY) {
- return userId + "-backup-key";
- }
- if (objectType == OBJECT_TYPE::TRANSACTION_LOGS) {
- return userId + "-logs";
- }
- if (objectType == OBJECT_TYPE::COMPACTION) {
- return userId + "-compaction";
- }
- throw std::runtime_error("unhandled operation");
-}
-
BackupServiceImpl::BackupServiceImpl() {
Aws::InitAPI({});
- this->storageManager = std::make_unique<AwsStorageManager>();
- if (!this->storageManager->getBucket(this->bucketName).isAvailable()) {
- throw std::runtime_error("bucket " + this->bucketName + " not available");
- }
}
BackupServiceImpl::~BackupServiceImpl() {
Aws::ShutdownAPI({});
}
-grpc::Status BackupServiceImpl::ResetKey(
+grpc::Status BackupServiceImpl::CreateNewBackup(
grpc::ServerContext *context,
- grpc::ServerReader<backup::ResetKeyRequest> *reader,
+ grpc::ServerReader<backup::CreateNewBackupRequest> *reader,
google::protobuf::Empty *response) {
- backup::ResetKeyRequest request;
- std::string id;
- AwsS3Bucket bucket = this->storageManager->getBucket(this->bucketName);
- try {
- while (reader->Read(&request)) {
- if (!id.size()) {
- id = request.userid();
- } else if (id != request.userid()) {
- throw std::runtime_error("id mismatch: " + id + "/" + request.userid());
- }
- const std::string newKey = request.newkey();
- const std::string compactionChunk = request.compactionchunk();
- // the following behavior assumes that the client sends:
- // 1. key + empty chunk
- // 2. empty key + chunk
- // ...
- // N. empty key + chunk
- if (newKey.size()) {
- std::cout << "Backup Service => ResetKey(this log will be removed) "
- "reading key ["
- << newKey << "]" << std::endl;
- bucket.writeObject(
- this->generateObjectName(id, OBJECT_TYPE::ENCRYPTED_BACKUP_KEY),
- newKey);
- bucket.clearObject(
- this->generateObjectName(id, OBJECT_TYPE::COMPACTION));
- } else if (compactionChunk.size()) {
- std::cout << "Backup Service => ResetKey(this log will be removed) "
- "reading chunk ["
- << compactionChunk << "]" << std::endl;
- bucket.appendToObject(
- this->generateObjectName(id, OBJECT_TYPE::COMPACTION),
- compactionChunk);
- }
- }
- bucket.clearObject(
- this->generateObjectName(id, OBJECT_TYPE::TRANSACTION_LOGS));
- } catch (std::runtime_error &e) {
- std::cout << "error: " << e.what() << std::endl;
- return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
- }
- return grpc::Status::OK;
+ return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
}
grpc::Status BackupServiceImpl::SendLog(
grpc::ServerContext *context,
- const backup::SendLogRequest *request,
+ grpc::ServerReader<backup::SendLogRequest> *reader,
google::protobuf::Empty *response) {
- const std::string id = request->userid();
- const std::string data = request->data();
-
- std::cout << "Backup Service => SendLog, id:[" << id << "] data: [" << data
- << "](this log will be removed)" << std::endl;
- try {
- this->storageManager->getBucket(this->bucketName)
- .appendToObject(
- this->generateObjectName(id, OBJECT_TYPE::TRANSACTION_LOGS), data);
- } catch (std::runtime_error &e) {
- std::cout << "error: " << e.what() << std::endl;
- return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
- }
-
- return grpc::Status::OK;
+ return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
}
grpc::Status BackupServiceImpl::PullBackupKey(
grpc::ServerContext *context,
- const backup::PullBackupKeyRequest *request,
- backup::PullBackupKeyResponse *response) {
- const std::string id = request->userid();
- const std::string pakeKey = request->pakekey();
-
- std::cout << "Backup Service => PullBackupKey, id:[" << id << "] pakeKey: ["
- << pakeKey << "](this log will be removed)" << std::endl;
-
- // TODO pake operations - verify user's password with pake's keys
- try {
- std::string key = this->storageManager->getBucket(this->bucketName)
- .getObjectData(this->generateObjectName(
- id, OBJECT_TYPE::ENCRYPTED_BACKUP_KEY));
- response->set_encryptedbackupkey(key);
- } catch (std::runtime_error &e) {
- std::cout << "error: " << e.what() << std::endl;
- return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
- }
-
- return grpc::Status::OK;
+ grpc::ServerReaderWriter<
+ backup::PullBackupKeyResponse,
+ backup::PullBackupKeyRequest> *stream) {
+ return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
}
grpc::Status BackupServiceImpl::PullCompaction(
grpc::ServerContext *context,
- const backup::PullCompactionRequest *request,
- grpc::ServerWriter<backup::PullCompactionResponse> *writer) {
- const std::string id = request->userid();
-
- std::cout << "Backup Service => PullCompaction, id:[" << id
- << "](this log will be removed)" << std::endl;
- AwsS3Bucket bucket = this->storageManager->getBucket(this->bucketName);
- try {
- backup::PullCompactionResponse response;
- std::function<void(const std::string &)> callback =
- [&response, &writer](std::string chunk) {
- response.set_compactionchunk(chunk);
- if (!writer->Write(response)) {
- throw std::runtime_error("writer interrupted sending compaction");
- }
- };
-
- bucket.getObjectDataChunks(
- this->generateObjectName(id, OBJECT_TYPE::COMPACTION),
- callback,
- GRPC_CHUNK_SIZE_LIMIT);
- } catch (std::runtime_error &e) {
- std::cout << "error: " << e.what() << std::endl;
- return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
- }
- try {
- backup::PullCompactionResponse response;
- std::function<void(const std::string &)> callback =
- [&response, &writer](std::string chunk) {
- response.set_logchunk(chunk);
- if (!writer->Write(response)) {
- throw std::runtime_error("writer interrupted sending logs");
- }
- };
-
- bucket.getObjectDataChunks(
- this->generateObjectName(id, OBJECT_TYPE::TRANSACTION_LOGS),
- callback,
- GRPC_CHUNK_SIZE_LIMIT);
- } catch (std::runtime_error &e) {
- std::cout << "error: " << e.what() << std::endl;
- return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
- }
- return grpc::Status::OK;
+ grpc::ServerReaderWriter<
+ backup::PullCompactionResponse,
+ backup::PullCompactionRequest> *stream) {
+ return grpc::Status(grpc::StatusCode::UNIMPLEMENTED, "not implemented yet");
}
} // namespace network

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 1:17 PM (21 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2575493
Default Alt Text
D3077.id9207.diff (9 KB)

Event Timeline