Forráskód Böngészése

server/client now compile, at least

tristangurtler 3 éve
szülő
commit
3cce4c56e4

+ 12 - 8
prsona/Makefile

@@ -29,6 +29,7 @@ CPP = g++
 CPPFLAGS = -std=c++14 -Wall -I$(PRSONA_INC_PATH) -I$(BGN_INC_PATH) -I$(666_INC_PATH) -I$(MG_INC_PATH) -O2
 CPPTESTFLAGS = -std=c++14 -Wall -I$(PRSONA_INC_PATH) -I$(BGN_INC_PATH) -I$(666_INC_PATH) -I$(MG_INC_PATH) -g
 LDFLAGS = -lgmp -lgmpxx -lssl -lcrypto
+NETWORK_LDFLAGS = -ldl -lpthread
 LDTESTFLAGS = -lgmp -lgmpxx -lssl -lcrypto -g
 
 CC = gcc
@@ -57,8 +58,11 @@ $(MG_OBJ_PATH):
 	mkdir -p $@
 
 PRSONA_FULL_SRC = $(wildcard $(PRSONA_SRC_PATH)/*.cpp)
-PRSONA_NETWORK_SRC = $(wildcard $(PRSONA_SRC_PATH)/network*.cpp)
-PRSONA_SRC = $(filter-out $(PRSONA_NETWORK_SRC) $(wildcard $(PRSONA_SRC_PATH)/*ain.cpp), $(PRSONA_FULL_SRC)) 
+PRSONA_FULL_NETWORK_SRC = $(wildcard $(PRSONA_SRC_PATH)/network*.cpp)
+PRSONA_SRC = $(filter-out $(PRSONA_FULL_NETWORK_SRC) $(wildcard $(PRSONA_SRC_PATH)/*ain.cpp), $(PRSONA_FULL_SRC)) 
+PRSONA_SHARED_NETWORK_OBJ = $(PRSONA_OBJ_PATH)/networking.o
+PRSONA_SERVER_NETWORK_OBJ = $(PRSONA_OBJ_PATH)/networkServer.o
+PRSONA_CLIENT_NETWORK_OBJ = $(PRSONA_OBJ_PATH)/networkClient.o
 PRSONA_NETWORK_OBJ = $(patsubst $(PRSONA_SRC_PATH)/%.cpp, $(PRSONA_OBJ_PATH)/%.o, $(PRSONA_NETWORK_SRC))
 PRSONA_OBJ = $(patsubst $(PRSONA_SRC_PATH)/%.cpp, $(PRSONA_OBJ_PATH)/%.o, $(PRSONA_SRC))
 
@@ -98,14 +102,14 @@ $(MG_OBJ_PATH)/%.o:
 $(PRSONA_BIN_PATH)/main: $(PRSONA_OBJ_PATH)/main.o $(PRSONA_OBJ) $(BGN_OBJ_PATH)/bgn.a
 	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS)
 
-$(PRSONA_BIN_PATH)/server: $(PRSONA_OBJ_PATH)/serverMain.o $(PRSONA_OBJ) $(PRSONA_NETWORK_OBJ) $(MG_OBJ) $(BGN_OBJ_PATH)/bgn.a
-	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS)
+$(PRSONA_BIN_PATH)/server: $(PRSONA_OBJ_PATH)/serverMain.o $(PRSONA_OBJ) $(PRSONA_SHARED_NETWORK_OBJ) $(PRSONA_SERVER_NETWORK_OBJ) $(MG_OBJ) $(BGN_OBJ_PATH)/bgn.a
+	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS) $(NETWORK_LDFLAGS)
 
-$(PRSONA_BIN_PATH)/client: $(PRSONA_OBJ_PATH)/clientMain.o $(PRSONA_OBJ) $(PRSONA_NETWORK_OBJ) $(MG_OBJ) $(BGN_OBJ_PATH)/bgn.a
-	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS)
+$(PRSONA_BIN_PATH)/client: $(PRSONA_OBJ_PATH)/clientMain.o $(PRSONA_OBJ) $(PRSONA_SHARED_NETWORK_OBJ) $(PRSONA_CLIENT_NETWORK_OBJ) $(MG_OBJ) $(BGN_OBJ_PATH)/bgn.a
+	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS) $(NETWORK_LDFLAGS)
 
-$(PRSONA_BIN_PATH)/orchestrator: $(PRSONA_OBJ_PATH)/orchestratorMain.o $(PRSONA_OBJ) $(PRSONA_NETWORK_OBJ) $(MG_OBJ) $(BGN_OBJ_PATH)/bgn.a
-	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS)
+$(PRSONA_BIN_PATH)/orchestrator: $(PRSONA_OBJ_PATH)/orchestratorMain.o $(PRSONA_OBJ) $(PRSONA_SHARED_NETWORK_OBJ) $(MG_OBJ) $(BGN_OBJ_PATH)/bgn.a
+	$(CPP) $(CPPFLAGS) -no-pie -o $@ $^ $(LDFLAGS) $(NETWORK_LDFLAGS)
 
 .PHONY: clean
 

+ 1 - 1
prsona/inc/base.hpp

@@ -13,6 +13,7 @@
 class PrsonaBase {
     public:
         static size_t MAX_ALLOWED_VOTE;
+        static Twistpoint EL_GAMAL_GENERATOR;
 
         // SETUP FUNCTIONS
         static void init();
@@ -30,7 +31,6 @@ class PrsonaBase {
 
     protected:
         // Essentially constants, true for both servers and clients
-        static Twistpoint EL_GAMAL_GENERATOR;
         static Scalar SCALAR_N;
         static Scalar DEFAULT_TALLY;
         static Scalar DEFAULT_VOTE;

+ 25 - 8
prsona/inc/networkClient.hpp

@@ -16,10 +16,10 @@ class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
     public:
         // CONSTRUCTORS
         PrsonaClientWebSocketHandler(
-            const PrsonaClient *prsonaClient, 
+            PrsonaClient *prsonaClient, 
             const std::vector<std::string>& serverIPs,
             const std::string& selfIP,
-            const std::default_random_engine *generator);
+            std::default_random_engine *generator);
 
         virtual bool handleConnection(
             CivetServer *server,
@@ -41,18 +41,24 @@ class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
             const struct mg_connection *conn);
 
     private:
-        const PrsonaClient *prsonaClient;
+        PrsonaClient *prsonaClient;
         const std::vector<std::string> serverIPs;
         const std::string selfIP;
-        const std::default_random_engine *generator;
+        std::default_random_engine *generator;
 
-        void verify_reputation_proof(struct mg_connection *c) const;
-}
+        void generate_response(
+            struct mg_connection *conn,
+            const char *filename) const;
+
+        void verify_reputation_proof(
+            struct mg_connection *conn,
+            const char *filename) const;
+};
 
 template <typename T>
 T get_committed_val_from_file(
     struct synchronization_tool *sync,
-    char *filename,
+    const char *filename,
     Proof& pi);
 
 template <typename T>
@@ -79,7 +85,18 @@ T get_server_committed_val(
     const std::vector<std::string>& serverIPs,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
-    const char *firstUri
+    const char *firstUri,
     const char *commitUri);
 
+Twistpoint get_generator_from_file(
+    struct synchronization_tool *sync,
+    const char *filename,
+    std::vector<Proof>& pi);
+
+Twistpoint get_generator(
+    std::default_random_engine *randomGenerator,
+    const std::vector<std::string>& serverIPs,
+    std::vector<Proof>& pi,
+    bool fresh);
+
 #endif

+ 127 - 40
prsona/inc/networkServer.hpp

@@ -3,6 +3,7 @@
 
 #include <string>
 #include <vector>
+#include <atomic>
 
 #include "server.hpp"
 #include "networking.hpp"
@@ -20,32 +21,37 @@ void release_update_locks(
     struct synchronization_tool *synch);
 
 std::string make_epoch_initiator_string(
-    std::vector<Proof> generatorProof,
-    Twistpoint nextGenerator);
+    const std::vector<Proof>& generatorProof,
+    const Twistpoint& nextGenerator);
 
 std::string make_epoch_update_string(
-    std::vector<std::vector<Proof>> pi,
-    std::vector<std::vector<Twistpoint>> permutationCommits,
-    std::vector<std::vector<Twistpoint>> freshPseudonymCommits,
-    std::vector<std::vector<Twistpoint>> freshPseudonymSeedCommits,
-    std::vector<std::vector<CurveBipoint>> serverTallyCommits,
-    std::vector<std::vector<std::vector<TwistBipoint>>> partwayVoteMatrixCommits,
-    std::vector<std::vector<std::vector<TwistBipoint>>> finalVoteMatrixCommits,
-    std::vector<std::vector<Twistpoint>> userTallyMaskCommits,
-    std::vector<std::vector<Twistpoint>> userTallyMessageCommits,
-    std::vector<std::vector<Twistpoint>> userTallySeedCommits,
-    Twistpoint nextGenerator,
+    const std::vector<std::vector<Proof>>& pi,
+    const std::vector<std::vector<Twistpoint>>& permutationCommits,
+    const std::vector<std::vector<Twistpoint>>& freshPseudonymCommits,
+    const std::vector<std::vector<Twistpoint>>& freshPseudonymSeedCommits,
+    const std::vector<std::vector<CurveBipoint>>& serverTallyCommits,
+    const std::vector<std::vector<std::vector<TwistBipoint>>>& partwayVoteMatrixCommits,
+    const std::vector<std::vector<std::vector<TwistBipoint>>>& finalVoteMatrixCommits,
+    const std::vector<std::vector<Twistpoint>>& userTallyMaskCommits,
+    const std::vector<std::vector<Twistpoint>>& userTallyMessageCommits,
+    const std::vector<std::vector<Twistpoint>>& userTallySeedCommits,
+    const Twistpoint& nextGenerator,
     bool doUserTallies);
 
+void distribute_epoch_updates(
+    const std::string& recipient,
+    const std::string& data,
+    const struct synchronization_tool* sync);
+
 class PrsonaServerWebSocketHandler : public CivetWebSocketHandler  {
     public:
         // CONSTRUCTORS
         PrsonaServerWebSocketHandler(
-            const PrsonaServer *prsonaServer, 
-            const std::mutex *updateMtx,
-            const std::atomic<size_t> *epochNum,
-            const std::vector<std::string> serverIPs,
-            const std::string selfIP);
+            PrsonaServer *prsonaServer, 
+            std::mutex *updateMtx,
+            std::atomic<size_t> *epochNum,
+            const std::vector<std::string>& serverIPs,
+            const std::string& selfIP);
 
         virtual bool handleConnection(
             CivetServer *server,
@@ -67,50 +73,131 @@ class PrsonaServerWebSocketHandler : public CivetWebSocketHandler  {
             const struct mg_connection *conn);
 
     private:
-        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;
 
         struct synchronization_tool updateSynch, distributeSynch;
 
+        void generate_response(
+            struct mg_connection *conn,
+            const char *filename);
+
         // BASIC PUBLIC SYSTEM INFO GETTERS
         void get_bgn_public_key(struct mg_connection *c) const;
         void get_num_clients(struct mg_connection *c) const;
         void get_num_servers(struct mg_connection *c) const;
 
         // ENCRYPTED DATA GETTERS
-        void get_current_votes_by(struct mg_connection *c) const;
-        void get_all_current_votes(struct mg_connection *c) const;
-        void get_current_user_encrypted_tally(struct mg_connection *c) const;
-        void get_current_server_encrypted_tally(struct mg_connection *c) const;
-        void get_current_pseudonyms(struct mg_connection *c) const;
+        void get_current_votes_by(
+            struct mg_connection *c,
+            const char *filename
+        ) const;
+        void get_all_current_votes(
+            struct mg_connection *c
+        ) const;
+        void get_current_user_encrypted_tally(
+            struct mg_connection *c,
+            const char *filename
+        ) const;
+        void get_current_server_encrypted_tally(
+            struct mg_connection *c,
+            const char *filename
+        ) const;
+        void get_current_pseudonyms(
+            struct mg_connection *c
+        ) const;
 
         // PROOF COMMITMENT GETTERS
-        void get_vote_row_commitment(struct mg_connection *c) const;
-        void get_vote_matrix_commitment(struct mg_connection *c) const;
-        void get_user_tally_commitment(struct mg_connection *c) const;
-        void get_server_tally_commitment(struct mg_connection *c) const;
-        void get_pseudonyms_commitment(struct mg_connection *c) const;
+        void get_vote_row_commitment(
+            struct mg_connection *c,
+            const char *filename
+        ) const;
+        void get_vote_matrix_commitment(
+            struct mg_connection *c
+        ) const;
+        void get_user_tally_commitment(
+            struct mg_connection *c,
+            const char *filename
+        ) const;
+        void get_server_tally_commitment(
+            struct mg_connection *c,
+            const char *filename
+        ) const;
+        void get_pseudonyms_commitment(
+            struct mg_connection *c
+        ) const;
 
         // CLIENT INTERACTIONS
-        void add_new_client(struct mg_connection *c);
-        void receive_vote(struct mg_connection *c);
+        void add_new_client(
+            struct mg_connection *c,
+            const char *filename
+        );
+        void receive_vote(
+            struct mg_connection *c,
+            const char *filename
+        );
 
         // CONSTRUCTOR HELPERS
         void get_bgn_details(struct mg_connection *c) const;
-        void initialize_fresh_generator(struct mg_connection *c);
-        void add_rand_seed_to_generator(struct mg_connection *c) const;
-        void set_EG_blind_generator(struct mg_connection *c);
+        void add_seed_to_generator(
+            struct mg_connection *conn,
+            const char *filename,
+            bool fresh
+        ) const;
+        void set_generator(
+            const char *filename,
+            bool fresh
+        );
 
         // EPOCH ROUNDS
-        void build_up_midway_pseudonyms(struct mg_connection *c);
-        void break_down_midway_pseudonyms(struct mg_connection *c);
-        void accept_epoch_updates(struct mg_connection *c);
+        void build_up_midway_pseudonyms(
+            struct mg_connection *c,
+            const char *filename
+        );
+        void break_down_midway_pseudonyms(
+            struct mg_connection *c,
+            const char *filename
+        );
+        void accept_epoch_updates(
+            struct mg_connection *c,
+            const char *filename
+        );
 
         // DATA MAINTENANCE
-        void import_new_user_update(struct mg_connection *c);
+        void import_new_user_update(
+            const char *filename
+        );
+
+        void distribute_new_user_updates(
+            std::vector<Proof> proofOfValidAddition,
+            std::vector<CurveBipoint> previousVoteTallies,
+            std::vector<Twistpoint> currentPseudonyms,
+            std::vector<EGCiphertext> currentUserEncryptedTallies,
+            std::vector<std::vector<TwistBipoint>> voteMatrix
+        ) const;
+
+        void distribute_new_vote(
+            std::vector<Proof> pi,
+            std::vector<TwistBipoint> newVotes,
+            Twistpoint shortTermPublicKey
+        ) const;
+
+        void get_partial_decryption(
+            struct mg_connection *conn
+        ) const;
+
+        void receive_tallied_scores(
+            struct mg_connection *conn,
+            const char *filename
+        );
+
+        void get_generator(
+            struct mg_connection *conn,
+            bool fresh
+        );
 }; 
 
 #endif

+ 18 - 18
prsona/inc/networking.hpp

@@ -3,11 +3,13 @@
 
 #include <mutex>
 #include <condition_variable>
+#include <string>
 
 #include "CivetServer.h"
 
 #define MG_WEBSOCKET_OPCODE_DATACOMPLETE 0xb
 #define PRSONA_PORT 8080
+#define PRSONA_PORT_STR "8080"
 #define USE_SSL 0
 
 #define EXIT_URI "/exit"
@@ -88,16 +90,16 @@ struct synchronization_tool {
 };
 
 std::string random_string(size_t length);
-void set_temp_filename(struct mg_connection *conn) const;
+char *set_temp_filename(struct mg_connection *conn);
 
 class RemoteControlHandler : public CivetHandler
 {
     public:
-        ExitHandler(struct synchronization_tool *sync)
+        RemoteControlHandler(struct synchronization_tool *sync)
             : sync(sync)
         { /* */ }
 
-        ExitHandler(struct synchronization_tool *sync,
+        RemoteControlHandler(struct synchronization_tool *sync,
             const std::string& message)
             : sync(sync), message(message)
         { /* */ }
@@ -105,65 +107,63 @@ class RemoteControlHandler : public CivetHandler
         bool handleGet(CivetServer *server, struct mg_connection *conn);
 
     private:
-        const struct synchronization_tool *sync;
+        struct synchronization_tool *sync;
         const std::string message;
 };
 
 class AltRemoteControlHandler : public CivetHandler
 {
     public:
-        ExitHandler(size_t value, struct synchronization_tool *sync)
+        AltRemoteControlHandler(size_t value, struct synchronization_tool *sync)
             : value(value), sync(sync)
         { /* */ }
 
-        ExitHandler(size_t value,
+        AltRemoteControlHandler(size_t value,
             struct synchronization_tool *sync,
             const std::string& message)
             : value(value), sync(sync), message(message)
         { /* */ }
 
         bool handleGet(CivetServer *server, struct mg_connection *conn);
-        std::string query() const;
+        std::string getQuery() const;
 
     private:
         const size_t value;
-        const struct synchronization_tool *sync;
+        struct synchronization_tool *sync;
         const std::string message;
         std::string query;
 };
 
-static int empty_websocket_data_handler(
+int empty_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
     char *data,
     size_t data_len,
-    void *user_data)
-{ return false; }
+    void *user_data);
 
-static void empty_websocket_close_handler(
+void empty_websocket_close_handler(
     const struct mg_connection *conn,
-    void *user_data)
-{ /* */ }
+    void *user_data);
 
-static int synchro_websocket_data_handler(
+int synchro_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
     char *data,
     size_t data_len,
     void *user_data);
 
-static void synchro_websocket_close_handler(
+void synchro_websocket_close_handler(
     const struct mg_connection *conn,
     void *user_data);
 
-static int file_websocket_data_handler(
+int file_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
     char *data,
     size_t data_len,
     void *user_data);
 
-static void file_websocket_close_handler(
+void file_websocket_close_handler(
     const struct mg_connection *conn,
     void *user_data);
 

+ 22 - 13
prsona/inc/server.hpp

@@ -31,6 +31,9 @@ class PrsonaServer : public PrsonaBase {
         Twistpoint add_next_seed_to_generator(
             std::vector<Proof>& pi,
             const Twistpoint& currGenerator) const;
+        Twistpoint add_rand_seed_to_generator(
+            std::vector<Proof>& pi,
+            const Twistpoint& currGenerator) const;
 
         // ENCRYPTED DATA GETTERS
         std::vector<TwistBipoint> get_current_votes_by(
@@ -42,6 +45,7 @@ class PrsonaServer : public PrsonaBase {
         CurveBipoint get_current_server_encrypted_tally(
             Proof& pi, const Twistpoint& shortTermPublicKey) const;
         std::vector<Twistpoint> get_current_pseudonyms(Proof& pi) const;
+        std::vector<Twistpoint> get_current_pseudonyms() const;
 
         // PROOF COMMITMENT GETTERS
         Proof get_vote_row_commitment(const Twistpoint& request) const;
@@ -62,7 +66,6 @@ class PrsonaServer : public PrsonaBase {
 
         void print_scores(const std::vector<CurveBipoint>& scores);
 
-    protected:
         // CONSTRUCTOR HELPERS
         const BGN& get_bgn_details() const;
 
@@ -70,10 +73,6 @@ class PrsonaServer : public PrsonaBase {
             const std::vector<Proof>& pi,
             const Twistpoint& firstGenerator);
 
-        Twistpoint add_rand_seed_to_generator(
-            std::vector<Proof>& pi,
-            const Twistpoint& currGenerator) const;
-
         bool set_EG_blind_generator(
             const std::vector<Proof>& pi,
             const Twistpoint& currGenerator);
@@ -90,7 +89,7 @@ class PrsonaServer : public PrsonaBase {
             Twistpoint& nextGenerator);
 
         void break_down_midway_pseudonyms(
-            std::vector<Proof>& generatorProof,
+            const std::vector<Proof>& generatorProof,
             std::vector<std::vector<std::vector<Proof>>>& pi,
             std::vector<std::vector<std::vector<Twistpoint>>>& permutationCommits,
             std::vector<std::vector<std::vector<Twistpoint>>>& freshPseudonymCommits,
@@ -118,6 +117,13 @@ class PrsonaServer : public PrsonaBase {
             bool doUserTallies);
 
         // DATA MAINTENANCE
+        void export_new_user_update(
+            std::vector<CurveBipoint>& otherPreviousVoteTallies,
+            std::vector<Twistpoint>& otherCurrentPseudonyms,
+            std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
+            std::vector<std::vector<TwistBipoint>>& otherVoteMatrix
+        ) const;
+
         bool import_new_user_update(
             const std::vector<Proof>& pi,
             const std::vector<CurveBipoint>& otherPreviousVoteTallies,
@@ -125,6 +131,16 @@ class PrsonaServer : public PrsonaBase {
             const std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
             const std::vector<std::vector<TwistBipoint>>& otherVoteMatrix);
 
+        // SCORE TALLYING
+        std::vector<Scalar> tally_scores();
+        Scalar get_max_possible_score();
+        void receive_tallied_scores(
+            const std::vector<EGCiphertext>& userTallyScores,
+            const std::vector<CurveBipoint>& serverTallyScores);
+        void encrypt(
+            CurveBipoint& element,
+            const Scalar& value);
+
     private:
         // constants for servers
         const size_t numServers;
@@ -154,13 +170,6 @@ class PrsonaServer : public PrsonaBase {
         // An imaginary class; it's just used right now to coordinate servers
         // in memory instead of via network action.
         friend class PrsonaServerEntity;
-        
-        // SCORE TALLYING
-        std::vector<Scalar> tally_scores();
-        Scalar get_max_possible_score();
-        void receive_tallied_scores(
-            const std::vector<EGCiphertext>& userTallyScores,
-            const std::vector<CurveBipoint>& serverTallyScores);
 
         // EPOCH HELPERS
         std::vector<std::vector<Proof>> epoch_calculations(

+ 45 - 14
prsona/src/clientMain.cpp

@@ -39,10 +39,11 @@ BGNPublicKey get_bgn_public_key_from_file(
 }
 
 BGNPublicKey get_bgn_public_key(
-    default_random_engine *generator,
+    default_random_engine *randomGenerator,
     const vector<string>& serverIPs)
 {
     struct synchronization_tool sync;
+    char *filename = NULL;
 
     uniform_int_distribution<size_t> distribution(0, serverIPs.size() - 1);
     size_t whichServer = distribution(*randomGenerator);
@@ -65,11 +66,11 @@ BGNPublicKey get_bgn_public_key(
         if (!conn)
         {
             cerr << "Couldn't obtain BGN details" << endl;
-            return 1;
+            continue;
         }
 
         unique_lock<mutex> lck(sync.mtx);
-        char *filename = set_temp_filename(conn);
+        filename = set_temp_filename(conn);
         sync.val = 0;
 
         mg_websocket_client_write(
@@ -183,7 +184,7 @@ void send_item(
             0);
 
         while (!sync.val)
-            sync.cv.wait(lck)
+            sync.cv.wait(lck);
 
         mg_close_connection(conn);
 
@@ -198,8 +199,11 @@ void make_vote(
     const vector<string>& serverIPs,
     size_t numClients)
 {
-    uniform_int_distribution<size_t> voteDistribution(
+    uniform_int_distribution<int> voteDistribution(
         0, PrsonaBase::get_max_allowed_vote());
+    uniform_int_distribution<int> numVoteDistribution(
+        0, numClients);
+    size_t numVotes = numVoteDistribution(generator);
 
     // Make the correct number of new votes, but shuffle where they go
     vector<Scalar> votes;
@@ -214,7 +218,7 @@ void make_vote(
     vector<Proof> generatorProof;
     Twistpoint freshGenerator =
         get_generator(
-            generator,
+            &generator,
             serverIPs,
             generatorProof,
             true);
@@ -238,7 +242,7 @@ void make_vote(
     vector<Proof> voteProof;
     encryptedVotes =
         prsonaClient->make_votes(
-            currVoteProof,
+            voteProof,
             fullProof,
             encryptedVotes,
             votes,
@@ -269,6 +273,26 @@ string make_vote_string(
     return buffer.str();
 }
 
+string make_rep_proof_string(
+    const vector<Proof>& pi,
+    const Twistpoint& shortTermPublicKey,
+    const Scalar& threshold)
+{
+    stringstream buffer;
+    BinarySizeT sizeOfVector;
+
+    sizeOfVector.set(pi.size());
+    
+    buffer >> sizeOfVector;
+    for (size_t i = 0; i < sizeOfVector.val(); i++)
+        buffer << pi[i];
+
+    buffer << shortTermPublicKey;
+    buffer << threshold;
+
+    return buffer.str();
+}
+
 void make_reputation_proof(
     default_random_engine& generator,
     const string& target,
@@ -279,7 +303,7 @@ void make_reputation_proof(
     vector<Proof> generatorProof;
     Twistpoint freshGenerator =
         get_generator(
-            generator,
+            &generator,
             serverIPs,
             generatorProof,
             true);
@@ -326,7 +350,7 @@ int main(int argc, char *argv[])
     mg_init_library(MG_FEATURES_SSL);
 #endif
     
-    const char *options[] = {"listening_ports", PRSONA_PORT, 0};
+    const char *options[] = {"listening_ports", PRSONA_PORT_STR, 0};
 
     vector<string> serverIPs, clientIPs;
     string selfIP;
@@ -385,7 +409,8 @@ int main(int argc, char *argv[])
         PrsonaBase::set_server_malicious();
 
     // Entities we operate with
-    PrsonaClient *prsonaClient = create_client(numServers);
+    PrsonaClient *prsonaClient =
+        create_client(&generator, serverIPs, numServers);
     CivetServer server(options);
 
     PrsonaClientWebSocketHandler wsHandler(prsonaClient, serverIPs, selfIP, &generator);
@@ -406,7 +431,7 @@ int main(int argc, char *argv[])
     while (!exitSync.val)
     {
         while (!exitSync.val && !exitSync.val2)
-            exitSync.cv.wait(lck);
+            exitSync.cv.wait(exitLock);
 
         size_t whichServer = distribution(generator);
 
@@ -414,14 +439,20 @@ int main(int argc, char *argv[])
         {
             case CLIENT_MAKE_VOTE:
                 make_vote(
+                    generator,
                     serverIPs[whichServer],
-                    prsonaClient);
+                    prsonaClient,
+                    serverIPs,
+                    numClients);
                 break;
 
             case CLIENT_MAKE_REP_PROOF:
                 make_reputation_proof(
-                    triggerRepHandler.query(),
-                    prsonaClient);
+                    generator,
+                    triggerRepHandler.getQuery(),
+                    prsonaClient,
+                    serverIPs,
+                    numClients);
                 break;
 
             default:

+ 52 - 26
prsona/src/networkClient.cpp

@@ -1,3 +1,4 @@
+#include <fstream>
 #include <cstring>
 #include <cstdio>
 
@@ -6,7 +7,7 @@
 template <>
 EGCiphertext get_committed_val_from_file<EGCiphertext>(
     struct synchronization_tool *sync,
-    char *filename,
+    const char *filename,
     Proof& pi)
 {
     std::unique_lock<std::mutex> lck(sync->mtx);
@@ -22,7 +23,7 @@ EGCiphertext get_committed_val_from_file<EGCiphertext>(
 template <>
 std::vector<TwistBipoint> get_committed_val_from_file<std::vector<TwistBipoint>>(
     struct synchronization_tool *sync,
-    char *filename,
+    const char *filename,
     Proof& pi)
 {
     std::unique_lock<std::mutex> lck(sync->mtx);
@@ -33,6 +34,7 @@ std::vector<TwistBipoint> get_committed_val_from_file<std::vector<TwistBipoint>>
     std::vector<TwistBipoint> retval;
 
     BinarySizeT sizeOfVector;
+    valFile >> sizeOfVector;
     for (size_t i = 0; i < sizeOfVector.val(); i++)
     {
         TwistBipoint currVote;
@@ -56,6 +58,8 @@ T get_first_committed_val(
     std::stringstream buffer;
     std::string data;
 
+    char *filename = NULL;
+
     buffer << shortTermPublicKey;
     data = buffer.str();
 
@@ -82,7 +86,7 @@ T get_first_committed_val(
         }
 
         std::unique_lock<std::mutex> lck(sync.mtx);
-        char *filename = set_temp_filename(conn);
+        filename = set_temp_filename(conn);
         sync.val = 0;
 
         mg_websocket_client_write(
@@ -98,14 +102,14 @@ T get_first_committed_val(
             0);
 
         while (!sync.val)
-            sync.cv.wait(lck)
+            sync.cv.wait(lck);
 
         mg_close_connection(conn);
 
         flag = true;
     }
 
-    T retval = get_committed_val_from_file<T>(filename, pi);
+    T retval = get_committed_val_from_file<T>(&sync, filename, pi);
 
     remove(filename);
     delete filename;
@@ -131,7 +135,7 @@ void get_additional_commitment(
     const std::string& skip,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
-    char *commitUri)
+    const char *commitUri)
 {
     std::vector<char *> commitmentFilenames;
     std::vector<struct synchronization_tool *> commitmentSyncs;
@@ -177,7 +181,7 @@ void get_additional_commitment(
                 0);
 
             while (!currSync->val)
-                currSync->cv.wait(lck)
+                currSync->cv.wait(lck);
 
             mg_close_connection(conn);
 
@@ -204,7 +208,7 @@ T get_server_committed_val(
     const std::vector<std::string>& serverIPs,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
-    const char *firstUri
+    const char *firstUri,
     const char *commitUri)
 {
     std::uniform_int_distribution<size_t> distribution(0, serverIPs.size() - 1);
@@ -217,7 +221,7 @@ T get_server_committed_val(
         get_first_committed_val<T>(
             serverIPs[whichServer],
             firstProof,
-            shortTermPublicKey
+            shortTermPublicKey,
             firstUri);
 
     pi.push_back(firstProof);
@@ -232,6 +236,22 @@ T get_server_committed_val(
     return retval;
 }
 
+template EGCiphertext get_server_committed_val<EGCiphertext>(
+    std::default_random_engine *generator,
+    const std::vector<std::string>& serverIPs,
+    std::vector<Proof>& pi,
+    const Twistpoint& shortTermPublicKey,
+    const char *firstUri,
+    const char *commitUri);
+
+template std::vector<TwistBipoint> get_server_committed_val<std::vector<TwistBipoint>>(
+    std::default_random_engine *generator,
+    const std::vector<std::string>& serverIPs,
+    std::vector<Proof>& pi,
+    const Twistpoint& shortTermPublicKey,
+    const char *firstUri,
+    const char *commitUri);
+
 Twistpoint get_generator_from_file(
     struct synchronization_tool *sync,
     const char *filename,
@@ -267,6 +287,8 @@ Twistpoint get_generator(
     std::uniform_int_distribution<size_t> distribution(0, serverIPs.size() - 1);
     size_t whichServer = distribution(*randomGenerator);
 
+    char *filename = NULL;
+
     pi.clear();
 
     const char* whichUri = (fresh ? FRESH_GEN_URI : BLIND_GEN_URI);
@@ -288,12 +310,12 @@ Twistpoint get_generator(
 
         if (!conn)
         {
-            cerr << "Couldn't obtain BGN details" << endl;
-            return 1;
+            std::cerr << "Couldn't obtain BGN details" << std::endl;
+            continue;
         }
 
-        unique_lock<mutex> lck(sync.mtx);
-        char *filename = set_temp_filename(conn);
+        std::unique_lock<std::mutex> lck(sync.mtx);
+        filename = set_temp_filename(conn);
         sync.val = 0;
 
         mg_websocket_client_write(
@@ -320,26 +342,26 @@ Twistpoint get_generator(
 }
 
 PrsonaClientWebSocketHandler::PrsonaClientWebSocketHandler(
-    const PrsonaClient *prsonaClient, 
+    PrsonaClient *prsonaClient, 
     const std::vector<std::string>& serverIPs,
     const std::string& selfIP,
-    const std::default_random_engine *generator)
+    std::default_random_engine *generator)
 : prsonaClient(prsonaClient), serverIPs(serverIPs),
     selfIP(selfIP), generator(generator)
 { /* */ }
 
-virtual bool PrsonaClientWebSocketHandler::handleConnection(
+bool PrsonaClientWebSocketHandler::handleConnection(
     CivetServer *server,
     const struct mg_connection *conn)
 {
     const struct mg_request_info *info = mg_get_request_info(conn);
     
-    flag = (info->query_string && info->query_string[0] == PRSONA_VERIFY_REPUTATION_PROOF);
+    bool flag = (info->query_string && info->query_string[0] == PRSONA_VERIFY_REPUTATION_PROOF);
 
     return flag;
 }
 
-virtual void PrsonaClientWebSocketHandler::handleReadyState(
+void PrsonaClientWebSocketHandler::handleReadyState(
     CivetServer *server,
     struct mg_connection *conn)
 {
@@ -357,7 +379,7 @@ virtual void PrsonaClientWebSocketHandler::handleReadyState(
     }
 }
 
-virtual bool PrsonaClientWebSocketHandler::handleData(
+bool PrsonaClientWebSocketHandler::handleData(
     CivetServer *server,
     struct mg_connection *conn,
     int bits,
@@ -385,9 +407,9 @@ virtual bool PrsonaClientWebSocketHandler::handleData(
     return true;
 }
 
-void PrsonaServerWebSocketHandler::generate_response(
+void PrsonaClientWebSocketHandler::generate_response(
     struct mg_connection *conn,
-    char *filename)
+    const char *filename) const
 {
     const struct mg_request_info *info = mg_get_request_info(conn);
 
@@ -402,7 +424,7 @@ void PrsonaServerWebSocketHandler::generate_response(
     }
 }
 
-virtual void PrsonaClientWebSocketHandler::handleClose(
+void PrsonaClientWebSocketHandler::handleClose(
     CivetServer *server,
     const struct mg_connection *conn)
 {
@@ -417,7 +439,7 @@ virtual void PrsonaClientWebSocketHandler::handleClose(
 void PrsonaClientWebSocketHandler::verify_reputation_proof(
     struct mg_connection *conn, const char *filename) const
 {
-    ifstream file(filename);
+    std::ifstream file(filename);
 
     std::vector<Proof> pi;
     Twistpoint shortTermPublicKey;
@@ -438,15 +460,19 @@ void PrsonaClientWebSocketHandler::verify_reputation_proof(
     std::vector<Proof> generatorProof;
     Twistpoint freshGenerator =
         get_generator(
-            &generator,
+            generator,
             serverIPs,
             generatorProof,
             true);
 
+    prsonaClient->receive_fresh_generator(
+            generatorProof,
+            freshGenerator);
+
     std::vector<Proof> encryptedScoreProof;
     EGCiphertext encryptedScore =
         get_server_committed_val<EGCiphertext>(
-            &generator,
+            generator,
             serverIPs,
             encryptedScoreProof,
             shortTermPublicKey,
@@ -461,7 +487,7 @@ void PrsonaClientWebSocketHandler::verify_reputation_proof(
             encryptedScoreProof,
             encryptedScore);
 
-    string data = flag ? "\x01" : "\x00";
+    std::string data = flag ? "\x01" : "\x00";
 
     mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_BINARY, data.c_str(), 1);
     mg_websocket_write(conn, MG_WEBSOCKET_OPCODE_DATACOMPLETE, "", 0);

+ 65 - 53
prsona/src/networkServer.cpp

@@ -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;

+ 28 - 11
prsona/src/networking.cpp

@@ -1,4 +1,8 @@
 #include <algorithm>
+#include <iostream>
+#include <cstring>
+
+#include "networking.hpp"
 
 std::string random_string(size_t length)
 {
@@ -17,7 +21,7 @@ std::string random_string(size_t length)
 }
 
 char *set_temp_filename(
-    struct mg_connection *conn) const
+    struct mg_connection *conn)
 {
     std::string filename = random_string(TMP_FILE_SIZE);
     
@@ -34,7 +38,7 @@ char *set_temp_filename(
 
 bool RemoteControlHandler::handleGet(CivetServer *server, struct mg_connection *conn)
 {
-    unique_lock<mutex> lck(sync->mtx);
+    std::unique_lock<std::mutex> lck(sync->mtx);
 
     mg_printf(conn,
               "HTTP/1.1 200 OK\r\nContent-Type: "
@@ -52,7 +56,7 @@ bool RemoteControlHandler::handleGet(CivetServer *server, struct mg_connection *
 
 bool AltRemoteControlHandler::handleGet(CivetServer *server, struct mg_connection *conn)
 {
-    unique_lock<mutex> lck(sync->mtx);
+    std::unique_lock<std::mutex> lck(sync->mtx);
 
     const struct mg_request_info *info = mg_get_request_info(conn);
     if (info->query_string)
@@ -72,12 +76,25 @@ bool AltRemoteControlHandler::handleGet(CivetServer *server, struct mg_connectio
     return true;
 }
 
-std::string AltRemoteControlHandler::query() const
+std::string AltRemoteControlHandler::getQuery() const
 {
     return query;
 }
 
-static int synchro_websocket_data_handler(
+int empty_websocket_data_handler(
+    struct mg_connection *conn,
+    int bits,
+    char *data,
+    size_t data_len,
+    void *user_data)
+{ return false; }
+
+void empty_websocket_close_handler(
+    const struct mg_connection *conn,
+    void *user_data)
+{ /* */ }
+
+int synchro_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
     char *data,
@@ -91,7 +108,7 @@ static int synchro_websocket_data_handler(
     {
         struct synchronization_tool *synch = (struct synchronization_tool *) user_data;
 
-        unique_lock<mutex> lck(synch->mtx);
+        std::unique_lock<std::mutex> lck(synch->mtx);
         synch->val++;
 
         return false;
@@ -101,18 +118,18 @@ static int synchro_websocket_data_handler(
     return false;    
 }
 
-static void synchro_websocket_close_handler(
+void synchro_websocket_close_handler(
     const struct mg_connection *conn,
     void *user_data)
 {
     struct synchronization_tool *synch = (struct synchronization_tool *) user_data;
 
-    unique_lock<mutex> lck(synch->mtx);
+    std::unique_lock<std::mutex> lck(synch->mtx);
     synch->val2 = 1;
     synch->cv.notify_all();
 }
 
-static int file_websocket_data_handler(
+int file_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
     char *data,
@@ -139,13 +156,13 @@ static int file_websocket_data_handler(
     return true;
 }
 
-static void file_websocket_close_handler(
+void file_websocket_close_handler(
     const struct mg_connection *conn,
     void *user_data)
 {
     struct synchronization_tool *sync = (struct synchronization_tool *) user_data;
 
-    unique_lock<mutex> lck(sync->mtx);
+    std::unique_lock<std::mutex> lck(sync->mtx);
     sync->val = 1;
     sync->cv.notify_all();
 }

+ 17 - 15
prsona/src/orchestratorMain.cpp

@@ -5,12 +5,16 @@
 #include <cstring>
 #include <cstdlib>
 #include <vector>
+#include <chrono>
+#include <thread>
 
 #include "networking.hpp"
 
 using namespace std;
 
-static int clients_websocket_data_handler(
+chrono::seconds oneSecond(1); 
+
+int clients_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
     char *data,
@@ -37,7 +41,7 @@ static int clients_websocket_data_handler(
     return false;    
 }
 
-void start_remote_actor(string target, bool server, string output)
+int start_remote_actor(string target, bool server, string output)
 {
     stringstream buffer;
     string command;
@@ -46,7 +50,7 @@ void start_remote_actor(string target, bool server, string output)
         << (server ? "startServer.sh " : "startClient.sh ") << output << "\'\"" ;
     command = buffer.str();
 
-    system(command.c_str());
+    return system(command.c_str());
 }
 
 void wait_for_servers_ready(string dealer)
@@ -54,7 +58,7 @@ void wait_for_servers_ready(string dealer)
     bool flag = false;
     while (!flag)
     {
-        sleep(1);
+        this_thread::sleep_for(oneSecond);
 
         stringstream sysString;
         string data;
@@ -93,11 +97,10 @@ void wait_for_clients_ready(string dealer, size_t numClients)
     bool flag = false;
     while (!flag)
     {
-        sleep(1);
+        this_thread::sleep_for(oneSecond);
 
         stringstream sysString;
         string data;
-        char buffer[255];
 
         struct mg_connection *conn =
             mg_connect_websocket_client(
@@ -137,7 +140,7 @@ void wait_for_clients_ready(string dealer, size_t numClients)
 
 void trigger_epoch(string dealer)
 {
-    sleep(1);
+    this_thread::sleep_for(oneSecond);
 
     bool flag = false;
     while (!flag)
@@ -189,7 +192,7 @@ void trigger_vote(string target)
             continue;
 
         sysString << "GET " << TRIGGER_VOTE_URI << " HTTP/1.1\r\n";
-        sysString << "Host: " << dealer << "\r\n\r\n";
+        sysString << "Host: " << target << "\r\n\r\n";
         data = sysString.str();
 
         mg_write(conn, data.c_str(), data.length());
@@ -219,7 +222,7 @@ void trigger_reputation_proof(string target, string verifier)
             continue;
 
         sysString << "GET " << TRIGGER_REP_URI << verifier << " HTTP/1.1\r\n";
-        sysString << "Host: " << dealer << "\r\n\r\n";
+        sysString << "Host: " << target << "\r\n\r\n";
         data = sysString.str();
 
         mg_write(conn, data.c_str(), data.length());
@@ -250,8 +253,7 @@ void execute_experiment(string dealer)
         switch(buffer[0])
         {
             case 'V':
-                string target = buffer + 2;
-                trigger_vote(target);
+                trigger_vote(string(buffer + 2));
                 break;
 
             case 'R':
@@ -320,7 +322,7 @@ int main(int argc, char* argv[])
     vector<thread> serverStartup, clientStartup;
     serverStartup.push_back(thread(start_remote_actor, dealerIP, true, experimentOutput));
 
-    sleep(1);
+    this_thread::sleep_for(oneSecond);
 
     cout << "Starting other servers." << endl;
 
@@ -349,7 +351,7 @@ int main(int argc, char* argv[])
     for (size_t i = 0; i < numClients; i++)
         clientStartup[i].join();
 
-    wait_for_clients_ready(dealerIP);
+    wait_for_clients_ready(dealerIP, numClients);
 
     cout << "Beginning experiment." << endl;
 
@@ -365,7 +367,7 @@ int main(int argc, char* argv[])
 
         struct mg_connection *conn =
             mg_connect_client(
-                clientIPs[i], 
+                clientIPs[i].c_str(), 
                 PRSONA_PORT,
                 USE_SSL, 
                 NULL,
@@ -388,7 +390,7 @@ int main(int argc, char* argv[])
 
         struct mg_connection *conn =
             mg_connect_client(
-                serverIPs[i], 
+                serverIPs[i].c_str(), 
                 PRSONA_PORT,
                 USE_SSL, 
                 NULL,

+ 25 - 1
prsona/src/server.cpp

@@ -133,6 +133,11 @@ std::vector<Twistpoint> PrsonaServer::get_current_pseudonyms(Proof& pi) const
     return currentPseudonyms;
 }
 
+std::vector<Twistpoint> PrsonaServer::get_current_pseudonyms() const
+{
+    return currentPseudonyms;
+}
+
 /*
  * PROOF COMMITMENT GETTERS
  */
@@ -399,6 +404,13 @@ void PrsonaServer::receive_tallied_scores(
     previousVoteTallies = serverTallyScores;
 }
 
+void PrsonaServer::encrypt(
+    CurveBipoint& element,
+    const Scalar& value)
+{
+    bgnSystem.encrypt(element, value);
+}
+
 /*
  * EPOCH ROUNDS
  */
@@ -456,7 +468,7 @@ void PrsonaServer::build_up_midway_pseudonyms(
 
 // The second round, going from A_0.5 to A_1
 void PrsonaServer::break_down_midway_pseudonyms(
-    std::vector<Proof>& generatorProof,
+    const std::vector<Proof>& generatorProof,
     std::vector<std::vector<std::vector<Proof>>>& pi,
     std::vector<std::vector<std::vector<Twistpoint>>>& permutationCommits,
     std::vector<std::vector<std::vector<Twistpoint>>>& freshPseudonymCommits,
@@ -1290,6 +1302,18 @@ bool PrsonaServer::pseudonyms_sorted(
  * DATA MAINTENANCE
  */
 
+void PrsonaServer::export_new_user_update(
+    std::vector<CurveBipoint>& otherPreviousVoteTallies,
+    std::vector<Twistpoint>& otherCurrentPseudonyms,
+    std::vector<EGCiphertext>& otherCurrentUserEncryptedTallies,
+    std::vector<std::vector<TwistBipoint>>& otherVoteMatrix) const
+{
+    otherPreviousVoteTallies = previousVoteTallies;
+    otherCurrentPseudonyms = currentPseudonyms;
+    otherCurrentUserEncryptedTallies = currentUserEncryptedTallies;
+    otherVoteMatrix = voteMatrix;
+}
+
 bool PrsonaServer::import_new_user_update(
     const std::vector<Proof>& pi,
     const std::vector<CurveBipoint>& otherPreviousVoteTallies,

+ 150 - 145
prsona/src/serverMain.cpp

@@ -97,7 +97,7 @@ Twistpoint update_data_from_epoch_gen_file(vector<Proof>& pi)
     {
         Proof currProof;
         epochFile >> currProof;
-        
+
         pi.push_back(currProof);
     }
     epochFile >> retval;
@@ -112,8 +112,6 @@ static int generator_websocket_data_handler(
     size_t data_len,
     void *user_data)
 {
-    struct synchronization_tool *synch = (struct synchronization_tool *) user_data;
-
     if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE || (bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
         return false;
 
@@ -148,7 +146,7 @@ static int epoch_websocket_data_handler(
     void *user_data)
 {
     if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE)
-        return false
+        return false;
     if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
     {
         unique_lock<mutex> lck(epochSync.mtx);
@@ -224,63 +222,64 @@ Twistpoint get_generator(
     else
         retval = prsonaServer->add_rand_seed_to_generator(pi, retval);
 
+    const char* which = (fresh ? GET_FRESH_GEN_URI : GET_BLIND_GEN_URI);
+
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
         if (serverIPs[i] == selfIP)
             continue;
 
-        char* which;
-        if (fresh)
-            which = GET_FRESH_GEN_URI;
-        else
-            which = GET_BLIND_GEN_URI;
-
-        Proof currProof;
-
-        struct mg_connection *conn =
-            mg_connect_websocket_client(
-                serverIPs[i].c_str(),
-                PRSONA_PORT,
-                USE_SSL,
-                NULL,
-                0,
-                which,
-                "null",
-                generator_websocket_data_handler,
-                generator_websocket_close_handler,
-                NULL);
-
-        if (!conn)
+        bool flag = false;
+        while (!flag)
         {
-            cerr << "Couldn't get server " << i << "'s update on generator" << endl;
-            return 1;
-        }
-
-        stringstream buffer;
-        string data;
-        buffer << retval;
-        data = buffer.str();
+            struct mg_connection *conn =
+                mg_connect_websocket_client(
+                    serverIPs[i].c_str(),
+                    PRSONA_PORT,
+                    USE_SSL,
+                    NULL,
+                    0,
+                    which,
+                    "null",
+                    generator_websocket_data_handler,
+                    generator_websocket_close_handler,
+                    NULL);
+
+            if (!conn)
+            {
+                cerr << "Couldn't get server " << i << "'s update on generator" << endl;
+                continue;
+            }
 
-        mg_websocket_client_write(
-            conn,
-            MG_WEBSOCKET_OPCODE_BINARY,
-            data.c_str(),
-            data.length());
+            stringstream buffer;
+            string data;
+            buffer << retval;
+            data = buffer.str();
+
+            mg_websocket_client_write(
+                conn,
+                MG_WEBSOCKET_OPCODE_BINARY,
+                data.c_str(),
+                data.length());
+
+            unique_lock<mutex> lck(generatorSync.mtx);
+            remove(GEN_TMP_FILE);
+            generatorSync.val = 0;
+            mg_websocket_client_write(
+                conn,
+                MG_WEBSOCKET_OPCODE_DATACOMPLETE,
+                "",
+                0);
 
-        unique_lock<mutex> lck(generatorSync.mtx);
-        remove(GEN_TMP_FILE);
-        generatorSync.val = 0;
-        mg_websocket_client_write(
-            conn,
-            MG_WEBSOCKET_OPCODE_DATACOMPLETE,
-            "",
-            0);
+            while (!generatorSync.val)
+                generatorSync.cv.wait(lck);
 
-        while (!generatorSync.val)
-            generatorSync.cv.wait(lck);
+            mg_close_connection(conn);
 
-        mg_close_connection(conn);
+            flag = true;
+        }
 
+        Proof currProof;
         retval = update_generator_from_gen_file(currProof);
         pi.push_back(currProof);
     }
@@ -303,6 +302,8 @@ void handout_generator(
 
     stringstream buffer;
     string data;
+
+    const char* which = (fresh ? GIVE_FRESH_GEN_URI : GIVE_BLIND_GEN_URI);
     
     BinarySizeT sizeOfVector(pi.size());
     buffer << sizeOfVector;
@@ -317,44 +318,44 @@ void handout_generator(
         if (serverIPs[i] == selfIP)
             continue;
 
-        char* which;
-        if (fresh)
-            which = GIVE_FRESH_GEN_URI;
-        else
-            which = GIVE_BLIND_GEN_URI;
-
-        struct mg_connection *conn =
-            mg_connect_websocket_client(
-                serverIPs[i].c_str(),
-                PRSONA_PORT,
-                USE_SSL,
-                NULL,
-                0,
-                which,
-                "null",
-                empty_websocket_data_handler,
-                empty_websocket_close_handler,
-                NULL);
-
-        if (!conn)
+        bool flag = false;
+        while (!flag)
         {
-            cerr << "Couldn't give " << (fresh ? "fresh" : "blind") << " generator to server " << i << endl;
-            return 1;
-        }
+            struct mg_connection *conn =
+                mg_connect_websocket_client(
+                    serverIPs[i].c_str(),
+                    PRSONA_PORT,
+                    USE_SSL,
+                    NULL,
+                    0,
+                    which,
+                    "null",
+                    empty_websocket_data_handler,
+                    empty_websocket_close_handler,
+                    NULL);
+
+            if (!conn)
+            {
+                cerr << "Couldn't give " << (fresh ? "fresh" : "blind") << " generator to server " << i << endl;
+                continue;
+            }
 
-        mg_websocket_client_write(
-            conn,
-            MG_WEBSOCKET_OPCODE_BINARY,
-            data.c_str(),
-            data.length());
+            mg_websocket_client_write(
+                conn,
+                MG_WEBSOCKET_OPCODE_BINARY,
+                data.c_str(),
+                data.length());
 
-        mg_websocket_client_write(
-            conn,
-            MG_WEBSOCKET_OPCODE_DATACOMPLETE,
-            "",
-            0);
+            mg_websocket_client_write(
+                conn,
+                MG_WEBSOCKET_OPCODE_DATACOMPLETE,
+                "",
+                0);
 
-        mg_close_connection(conn);
+            mg_close_connection(conn);
+
+            flag = true;
+        }
     }
 }
 
@@ -366,19 +367,14 @@ Twistpoint initiate_epoch_updates(
 {
     Twistpoint retval;
     struct synchronization_tool epochSync;
+    const char* which = (isBreakdown ? EPOCH_BREAK_DOWN_URI : EPOCH_BUILD_UP_URI);
 
     bool flag = false;
     while (!flag)
     {
-        char* which;
-        if (isBreakdown)
-            which = EPOCH_BREAK_DOWN_URI;
-        else
-            which = EPOCH_BUILD_UP_URI;
-
         struct mg_connection *conn =
             mg_connect_websocket_client(
-                serverIPs[i].c_str(),
+                recipient.c_str(),
                 PRSONA_PORT,
                 USE_SSL,
                 NULL,
@@ -486,7 +482,6 @@ vector<Proof> epoch_build_up(
                 serverTallyCommits[0],
                 partwayVoteMatrixCommits[0],
                 finalVoteMatrixCommits[0],
-                nextGenerator[0],
                 currUserTallyMaskCommits,
                 currUserTallyMessageCommits,
                 currUserTallySeedCommits,
@@ -494,7 +489,7 @@ vector<Proof> epoch_build_up(
                 false);
 
             struct synchronization_tool epochSync;
-            epochSync->val = 1;
+            epochSync.val = 1;
             for (size_t j = 0; j < serverIPs.size(); j++)
             {
                 if (i == j)
@@ -505,7 +500,7 @@ vector<Proof> epoch_build_up(
                     data,
                     &epochSync);
             }
-            unique_lock<mutex> lck(epochSync);
+            unique_lock<mutex> lck(epochSync.mtx);
             while (epochSync.val < serverIPs.size())
                 epochSync.cv.wait(lck);
 
@@ -517,7 +512,7 @@ vector<Proof> epoch_build_up(
                 generatorProofHolder[0],
                 nextGenerator);
             nextGenerator = initiate_epoch_updates(
-                serverIPs[j],
+                serverIPs[i],
                 data,
                 generatorProofHolder,
                 false);
@@ -582,7 +577,6 @@ void epoch_break_down(
                 serverTallyCommits[0],
                 partwayVoteMatrixCommits[0],
                 finalVoteMatrixCommits[0],
-                nextGenerator[0],
                 userTallyMaskCommits[0],
                 userTallyMessageCommits[0],
                 userTallySeedCommits[0],
@@ -590,7 +584,7 @@ void epoch_break_down(
                 true);
 
             struct synchronization_tool epochSync;
-            epochSync->val = 1;
+            epochSync.val = 1;
             for (size_t j = 0; j < serverIPs.size(); j++)
             {
                 if (i == j)
@@ -612,7 +606,7 @@ void epoch_break_down(
                 generatorProof,
                 nextGenerator);
             initiate_epoch_updates(
-                serverIPs[j],
+                serverIPs[i],
                 data,
                 unused,
                 true);
@@ -657,7 +651,7 @@ void tally_scores(
 
                 if (!conn)
                 {
-                    std::cerr << "Trouble initiating epoch update with server at " << recipient << std::endl;
+                    std::cerr << "Trouble initiating epoch update with server at " << serverIPs[i] << std::endl;
                     continue;
                 }
 
@@ -668,15 +662,18 @@ void tally_scores(
                     0);
 
                 mg_close_connection(conn);
+
+                flag = true;
             }
         }
     }
 
-    unique_lock<mutex> lck(tallySync.mtx)
+    unique_lock<mutex> lck(tallySync.mtx);
     while (tallySync.val < serverIPs.size())
         tallySync.cv.wait(lck);
 
     std::vector<EGCiphertext> retval;
+    std::vector<Twistpoint> currentPseudonyms = prsonaServer->get_current_pseudonyms();
     std::vector<Scalar> decryptedTalliedScores = prsonaServer->tally_scores();
     mpz_class maxScorePossibleThisRound =
         prsonaServer->get_max_possible_score().toInt() *
@@ -703,10 +700,10 @@ void tally_scores(
 
         // Give the server the new weights,
         // to get passed around to the other servers
-        prsonaServer->bgnSystem.encrypt(
+        prsonaServer->encrypt(
             serverTallyScores[i], decryptedTalliedScores[i]);
 
-        userTallyScores[i].mask = prsonaServer->currentPseudonyms[i] * currMask;
+        userTallyScores[i].mask = currentPseudonyms[i] * currMask;
         userTallyScores[i].encryptedMessage =
             (nextGenerator * currMask) +
             (prsonaServer->get_blinding_generator() * decryptedTalliedScores[i]);
@@ -763,7 +760,7 @@ void distribute_tallied_scores(
 
                 if (!conn)
                 {
-                    std::cerr << "Trouble initiating epoch update with server at " << recipient << std::endl;
+                    std::cerr << "Trouble initiating epoch update with server at " << serverIPs[i] << std::endl;
                     continue;
                 }
 
@@ -780,11 +777,13 @@ void distribute_tallied_scores(
                     0);
 
                 mg_close_connection(conn);
+
+                flag = true;
             }
         }
     }
 
-    unique_lock<mutex> lck(tallySync.mtx)
+    unique_lock<mutex> lck(tallySync.mtx);
     while (tallySync.val < serverIPs.size())
         tallySync.cv.wait(lck);
 }
@@ -801,7 +800,7 @@ void epoch(
         lck,
         serverIPs,
         selfIP,
-        updateSync);
+        &updateSync);
 
     vector<Proof> generatorProof =
         epoch_build_up(
@@ -842,7 +841,7 @@ void epoch(
         lck,
         serverIPs,
         selfIP,
-        updateSync);
+        &updateSync);
 }
 
 class EpochReadyHandler : public CivetHandler
@@ -853,8 +852,8 @@ class EpochReadyHandler : public CivetHandler
 
         bool handleGet(CivetServer *server, struct mg_connection *conn)
         {
-            unique_lock<mutex> lck(exitSync.mtx, defer_lock);
-            unique_lock<mutex> lck(readySync.mtx);
+            unique_lock<mutex> exitLock(exitSync.mtx, defer_lock);
+            unique_lock<mutex> readyLock(readySync.mtx);
 
             if (readySync.val < numServers)
             {
@@ -863,7 +862,7 @@ class EpochReadyHandler : public CivetHandler
                           "text/plain\r\nConnection: close\r\n\r\n");
                 mg_printf(conn, "Server is waiting for other servers to begin.\n");
             }
-            else if (lck.try_lock())
+            else if (exitLock.try_lock())
             {
                 mg_printf(conn,
                           "HTTP/1.1 200 OK\r\nContent-Type: "
@@ -910,7 +909,7 @@ int main(int argc, char *argv[])
     mg_init_library(MG_FEATURES_SSL);
 #endif
     
-    const char *options[] = {"listening_ports", PRSONA_PORT, 0};
+    const char *options[] = {"listening_ports", PRSONA_PORT_STR, 0};
 
     vector<string> serverIPs;
     string selfIP, dealerIP;
@@ -973,38 +972,44 @@ int main(int argc, char *argv[])
     {
         cout << "Retrieving BGN details." << endl;
 
-        struct mg_connection *conn =
-            mg_connect_websocket_client(
-                dealerIP.c_str(),
-                PRSONA_PORT,
-                USE_SSL,
-                NULL,
-                0,
-                BGN_URI,
-                "null",
-                bgn_websocket_data_handler,
-                bgn_websocket_close_handler,
-                NULL);
-
-        if (!conn)
+        bool flag = false;
+        while (!flag)
         {
-            cerr << "Couldn't obtain BGN details." << endl;
-            return 1;
-        }
+            struct mg_connection *conn =
+                mg_connect_websocket_client(
+                    dealerIP.c_str(),
+                    PRSONA_PORT,
+                    USE_SSL,
+                    NULL,
+                    0,
+                    PRIVATE_BGN_URI,
+                    "null",
+                    bgn_websocket_data_handler,
+                    bgn_websocket_close_handler,
+                    NULL);
+
+            if (!conn)
+            {
+                cerr << "Couldn't obtain BGN details." << endl;
+                continue;
+            }
 
-        unique_lock<mutex> lck(bgnSync.mtx);
-        remove(BGN_TMP_FILE);
-        bgnSync.val = 0;
-        mg_websocket_client_write(
-            conn,
-            MG_WEBSOCKET_OPCODE_DATACOMPLETE,
-            "",
-            0);
+            unique_lock<mutex> lck(bgnSync.mtx);
+            remove(BGN_TMP_FILE);
+            bgnSync.val = 0;
+            mg_websocket_client_write(
+                conn,
+                MG_WEBSOCKET_OPCODE_DATACOMPLETE,
+                "",
+                0);
 
-        while (!bgnSync.val)
-            bgnSync.cv.wait(lck);
+            while (!bgnSync.val)
+                bgnSync.cv.wait(lck);
 
-        mg_close_connection(conn);
+            mg_close_connection(conn);
+
+            flag = true;
+        }
 
         prsonaServer = create_server_from_bgn_file(numServers);
     }
@@ -1028,14 +1033,14 @@ int main(int argc, char *argv[])
 
         vector<Proof> pi;
         Twistpoint freshGenerator =
-            get_generator(pi, prsonaServer, serverIPs, true);
+            get_generator(pi, prsonaServer, serverIPs, selfIP, true);
 
-        handout_generator(pi, freshGenerator, prsonaServer, serverIPs, true);
+        handout_generator(pi, freshGenerator, prsonaServer, serverIPs, selfIP, true);
 
         Twistpoint blindGenerator =
-            get_generator(pi, prsonaServer, serverIPs, false);
+            get_generator(pi, prsonaServer, serverIPs, selfIP, false);
 
-        handout_generator(pi, freshGenerator, prsonaServer, serverIPs, false);
+        handout_generator(pi, blindGenerator, prsonaServer, serverIPs, selfIP, false);
     }
     else
     {
@@ -1046,7 +1051,7 @@ int main(int argc, char *argv[])
 
         struct mg_connection *conn =
             mg_connect_client(
-                dealerIP, 
+                dealerIP.c_str(), 
                 PRSONA_PORT,
                 USE_SSL, 
                 NULL,
@@ -1088,7 +1093,7 @@ int main(int argc, char *argv[])
             {
                 cout << "Executing epoch." << endl;
 
-                epoch(prsonaServer);
+                epoch(prsonaServer, serverIPs, selfIP);
 
                 exitSync.val2 = 0;
             }
@@ -1097,7 +1102,7 @@ int main(int argc, char *argv[])
     else
     {
         while (!exitSync.val)
-            exitSync.cv.wait(exitLock)
+            exitSync.cv.wait(exitLock);
     }
 
     cout << "Shutting down." << endl;