Skip to content

Commit

Permalink
server: ledger now more organised
Browse files Browse the repository at this point in the history
  • Loading branch information
elkanatovey committed Dec 1, 2022
1 parent 558423a commit 0696f1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
29 changes: 14 additions & 15 deletions src/services/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,17 @@ services::FullServer::RegisterAsClient(grpc::ServerContext *context, const distr
)
));
auto client_info = std::make_unique<services::ClientInfo>(ClientInfo());
client_info->client_info_marshaled.set_galois_keys(request->galois_keys());

registration_mutex.lock();
if (client_stubs.find(requesting_client) == client_stubs.end()) {
client_info->client_info_marshaled.set_client_mailbox(client_counter);
id_to_mailbox.insert({requesting_client ,client_counter});
query_bookeeper.insert({client_counter, std::move(client_info)});

client_stubs.insert({requesting_client, std::move(client_conn)});
response->set_mailbox_id(client_counter);
client_counter+=1;
client_info->galois_keys_marshaled.set_keys(request->galois_keys());
client_info->client_stub = std::move(client_conn);

{ // this scope is for the unique lock do not delete!
std::unique_lock lock(client_query_manager.ledger_mutex);

client_info->galois_keys_marshaled.set_key_pos(client_query_manager.client_counter);
client_query_manager.client_query_info.insert({client_query_manager.client_counter, std::move(client_info)});
response->set_mailbox_id(client_query_manager.client_counter);
client_query_manager.client_counter+=1;
}
registration_mutex.unlock();


} catch (std::exception &e) {
Expand All @@ -79,9 +75,12 @@ grpc::Status
services::FullServer::StoreQuery(grpc::ServerContext *context, const distribicom::ClientQueryRequest *request,
distribicom::Ack *response) {

auto id = context->auth_context()->GetPeerIdentityPropertyName();
auto num_id = id_to_mailbox[id];
query_bookeeper[num_id]->client_info_marshaled.CopyFrom(*request);
auto id = request->mailbox_id();

{ // this scope is for the shared lock do not delete!
std::shared_lock lock(client_query_manager.ledger_mutex);
client_query_manager.client_query_info[id]->query_info_marshaled.CopyFrom(*request);
}
response->set_success(true);
return grpc::Status::OK;
}
Expand Down
19 changes: 12 additions & 7 deletions src/services/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ namespace services {
* ClientInfo stores objects related to an individual client
*/
struct ClientInfo {
distribicom::QueryInfo client_info_marshaled;
std::string stub_id;
distribicom::ClientQueryRequest query_info_marshaled;
distribicom::GaloisKeys galois_keys_marshaled;

PirQuery query;
seal::GaloisKeys galois_keys;
std::unique_ptr<distribicom::Client::Stub> client_stub;
};

struct ClientQueryLedger {
std::shared_mutex ledger_mutex;
std::map<std::uint32_t, std::unique_ptr<ClientInfo>> client_query_info;
std::uint64_t client_counter=0;
};


// uses both the Manager and the Server services to complete a full distribicom server.
class FullServer final : public distribicom::Server::Service{
// used for tests
Expand All @@ -35,11 +44,7 @@ namespace services {
std::unique_ptr<PIRClient> client;

// concurrency stuff
std::map<std::string, std::unique_ptr<distribicom::Client::Stub>> client_stubs;
std::map<std::string, std::uint32_t> id_to_mailbox;
std::map<std::uint32_t, std::unique_ptr<ClientInfo>> query_bookeeper;
std::mutex registration_mutex;
std::uint64_t client_counter=0;
ClientQueryLedger client_query_manager;



Expand Down

0 comments on commit 0696f1a

Please sign in to comment.