|
@@ -1,4 +1,5 @@
|
|
|
#include <iostream>
|
|
|
+#include <fstream>
|
|
|
#include <sstream>
|
|
|
#include <cstring>
|
|
|
#include <cstdio>
|
|
@@ -40,7 +41,7 @@ void obtain_update_locks(
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- unique_lock<mutex> lck(sync->mtx);
|
|
|
+ std::unique_lock<std::mutex> lck(sync->mtx);
|
|
|
sync->val = 0;
|
|
|
sync->val2 = 0;
|
|
|
mg_websocket_client_write(
|
|
@@ -94,7 +95,7 @@ void release_update_locks(
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- unique_lock<mutex> lck(sync->mtx);
|
|
|
+ std::unique_lock<std::mutex> lck(sync->mtx);
|
|
|
sync->val = 0;
|
|
|
sync->val2 = 0;
|
|
|
mg_websocket_client_write(
|
|
@@ -134,7 +135,7 @@ void read_epoch_initiator_string(
|
|
|
std::vector<Proof>& generatorProof,
|
|
|
Twistpoint& nextGenerator)
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
BinarySizeT sizeOfVector;
|
|
|
|
|
|
generatorProof.clear();
|
|
@@ -145,7 +146,7 @@ void read_epoch_initiator_string(
|
|
|
Proof currProof;
|
|
|
file >> currProof;
|
|
|
|
|
|
- generatorProof.push_back;
|
|
|
+ generatorProof.push_back(currProof);
|
|
|
}
|
|
|
|
|
|
file >> nextGenerator;
|
|
@@ -258,7 +259,7 @@ bool read_epoch_update_string(
|
|
|
std::vector<std::vector<Twistpoint>>& userTallySeedCommits,
|
|
|
Twistpoint& nextGenerator)
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
BinarySizeT sizeOfVectorI, sizeOfVectorJ;
|
|
|
|
|
|
pi.clear();
|
|
@@ -444,7 +445,7 @@ void distribute_epoch_updates(
|
|
|
{
|
|
|
struct mg_connection *conn =
|
|
|
mg_connect_websocket_client(
|
|
|
- serverIPs[i].c_str(),
|
|
|
+ recipient.c_str(),
|
|
|
PRSONA_PORT,
|
|
|
USE_SSL,
|
|
|
NULL,
|
|
@@ -484,16 +485,16 @@ void distribute_epoch_updates(
|
|
|
*/
|
|
|
|
|
|
PrsonaServerWebSocketHandler::PrsonaServerWebSocketHandler(
|
|
|
- const PrsonaServer *prsonaServer,
|
|
|
- const std::mutex *updateMtx,
|
|
|
- const std::atomic<size_t> *epochNum,
|
|
|
+ PrsonaServer *prsonaServer,
|
|
|
+ std::mutex *updateMtx,
|
|
|
+ std::atomic<size_t> *epochNum,
|
|
|
const std::vector<std::string> &serverIPs,
|
|
|
const std::string &selfIP)
|
|
|
: prsonaServer(prsonaServer), updateMtx(updateMtx), epochNum(epochNum),
|
|
|
serverIPs(serverIPs), selfIP(selfIP)
|
|
|
{ /* */ }
|
|
|
|
|
|
-virtual bool PrsonaServerWebSocketHandler::handleConnection(
|
|
|
+bool PrsonaServerWebSocketHandler::handleConnection(
|
|
|
CivetServer *server,
|
|
|
const struct mg_connection *conn)
|
|
|
{
|
|
@@ -506,7 +507,7 @@ virtual bool PrsonaServerWebSocketHandler::handleConnection(
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
-virtual void PrsonaServerWebSocketHandler::handleReadyState(
|
|
|
+void PrsonaServerWebSocketHandler::handleReadyState(
|
|
|
CivetServer *server,
|
|
|
struct mg_connection *conn)
|
|
|
{
|
|
@@ -538,7 +539,7 @@ virtual void PrsonaServerWebSocketHandler::handleReadyState(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-virtual bool PrsonaServerWebSocketHandler::handleData(
|
|
|
+bool PrsonaServerWebSocketHandler::handleData(
|
|
|
CivetServer *server,
|
|
|
struct mg_connection *conn,
|
|
|
int bits,
|
|
@@ -568,7 +569,7 @@ virtual bool PrsonaServerWebSocketHandler::handleData(
|
|
|
|
|
|
void PrsonaServerWebSocketHandler::generate_response(
|
|
|
struct mg_connection *conn,
|
|
|
- char *filename)
|
|
|
+ const char *filename)
|
|
|
{
|
|
|
const struct mg_request_info *info = mg_get_request_info(conn);
|
|
|
|
|
@@ -579,7 +580,7 @@ void PrsonaServerWebSocketHandler::generate_response(
|
|
|
break;
|
|
|
|
|
|
case PRSONA_RECEIVE_VOTE:
|
|
|
- receive_vote(filename);
|
|
|
+ receive_vote(conn, filename);
|
|
|
break;
|
|
|
|
|
|
case PRSONA_GET_BGN_PUBKEY:
|
|
@@ -655,15 +656,15 @@ void PrsonaServerWebSocketHandler::generate_response(
|
|
|
break;
|
|
|
|
|
|
case PRSONA_EPOCH_BUILD_UP:
|
|
|
- build_up_midway_pseudonyms(conn);
|
|
|
+ build_up_midway_pseudonyms(conn, filename);
|
|
|
break;
|
|
|
|
|
|
case PRSONA_EPOCH_BREAK_DOWN:
|
|
|
- break_down_midway_pseudonyms(conn);
|
|
|
+ break_down_midway_pseudonyms(conn, filename);
|
|
|
break;
|
|
|
|
|
|
case PRSONA_EPOCH_UPDATE:
|
|
|
- accept_epoch_updates(filename);
|
|
|
+ accept_epoch_updates(conn, filename);
|
|
|
break;
|
|
|
|
|
|
case PRSONA_NEW_USER_UPDATE:
|
|
@@ -671,7 +672,7 @@ void PrsonaServerWebSocketHandler::generate_response(
|
|
|
break;
|
|
|
|
|
|
case PRSONA_GET_PARTIAL_DECRYPTION:
|
|
|
- get_partial_decryption(conn, filename);
|
|
|
+ get_partial_decryption(conn);
|
|
|
break;
|
|
|
|
|
|
case PRSONA_RECEIVE_PARTIAL_DECRYPTION:
|
|
@@ -691,7 +692,7 @@ void PrsonaServerWebSocketHandler::generate_response(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-virtual void PrsonaServerWebSocketHandler::handleClose(
|
|
|
+void PrsonaServerWebSocketHandler::handleClose(
|
|
|
CivetServer *server,
|
|
|
const struct mg_connection *conn)
|
|
|
{
|
|
@@ -753,7 +754,7 @@ void PrsonaServerWebSocketHandler::get_num_servers(
|
|
|
void PrsonaServerWebSocketHandler::get_current_votes_by(
|
|
|
struct mg_connection *conn, const char *filename) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint shortTermPublicKey;
|
|
|
file >> shortTermPublicKey;
|
|
@@ -803,7 +804,7 @@ void PrsonaServerWebSocketHandler::get_all_current_votes(
|
|
|
void PrsonaServerWebSocketHandler::get_current_user_encrypted_tally(
|
|
|
struct mg_connection *conn, const char *filename) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint shortTermPublicKey;
|
|
|
file >> shortTermPublicKey;
|
|
@@ -826,7 +827,7 @@ void PrsonaServerWebSocketHandler::get_current_user_encrypted_tally(
|
|
|
void PrsonaServerWebSocketHandler::get_current_server_encrypted_tally(
|
|
|
struct mg_connection *conn, const char *filename) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint shortTermPublicKey;
|
|
|
file >> shortTermPublicKey;
|
|
@@ -875,7 +876,7 @@ void PrsonaServerWebSocketHandler::get_current_pseudonyms(
|
|
|
void PrsonaServerWebSocketHandler::get_vote_row_commitment(
|
|
|
struct mg_connection *conn, const char *filename) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint shortTermPublicKey;
|
|
|
file >> shortTermPublicKey;
|
|
@@ -912,7 +913,7 @@ void PrsonaServerWebSocketHandler::get_vote_matrix_commitment(
|
|
|
void PrsonaServerWebSocketHandler::get_user_tally_commitment(
|
|
|
struct mg_connection *conn, const char *filename) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint shortTermPublicKey;
|
|
|
file >> shortTermPublicKey;
|
|
@@ -933,7 +934,7 @@ void PrsonaServerWebSocketHandler::get_user_tally_commitment(
|
|
|
void PrsonaServerWebSocketHandler::get_server_tally_commitment(
|
|
|
struct mg_connection *conn, const char *filename) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint shortTermPublicKey;
|
|
|
file >> shortTermPublicKey;
|
|
@@ -974,6 +975,8 @@ void PrsonaServerWebSocketHandler::distribute_new_user_updates(
|
|
|
std::vector<EGCiphertext> currentUserEncryptedTallies,
|
|
|
std::vector<std::vector<TwistBipoint>> voteMatrix) const
|
|
|
{
|
|
|
+ struct synchronization_tool distributeSync;
|
|
|
+
|
|
|
std::stringstream buffer;
|
|
|
std::string data;
|
|
|
BinarySizeT sizeOfVector;
|
|
@@ -1023,7 +1026,7 @@ void PrsonaServerWebSocketHandler::distribute_new_user_updates(
|
|
|
"null",
|
|
|
synchro_websocket_data_handler,
|
|
|
synchro_websocket_close_handler,
|
|
|
- (void *) distributeSync);
|
|
|
+ (void *) &distributeSync);
|
|
|
|
|
|
if (!conn)
|
|
|
{
|
|
@@ -1031,30 +1034,32 @@ void PrsonaServerWebSocketHandler::distribute_new_user_updates(
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- unique_lock<mutex> syncLock(distributeSync->mtx);
|
|
|
- distributeSync->val = 0;
|
|
|
- distributeSync->val2 = 0;
|
|
|
+ std::unique_lock<std::mutex> syncLock(distributeSync.mtx);
|
|
|
+ distributeSync.val = 0;
|
|
|
+ distributeSync.val2 = 0;
|
|
|
mg_websocket_client_write(
|
|
|
conn,
|
|
|
MG_WEBSOCKET_OPCODE_BINARY,
|
|
|
data.c_str(),
|
|
|
data.length());
|
|
|
|
|
|
- while (!distributeSync->val2)
|
|
|
- distributeSync->cv.wait(syncLock);
|
|
|
+ while (!distributeSync.val2)
|
|
|
+ distributeSync.cv.wait(syncLock);
|
|
|
|
|
|
mg_close_connection(conn);
|
|
|
|
|
|
- if (distributeSync->val)
|
|
|
+ if (distributeSync.val)
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void PrsonaServerWebSocketHandler::distribute_new_vote(
|
|
|
- std::vector<Proof> pi;
|
|
|
+ std::vector<Proof> pi,
|
|
|
std::vector<TwistBipoint> newVotes,
|
|
|
Twistpoint shortTermPublicKey) const
|
|
|
{
|
|
|
+ struct synchronization_tool distributeSync;
|
|
|
+
|
|
|
std::stringstream buffer;
|
|
|
std::string data;
|
|
|
BinarySizeT sizeOfVector;
|
|
@@ -1093,7 +1098,7 @@ void PrsonaServerWebSocketHandler::distribute_new_vote(
|
|
|
"null",
|
|
|
synchro_websocket_data_handler,
|
|
|
synchro_websocket_close_handler,
|
|
|
- (void *) distributeSync);
|
|
|
+ (void *) &distributeSync);
|
|
|
|
|
|
if (!conn)
|
|
|
{
|
|
@@ -1101,21 +1106,21 @@ void PrsonaServerWebSocketHandler::distribute_new_vote(
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- unique_lock<mutex> syncLock(distributeSync->mtx);
|
|
|
- distributeSync->val = 0;
|
|
|
- distributeSync->val2 = 0;
|
|
|
+ std::unique_lock<std::mutex> syncLock(distributeSync.mtx);
|
|
|
+ distributeSync.val = 0;
|
|
|
+ distributeSync.val2 = 0;
|
|
|
mg_websocket_client_write(
|
|
|
conn,
|
|
|
MG_WEBSOCKET_OPCODE_BINARY,
|
|
|
data.c_str(),
|
|
|
data.length());
|
|
|
|
|
|
- while (!distributeSync->val2)
|
|
|
- distributeSync->cv.wait(syncLock);
|
|
|
+ while (!distributeSync.val2)
|
|
|
+ distributeSync.cv.wait(syncLock);
|
|
|
|
|
|
mg_close_connection(conn);
|
|
|
|
|
|
- if (distributeSync->val)
|
|
|
+ if (distributeSync.val)
|
|
|
i++;
|
|
|
}
|
|
|
}
|
|
@@ -1127,7 +1132,9 @@ void PrsonaServerWebSocketHandler::distribute_new_vote(
|
|
|
void PrsonaServerWebSocketHandler::add_new_client(
|
|
|
struct mg_connection *conn, const char *filename)
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ struct synchronization_tool updateSync;
|
|
|
+
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Proof proofOfValidKey;
|
|
|
file >> proofOfValidKey;
|
|
@@ -1171,6 +1178,9 @@ void PrsonaServerWebSocketHandler::add_new_client(
|
|
|
selfIP,
|
|
|
&updateSync);
|
|
|
|
|
|
+ std::stringstream buffer;
|
|
|
+ std::string data;
|
|
|
+
|
|
|
BinarySizeT sizeOfVector(proofOfValidAddition.size());
|
|
|
buffer << sizeOfVector;
|
|
|
for (size_t i = 0; i < sizeOfVector.val(); i++)
|
|
@@ -1182,9 +1192,11 @@ void PrsonaServerWebSocketHandler::add_new_client(
|
|
|
}
|
|
|
|
|
|
void PrsonaServerWebSocketHandler::receive_vote(
|
|
|
- const char *filename)
|
|
|
+ struct mg_connection *conn, const char *filename)
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ struct synchronization_tool distributeSync;
|
|
|
+
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
BinarySizeT sizeOfVector;
|
|
|
file >> sizeOfVector;
|
|
@@ -1264,7 +1276,7 @@ void PrsonaServerWebSocketHandler::get_bgn_details(
|
|
|
void PrsonaServerWebSocketHandler::add_seed_to_generator(
|
|
|
struct mg_connection *conn, const char *filename, bool fresh) const
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
Twistpoint currGenerator;
|
|
|
file >> currGenerator;
|
|
@@ -1295,7 +1307,7 @@ void PrsonaServerWebSocketHandler::add_seed_to_generator(
|
|
|
void PrsonaServerWebSocketHandler::set_generator(
|
|
|
const char *filename, bool fresh)
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
BinarySizeT sizeOfVector;
|
|
|
file >> sizeOfVector;
|
|
@@ -1358,7 +1370,7 @@ void PrsonaServerWebSocketHandler::build_up_midway_pseudonyms(
|
|
|
|
|
|
std::vector<std::vector<Twistpoint>> userTallyMaskCommits, userTallyMessageCommits, userTallySeedCommits;
|
|
|
|
|
|
- string data =
|
|
|
+ std::string data =
|
|
|
make_epoch_update_string(
|
|
|
pi[1],
|
|
|
permutationCommits[0],
|
|
@@ -1374,7 +1386,7 @@ void PrsonaServerWebSocketHandler::build_up_midway_pseudonyms(
|
|
|
false);
|
|
|
|
|
|
struct synchronization_tool epochSync;
|
|
|
- epochSync->val = 1;
|
|
|
+ epochSync.val = 1;
|
|
|
for (size_t i = 0; i < serverIPs.size(); i++)
|
|
|
{
|
|
|
if (serverIPs[i] == selfIP)
|
|
@@ -1386,7 +1398,7 @@ void PrsonaServerWebSocketHandler::build_up_midway_pseudonyms(
|
|
|
&epochSync);
|
|
|
}
|
|
|
|
|
|
- unique_lock<mutex> lck(epochSync);
|
|
|
+ std::unique_lock<std::mutex> lck(epochSync.mtx);
|
|
|
while (epochSync.val < serverIPs.size())
|
|
|
epochSync.cv.wait(lck);
|
|
|
|
|
@@ -1434,7 +1446,7 @@ void PrsonaServerWebSocketHandler::break_down_midway_pseudonyms(
|
|
|
userTallySeedCommits,
|
|
|
nextGenerator);
|
|
|
|
|
|
- string data =
|
|
|
+ std::string data =
|
|
|
make_epoch_update_string(
|
|
|
pi[0],
|
|
|
permutationCommits[0],
|
|
@@ -1462,7 +1474,7 @@ void PrsonaServerWebSocketHandler::break_down_midway_pseudonyms(
|
|
|
&epochSync);
|
|
|
}
|
|
|
|
|
|
- unique_lock<mutex> lck(epochSync.mtx);
|
|
|
+ std::unique_lock<std::mutex> lck(epochSync.mtx);
|
|
|
while (epochSync.val < serverIPs.size())
|
|
|
epochSync.cv.wait(lck);
|
|
|
|
|
@@ -1530,7 +1542,7 @@ void PrsonaServerWebSocketHandler::import_new_user_update(
|
|
|
std::vector<EGCiphertext> currentUserEncryptedTallies;
|
|
|
std::vector<std::vector<TwistBipoint>> voteMatrix;
|
|
|
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
BinarySizeT sizeOfVector;
|
|
|
|
|
@@ -1593,7 +1605,7 @@ void PrsonaServerWebSocketHandler::import_new_user_update(
|
|
|
}
|
|
|
|
|
|
void PrsonaServerWebSocketHandler::get_partial_decryption(
|
|
|
- struct mg_connection *conn)
|
|
|
+ struct mg_connection *conn) const
|
|
|
{
|
|
|
mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_DATACOMPLETE, "", 0);
|
|
|
}
|
|
@@ -1601,7 +1613,7 @@ void PrsonaServerWebSocketHandler::get_partial_decryption(
|
|
|
void PrsonaServerWebSocketHandler::receive_tallied_scores(
|
|
|
struct mg_connection *conn, const char *filename)
|
|
|
{
|
|
|
- ifstream file(filename);
|
|
|
+ std::ifstream file(filename);
|
|
|
|
|
|
std::vector<EGCiphertext> userScores;
|
|
|
std::vector<CurveBipoint> serverScores;
|