Skip to content

Commit

Permalink
server main-loop binary supported
Browse files Browse the repository at this point in the history
  • Loading branch information
algonathan committed Dec 5, 2022
1 parent c6ba581 commit f901016
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 120 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ target_link_libraries(distribicom_cpp marshal_package multiplication_utils sealp


add_executable(main1 main.cpp)
add_executable(main_server server.cpp)

set_target_properties(
main1
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/examples
)
#target_include_directories(main1 PUBLIC ${com_sealpir_SOURCE_DIR}/src)
target_link_libraries(main1 distribicom_cpp)
target_link_libraries(main_server distribicom_cpp)
207 changes: 104 additions & 103 deletions src/internals/protos/distribicom.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,85 @@ package distribicom;

// all services assumes configs: (DistribicomConfigs)
service Worker {// anyone who wishes to work runs this services.
/*
Send task is a stream that runs each round until all information in regards to the task is done.
The manager initialize the stream once the round begins, and pushes all ctxs and ptxs the worker should
use in the mat-mul operation.
once the server is done sending the data, it should close the stream.
/*
Send task is a stream that runs each round until all information in regards to the task is done.
The manager initialize the stream once the round begins, and pushes all ctxs and ptxs the worker should
use in the mat-mul operation.
once the server is done sending the data, it should close the stream.
Metadata, like round number ETC should be sent inside the stream context.
*/
rpc SendTask (stream WorkerTaskPart) returns (Ack) {};
Metadata, like round number ETC should be sent inside the stream context.
*/
rpc SendTask (stream WorkerTaskPart) returns (Ack) {};
}


// facing workers, pub/sub of work that should be done.
service Manager {// masterServer runs this service.

// PartialWorkStream i save this on my server map.
rpc RegisterAsWorker (WorkerRegistryRequest) returns (Ack) {};
// PartialWorkStream i save this on my server map.
rpc RegisterAsWorker (WorkerRegistryRequest) returns (Ack) {};

// a worker should send its work, along with credentials of what it sent.
rpc ReturnLocalWork (stream MatrixPart) returns (Ack) {};
// a worker should send its work, along with credentials of what it sent.
rpc ReturnLocalWork (stream MatrixPart) returns (Ack) {};
}


service Client {// anyone who owns a query need to run a listener for this service.
// once the round ends, and the server has an answer it should call upon this RPC call and send the answer
// to the client
rpc Answer (PirResponse) returns (Ack) {};
rpc TellNewRound (TellNewRoundRequest) returns (WriteRequest) {};
rpc Answer (PirResponse) returns (Ack) {};
rpc TellNewRound (TellNewRoundRequest) returns (WriteRequest) {};
}

// facing clients, allowing them to read and write to the server.
service Server {// masterServer runs this service.
/*
Assumes this cannot be called in the middle of a round.
/*
Assumes this cannot be called in the middle of a round.
We assume this connection is performed with a TLS secured channel to the server.
We assume this connection is performed with a TLS secured channel to the server.
Upon receiving this call, the server should create a Client instance so it'll be able to answer the client
using the `Answer` RPC call once the round is over.
Should contact this given client according to its IP.
Should contact the client with MAC with a MAC using the clients given request key.
*/
rpc RegisterAsClient (ClientRegistryRequest) returns (ClientRegistryReply) {};
Upon receiving this call, the server should create a Client instance so it'll be able to answer the client
using the `Answer` RPC call once the round is over.
Should contact this given client according to its IP.
Should contact the client with MAC with a MAC using the clients given request key.
*/
rpc RegisterAsClient (ClientRegistryRequest) returns (ClientRegistryReply) {};

/*
Once the client is done sending to the server, it should close the connection.
*/
rpc StoreQuery (ClientQueryRequest) returns (Ack) {};
/*
Anyone can write to the DB, on an unsecured channel.
Need to avoid malicious users from writing to all cells in the DB.
the server must ensure any writing is done once per
client though. (TODO: think of the proper way to do that in our system).
*/
rpc WriteToDB (WriteRequest) returns (Ack) {};
/*
Once the client is done sending to the server, it should close the connection.
*/
rpc StoreQuery (ClientQueryRequest) returns (Ack) {};
/*
Anyone can write to the DB, on an unsecured channel.
Need to avoid malicious users from writing to all cells in the DB.
the server must ensure any writing is done once per
client though. (TODO: think of the proper way to do that in our system).
*/
rpc WriteToDB (WriteRequest) returns (Ack) {};
}


message Ack {
bool success = 1; // states whether the client received all messages correctly.
bool success = 1; // states whether the client received all messages correctly.
}
message WorkerTaskPart {
oneof part {
MatrixPart matrixPart = 1;
GaloisKeys gkey = 3;
}
oneof part {
MatrixPart matrixPart = 1;
GaloisKeys gkey = 3;
}
}
message MatrixPart {
oneof data {
Ciphertext ctx = 1;
Plaintext ptx = 2;
}
oneof data {
Ciphertext ctx = 1;
Plaintext ptx = 2;
}

int32 row = 3;
int32 col = 4;
int32 row = 3;
int32 col = 4;
}

message QueryCiphertext {
bytes data = 1;
bytes data = 1;
}

message GaloisKeys{
Expand All @@ -103,113 +103,114 @@ message Plaintexts {repeated Plaintext data = 1;}

// small:
message WriteRequest {
// todo: should it be stated as row,col,ptx-part in the DB's matrix? I think it is easier to work like that...
uint64 ptxnumber = 1;
uint32 whereinptx = 2;
bytes data = 3; // 288 bytes?
// todo: should it be stated as row,col,ptx-part in the DB's matrix? I think it is easier to work like that...
uint64 ptxnumber = 1;
uint32 whereinptx = 2;
bytes data = 3; // 288 bytes?
};

message PirResponse {
repeated Ciphertext data = 1;
repeated Ciphertext data = 1;
}

message ClientQueryRequest {
repeated Ciphertext query_dim1 = 1;
repeated Ciphertext query_dim2 = 2;
uint32 mailbox_id = 3;
repeated Ciphertext query_dim1 = 1;
repeated Ciphertext query_dim2 = 2;
uint32 mailbox_id = 3;
}

message ClientRegistryRequest {
// should be used to ensure the client knows the messages are legitimate from the server.
bytes credentials = 1;
// should be used to ensure the client knows the messages are legitimate from the server.
bytes credentials = 1;

// the port the client is listening to.
uint32 client_port = 2;
// the port the client is listening to.
uint32 client_port = 2;

bytes galois_keys = 3;
bytes galois_keys = 3;
}

message ClientRegistryReply {
// should be used to ensure the server knows the messages are legitimate from the client.
bytes credentials = 1;
uint32 num_mailboxes = 2;
uint32 mailbox_id = 3; // assume this is some number mod number of elements supported in db
// should be used to ensure the server knows the messages are legitimate from the client.
bytes credentials = 1;
uint32 num_mailboxes = 2;
uint32 mailbox_id = 3; // assume this is some number mod number of elements supported in db
}

message ClientConfigs {
AppConfigs app_configs = 1;
AppConfigs app_configs = 1;

// the port the client is listening to.
uint32 client_port = 2;
// the port the client is listening to.
uint32 client_port = 2;
};


message TellNewRoundRequest {
int32 round = 1;
int32 round = 1;
}

message WorkerRegistryRequest {
// should be used to ensure the worker knows the messages are legitimate from the server.
bytes credentials = 1;
// should be used to ensure the worker knows the messages are legitimate from the server.
bytes credentials = 1;

// the port the worker is listening to.
uint32 workerPort = 2;
// the port the worker is listening to.
uint32 workerPort = 2;
}

// Every subscriber should have a certificate it created to ensure the connections from the server
// are secure
message Subscriber {
// TODO consider how to use. probably only need the sym_key.
bytes secretKey = 1;
bytes publicKey = 2;
bytes sym_key = 3;
// TODO consider how to use. probably only need the sym_key.
bytes secretKey = 1;
bytes publicKey = 2;
bytes sym_key = 3;
}


// used to group info at server to send onward to client
message QueryInfo {
uint32 client_mailbox = 1;
bytes galois_keys = 2;
ClientQueryRequest query = 3; // this is single ctx for now
};

/// configurations:

message Configs {
// encryption params
string scheme = 1;
uint32 polynomial_degree = 2;
// encryption params
string scheme = 1;
uint32 polynomial_degree = 2;

uint32 logarithm_plaintext_coefficient = 3; //logt
uint32 logarithm_plaintext_coefficient = 3; //logt

// for PIR params
uint32 db_rows = 4;
uint32 db_cols = 5;
uint32 size_per_element = 6; // element represents a position inside the plaintext that a user can write to.
uint32 dimensions = 7; // in our case defaults eqauls to 2.
// for PIR params
uint32 db_rows = 4;
uint32 db_cols = 5;
uint32 size_per_element = 6; // element represents a position inside the plaintext that a user can write to.
uint32 dimensions = 7; // in our case defaults eqauls to 2.


// legacy from sealpir
uint32 number_of_elements = 8; //number of elements packed in ptx, referred to as items in sealpir
bool use_symmetric = 9;
bool use_batching = 10;
bool use_recursive_mod_switching = 11;
// legacy from sealpir
uint32 number_of_elements = 8; //number of elements packed in ptx, referred to as items in sealpir
bool use_symmetric = 9;
bool use_batching = 10;
bool use_recursive_mod_switching = 11;
};

// all configs necessary for individual client/worker ?

message AppConfigs {
Configs configs = 1;
Configs configs = 1;

//every worker/ client will need to register to the following address:
string main_server_hostname = 2;
bytes main_server_cert = 3; // TODO: use for TLS connection.
//every worker/ client will need to register to the following address:
string main_server_hostname = 2;
bytes main_server_cert = 3; // TODO: use for TLS connection.
uint64 number_of_workers = 4;
uint64 query_wait_time = 5;
};

message WorkerConfigs {
AppConfigs appConfigs = 1;
AppConfigs appConfigs = 1;

// the port the worker is listening to.
uint32 workerPort = 2;
// the port the worker is listening to.
uint32 workerPort = 2;
};

// used to group info at server to send onward to client
message QueryInfo {
uint32 client_mailbox = 1;
bytes galois_keys = 2;
ClientQueryRequest query = 3; // this is single ctx for now
};
2 changes: 1 addition & 1 deletion src/marshal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(marshal_package marshal.hpp marshal.cpp)
add_library(marshal_package marshal.hpp marshal.cpp local_storage.hpp local_storage.cpp)

cmake_path(GET CMAKE_CURRENT_SOURCE_DIR PARENT_PATH MY_PARENT_DIR)

Expand Down
21 changes: 21 additions & 0 deletions src/marshal/local_storage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "local_storage.hpp"


std::string load_from_file(const std::filesystem::path &filename) {
std::ifstream ifs(filename);

std::string content((std::istreambuf_iterator<char>(ifs)),
(std::istreambuf_iterator<char>()));

ifs.close();
return content;
}

void dump_to_file(const std::filesystem::path &filename, const std::string &content) {

std::filesystem::create_directories(filename.parent_path());

std::ofstream ofs(filename);
ofs << content;
ofs.close();
}
7 changes: 7 additions & 0 deletions src/marshal/local_storage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#include <fstream>
#include <filesystem>

std::string load_from_file(const std::filesystem::path &filename);

void dump_to_file(const std::filesystem::path &filename, const std::string &content);
Loading

0 comments on commit f901016

Please sign in to comment.