Browse Source

various bugfixes, and further establishing the environment for testing

tristangurtler 3 years ago
parent
commit
3980749a6c

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 **/bin/
 **/obj/
+**/tmp/

+ 7 - 3
prsona/Makefile

@@ -2,12 +2,14 @@ INC_PATH = inc
 SRC_PATH = src
 OBJ_PATH = obj
 BIN_PATH = bin
+TMP_PATH = tmp
 
 PRSONA_PATH = .
 PRSONA_INC_PATH = $(PRSONA_PATH)/$(INC_PATH)
 PRSONA_SRC_PATH = $(PRSONA_PATH)/$(SRC_PATH)
 PRSONA_OBJ_PATH = $(PRSONA_PATH)/$(OBJ_PATH)
 PRSONA_BIN_PATH = $(PRSONA_PATH)/$(BIN_PATH)
+PRSONA_TMP_PATH = $(PRSONA_PATH)/$(TMP_PATH)
 
 BGN_PATH = ../BGN2/bgn2
 BGN_INC_PATH = $(BGN_PATH)/$(INC_PATH)
@@ -36,11 +38,13 @@ CC = gcc
 CFLAGS = -std=c99 -O3 -fomit-frame-pointer -I$(666_INC_PATH) -I$(MG_INC_PATH)
 C_LDFLAGS = -lm
 
+all : main server client orchestrator
+
 main: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_BIN_PATH)/main
 
-server: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_BIN_PATH)/server
-client: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_BIN_PATH)/client
-orchestrator: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_BIN_PATH)/orchestrator
+server: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_TMP_PATH) $(PRSONA_BIN_PATH)/server
+client: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_TMP_PATH) $(PRSONA_BIN_PATH)/client
+orchestrator: $(PRSONA_BIN_PATH) $(PRSONA_OBJ_PATH) $(BGN_OBJ_PATH) $(666_OBJ_PATH) $(PRSONA_TMP_PATH) $(PRSONA_BIN_PATH)/orchestrator
 
 $(PRSONA_BIN_PATH):
 	mkdir -p $@

+ 1 - 0
prsona/cfg/clientIPs.cfg

@@ -0,0 +1 @@
+127.0.0.1:8082

+ 0 - 0
prsona/cfg/commands.cfg


+ 1 - 0
prsona/cfg/dealerIP.cfg

@@ -0,0 +1 @@
+127.0.0.1:8080

+ 1 - 0
prsona/cfg/selfIP-c0.cfg

@@ -0,0 +1 @@
+127.0.0.1:8082

+ 1 - 0
prsona/cfg/selfIP-c1.cfg

@@ -0,0 +1 @@
+127.0.0.1:8083

+ 1 - 0
prsona/cfg/selfIP-c2.cfg

@@ -0,0 +1 @@
+127.0.0.1:8084

+ 1 - 0
prsona/cfg/selfIP-c3.cfg

@@ -0,0 +1 @@
+127.0.0.1:8085

+ 1 - 0
prsona/cfg/selfIP-c4.cfg

@@ -0,0 +1 @@
+127.0.0.1:8086

+ 1 - 0
prsona/cfg/selfIP-d.cfg

@@ -0,0 +1 @@
+127.0.0.1:8080

+ 1 - 0
prsona/cfg/selfIP-s1.cfg

@@ -0,0 +1 @@
+127.0.0.1:8081

+ 2 - 0
prsona/cfg/serverIPs.cfg

@@ -0,0 +1,2 @@
+127.0.0.1:8080
+127.0.0.1:8081

+ 11 - 4
prsona/inc/networkClient.hpp

@@ -18,7 +18,7 @@ class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
         PrsonaClientWebSocketHandler(
             PrsonaClient *prsonaClient, 
             const std::vector<std::string>& serverIPs,
-            const std::string& selfIP,
+            const std::vector<int>& serverPorts,
             std::default_random_engine *generator);
 
         virtual bool handleConnection(
@@ -43,7 +43,7 @@ class PrsonaClientWebSocketHandler : public CivetWebSocketHandler {
     private:
         PrsonaClient *prsonaClient;
         const std::vector<std::string> serverIPs;
-        const std::string selfIP;
+        const std::vector<int> serverPorts;
         std::default_random_engine *generator;
 
         void generate_response(
@@ -63,7 +63,9 @@ T get_committed_val_from_file(
 
 template <typename T>
 T get_first_committed_val(
+    std::default_random_engine *rng,
     const std::string& server,
+    int serverPort,
     Proof& pi,
     const Twistpoint& shortTermPublicKey,
     const char *firstUri);
@@ -73,8 +75,11 @@ Proof get_commitment_from_file(
     char *filename);
 
 void get_additional_commitment(
-    const std::vector<std::string>& servers,
-    const std::string& skip,
+    std::default_random_engine *rng,
+    const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
+    const std::string& skipIP,
+    int skipPort,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
     char *which);
@@ -83,6 +88,7 @@ template <typename T>
 T get_server_committed_val(
     std::default_random_engine *generator,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
     const char *firstUri,
@@ -96,6 +102,7 @@ Twistpoint get_generator_from_file(
 Twistpoint get_generator(
     std::default_random_engine *randomGenerator,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     std::vector<Proof>& pi,
     bool fresh);
 

+ 14 - 2
prsona/inc/networkServer.hpp

@@ -1,6 +1,7 @@
 #ifndef __PRSONA_NETWORK_SERVER_HPP
 #define __PRSONA_NETWORK_SERVER_HPP
 
+#include <random>
 #include <string>
 #include <vector>
 #include <atomic>
@@ -11,13 +12,17 @@
 void obtain_update_locks(
     std::unique_lock<std::mutex> &lck,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     const std::string& selfIP,
+    int selfPort,
     struct synchronization_tool *synch);
 
 void release_update_locks(
     std::unique_lock<std::mutex> &lck,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     const std::string& selfIP,
+    int selfPort,
     struct synchronization_tool *synch);
 
 std::string make_epoch_initiator_string(
@@ -40,6 +45,7 @@ std::string make_epoch_update_string(
 
 void distribute_epoch_updates(
     const std::string& recipient,
+    int recipientPort,
     const std::string& data,
     const struct synchronization_tool* sync);
 
@@ -47,11 +53,14 @@ class PrsonaServerWebSocketHandler : public CivetWebSocketHandler  {
     public:
         // CONSTRUCTORS
         PrsonaServerWebSocketHandler(
-            PrsonaServer *prsonaServer, 
+            PrsonaServer *prsonaServer,
+            std::default_random_engine *rng, 
             std::mutex *updateMtx,
             std::atomic<size_t> *epochNum,
             const std::vector<std::string>& serverIPs,
-            const std::string& selfIP);
+            const std::vector<int>& serverPorts,
+            const std::string& selfIP,
+            int selfPort);
 
         virtual bool handleConnection(
             CivetServer *server,
@@ -74,10 +83,13 @@ class PrsonaServerWebSocketHandler : public CivetWebSocketHandler  {
 
     private:
         PrsonaServer *prsonaServer;
+        std::default_random_engine *rng;
         std::mutex *updateMtx;
         std::atomic<size_t> *epochNum;
         const std::vector<std::string> serverIPs;
+        const std::vector<int> serverPorts;
         const std::string selfIP;
+        const int selfPort;
 
         struct synchronization_tool updateSynch, distributeSynch;
 

+ 9 - 4
prsona/inc/networking.hpp

@@ -8,7 +8,6 @@
 #include "CivetServer.h"
 
 #define MG_WEBSOCKET_OPCODE_DATACOMPLETE 0xb
-#define PRSONA_PORT 8080
 #define PRSONA_PORT_STR "8080"
 #define USE_SSL 0
 
@@ -26,9 +25,15 @@
 #define PUBLIC_BGN_URI "/ws?c"
 #define NUM_CLIENTS_URI "/ws?d"
 #define VOTES_BY_URI "/ws?f"
+#define VOTE_MATRIX_URI "/ws?g"
 #define USER_TALLY_URI "/ws?h"
+#define SERVER_TALLY_URI "/ws?i"
+#define PSEUDONYMS_URI "/ws?j"
 #define VOTES_BY_COMMIT_URI "/ws?k"
+#define VOTE_MATRIX_COMMIT_URI "/ws?l"
 #define USER_TALLY_COMMIT_URI "/ws?m"
+#define SERVER_TALLY_COMMIT_URI "/ws?n"
+#define PSEUDONYMS_COMMIT_URI "/ws?o"
 #define PRIVATE_BGN_URI "/ws?p"
 #define GET_FRESH_GEN_URI "/ws?q"
 #define GIVE_FRESH_GEN_URI "/ws?r"
@@ -45,7 +50,7 @@
 #define REP_PROOF_URI "/ws?d"
 
 #define TMP_FILE_SIZE 12
-#define TMP_DIR "~/tmp/"
+#define TMP_DIR "./tmp/"
 #define TMP_DIR_SIZE 6
 
 enum RequestType {
@@ -89,8 +94,8 @@ struct synchronization_tool {
     size_t val, val2;
 };
 
-std::string random_string(size_t length);
-char *set_temp_filename(struct mg_connection *conn);
+std::string random_string(std::default_random_engine& generator, size_t length);
+char *set_temp_filename(std::default_random_engine& generator, struct mg_connection *conn);
 
 class RemoteControlHandler : public CivetHandler
 {

+ 2 - 0
prsona/inc/proof.hpp

@@ -32,6 +32,8 @@ class Proof {
         std::vector<Scalar> challengeParts;
         std::vector<Scalar> responseParts;
 
+        bool operator==(const Proof& b);
+
         friend std::ostream& operator<<(std::ostream& os, const Proof& output);
         friend std::istream& operator>>(std::istream& is, Proof& input);
 };

+ 3 - 0
prsona/src/base.cpp

@@ -101,7 +101,10 @@ bool PrsonaBase::set_EG_blind_generator(
     size_t numServers)
 {
     if (!verify_generator_proof(pi, currGenerator, numServers))
+    {
+        std::cerr << "Could not set EG blind generator correctly." << std::endl;
         return false;
+    }
 
     elGamalBlindGeneratorProof = pi;
     elGamalBlindGenerator = currGenerator;

+ 303 - 35
prsona/src/clientMain.cpp

@@ -38,9 +38,31 @@ BGNPublicKey get_bgn_public_key_from_file(
     return publicKey;
 }
 
+vector<Proof> get_valid_addition_proof_from_file(
+    struct synchronization_tool *sync,
+    const char *filename)
+{
+    unique_lock<mutex> lck(sync->mtx);
+    ifstream additionFile(filename);
+
+    vector<Proof> retval;
+
+    BinarySizeT sizeOfVector;
+    additionFile >> sizeOfVector;
+    for (size_t i = 0; i < sizeOfVector.val(); i++)
+    {
+        Proof currProof;
+        additionFile >> currProof;
+        retval.push_back(currProof);
+    }
+
+    return retval;
+}
+
 BGNPublicKey get_bgn_public_key(
     default_random_engine *randomGenerator,
-    const vector<string>& serverIPs)
+    const vector<string>& serverIPs,
+    const vector<int>& serverPorts)
 {
     struct synchronization_tool sync;
     char *filename = NULL;
@@ -53,7 +75,7 @@ BGNPublicKey get_bgn_public_key(
     {
         struct mg_connection *conn = mg_connect_websocket_client(
             serverIPs[whichServer].c_str(),
-            PRSONA_PORT,
+            serverPorts[whichServer],
             USE_SSL,
             NULL,
             0,
@@ -70,7 +92,7 @@ BGNPublicKey get_bgn_public_key(
         }
 
         unique_lock<mutex> lck(sync.mtx);
-        filename = set_temp_filename(conn);
+        filename = set_temp_filename(*randomGenerator, conn);
         sync.val = 0;
 
         mg_websocket_client_write(
@@ -96,25 +118,181 @@ BGNPublicKey get_bgn_public_key(
     return retval;
 }
 
+void verify_valid_addition(
+    PrsonaClient *newUser,
+    default_random_engine *rng,
+    const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
+    const vector<Proof>& proofOfValidAddition,
+    const Twistpoint& shortTermPublicKey)
+{
+    vector<Proof> serverEncryptedScoreProof;
+    CurveBipoint serverEncryptedScore =
+        get_server_committed_val<CurveBipoint>(
+            rng,
+            serverIPs,
+            serverPorts,
+            serverEncryptedScoreProof,
+            shortTermPublicKey,
+            SERVER_TALLY_URI,
+            SERVER_TALLY_COMMIT_URI);
+
+    vector<Proof> userEncryptedScoreProof;
+    EGCiphertext userEncryptedScore =
+        get_server_committed_val<EGCiphertext>(
+            rng,
+            serverIPs,
+            serverPorts,
+            userEncryptedScoreProof,
+            shortTermPublicKey,
+            USER_TALLY_URI,
+            USER_TALLY_COMMIT_URI);
+
+    vector<Proof> voteMatrixProof;
+    vector<vector<TwistBipoint>> voteMatrix =
+        get_server_committed_val<vector<vector<TwistBipoint>>>(
+            rng,
+            serverIPs,
+            serverPorts,
+            voteMatrixProof,
+            shortTermPublicKey,
+            VOTE_MATRIX_URI,
+            VOTE_MATRIX_COMMIT_URI);
+
+    vector<Proof> pseudonymsProof;
+    vector<Twistpoint> currentPseudonyms =
+        get_server_committed_val<vector<Twistpoint>>(
+            rng,
+            serverIPs,
+            serverPorts,
+            pseudonymsProof,
+            shortTermPublicKey,
+            PSEUDONYMS_URI,
+            PSEUDONYMS_COMMIT_URI);
+
+    newUser->receive_new_user_data(
+        proofOfValidAddition,
+        serverEncryptedScoreProof,
+        serverEncryptedScore,
+        userEncryptedScoreProof,
+        userEncryptedScore,
+        voteMatrixProof,
+        voteMatrix,
+        pseudonymsProof,
+        currentPseudonyms);
+}
+
+void register_new_client(
+    default_random_engine *generator,
+    const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
+    PrsonaClient *newUser,
+    const Proof& proofOfValidSTPK,
+    const Twistpoint& shortTermPublicKey)
+{
+    struct synchronization_tool sync;
+    char *filename = NULL;
+    stringstream buffer;
+    string data;
+
+    buffer << proofOfValidSTPK;
+    buffer << shortTermPublicKey;
+
+    data = buffer.str();
+
+    uniform_int_distribution<size_t> distribution(0, serverIPs.size() - 1);
+    size_t whichServer = distribution(*generator);
+
+    bool flag = false;
+    while (!flag)
+    {
+        struct mg_connection *conn = mg_connect_websocket_client(
+            serverIPs[whichServer].c_str(),
+            serverPorts[whichServer],
+            USE_SSL,
+            NULL,
+            0,
+            PUBLIC_BGN_URI,
+            "null",
+            file_websocket_data_handler,
+            file_websocket_close_handler,
+            (void *) &sync);
+
+        if (!conn)
+        {
+            cerr << "Couldn't register new client" << endl;
+            continue;
+        }
+
+        unique_lock<mutex> lck(sync.mtx);
+        filename = set_temp_filename(*generator, conn);
+        sync.val = 0;
+        mg_websocket_client_write(
+            conn,
+            MG_WEBSOCKET_OPCODE_BINARY,
+            data.c_str(),
+            data.length());
+
+        mg_websocket_client_write(
+            conn,
+            MG_WEBSOCKET_OPCODE_DATACOMPLETE,
+            "",
+            0);
+
+        while (!sync.val)
+            sync.cv.wait(lck);
+
+        mg_close_connection(conn);
+
+        flag = true;
+    }
+
+    vector<Proof> proofOfValidAddition = 
+        get_valid_addition_proof_from_file(&sync, filename);
+
+    remove(filename);
+    delete filename;
+
+    verify_valid_addition(newUser, generator, serverIPs, serverPorts, proofOfValidAddition, shortTermPublicKey);
+}
+
 PrsonaClient *create_client(
     default_random_engine *generator,
-    const vector<string> serverIPs,
+    const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     size_t numServers)
 {
     BGNPublicKey publicKey =
         get_bgn_public_key(
             generator,
-            serverIPs);
+            serverIPs,
+            serverPorts);
 
     vector<Proof> generatorProof;
     Twistpoint blindGenerator =
         get_generator(
             generator,
             serverIPs,
+            serverPorts,
             generatorProof,
             false);
 
-    return new PrsonaClient(generatorProof, blindGenerator, publicKey, numServers);
+    PrsonaClient *retval =
+        new PrsonaClient(generatorProof, blindGenerator, publicKey, numServers);
+
+    Proof proofOfValidSTPK;
+    Twistpoint shortTermPublicKey = retval->get_short_term_public_key(
+                                        proofOfValidSTPK);
+
+    register_new_client(
+        generator,
+        serverIPs,
+        serverPorts,
+        retval,
+        proofOfValidSTPK,
+        shortTermPublicKey);
+
+    return retval;
 }
 
 string make_vote_string(
@@ -144,7 +322,7 @@ string make_vote_string(
 }
 
 void send_item(
-    const string& target, const string& data, const char* whichUri)
+    const string& target, int targetPort, const string& data, const char* whichUri)
 {
     struct synchronization_tool sync;
     bool flag = false;
@@ -152,7 +330,7 @@ void send_item(
     {
         struct mg_connection *conn = mg_connect_websocket_client(
             target.c_str(),
-            PRSONA_PORT,
+            targetPort,
             USE_SSL,
             NULL,
             0,
@@ -195,8 +373,10 @@ void send_item(
 void make_vote(
     default_random_engine& generator,
     const string& target,
+    int targetPort,
     PrsonaClient* prsonaClient,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     size_t numClients)
 {
     uniform_int_distribution<int> voteDistribution(
@@ -220,6 +400,7 @@ void make_vote(
         get_generator(
             &generator,
             serverIPs,
+            serverPorts,
             generatorProof,
             true);
 
@@ -234,6 +415,7 @@ void make_vote(
         get_server_committed_val<vector<TwistBipoint>>(
             &generator,
             serverIPs,
+            serverPorts,
             fullProof,
             shortTermPublicKey,
             VOTES_BY_URI,
@@ -251,7 +433,7 @@ void make_vote(
     string data =
         make_vote_string(voteProof, encryptedVotes, shortTermPublicKey);
 
-    send_item(target, data, GIVE_NEW_VOTE_URI);
+    send_item(target, targetPort, data, GIVE_NEW_VOTE_URI);
 }
 
 string make_vote_string(
@@ -296,8 +478,10 @@ string make_rep_proof_string(
 void make_reputation_proof(
     default_random_engine& generator,
     const string& target,
+    int targetPort,
     PrsonaClient* prsonaClient,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     size_t numClients)
 {
     vector<Proof> generatorProof;
@@ -305,6 +489,7 @@ void make_reputation_proof(
         get_generator(
             &generator,
             serverIPs,
+            serverPorts,
             generatorProof,
             true);
 
@@ -319,6 +504,7 @@ void make_reputation_proof(
         get_server_committed_val<EGCiphertext>(
             &generator,
             serverIPs,
+            serverPorts,
             encryptedScoreProof,
             shortTermPublicKey,
             USER_TALLY_URI,
@@ -337,7 +523,7 @@ void make_reputation_proof(
     string data =
         make_rep_proof_string(repProof, shortTermPublicKey, threshold);
 
-    send_item(target, data, REP_PROOF_URI);
+    send_item(target, targetPort, data, REP_PROOF_URI);
 }
 
 int main(int argc, char *argv[])
@@ -349,37 +535,100 @@ int main(int argc, char *argv[])
 #else
     mg_init_library(MG_FEATURES_SSL);
 #endif
-    
-    const char *options[] = {"listening_ports", PRSONA_PORT_STR, 0};
 
-    vector<string> serverIPs, clientIPs;
-    string selfIP;
+    string id = "";
+    if (argc > 1)
+        id = argv[1];
 
-    string seedStr = "seed";
+    string seedStr;
+    if (id.empty())
+        seedStr = "default-client";
+    else
+    {
+        seedStr = id;
+        seedStr += "-client";
+    }
+    
+    vector<string> serverIPs, clientIPs;
+    vector<int> serverPorts, clientPorts;
+    string selfIP, selfPortStr;
+    int selfPort = 0;
 
-    char buffer[40];
-    ifstream serverConfig("serverIPs.cfg");
+    char buffer[46], *helper;
+    ifstream serverConfig("cfg/serverIPs.cfg");
     while (!serverConfig.eof())
     {
-        serverConfig.getline(buffer, 40);
+        serverConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            serverIPs.push_back(string(buffer));
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                serverIPs.push_back(string(helper));
+                helper = strtok(NULL, ":");
+                serverPorts.push_back(atoi(helper));
+            }
+            else
+            {
+                serverIPs.push_back(string(helper));
+                serverPorts.push_back(atoi(PRSONA_PORT_STR));
+            }
+        }
     }
 
-    ifstream clientConfig("clientIPs.cfg");
+    ifstream clientConfig("cfg/clientIPs.cfg");
     while (!clientConfig.eof())
     {
-        clientConfig.getline(buffer, 40);
+        clientConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            clientIPs.push_back(string(buffer));
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                clientIPs.push_back(string(helper));
+                helper = strtok(NULL, ":");
+                clientPorts.push_back(atoi(helper));
+            }
+            else
+            {
+                clientIPs.push_back(string(helper));
+                clientPorts.push_back(atoi(PRSONA_PORT_STR));
+            }
+        }
+    }
+
+    string selfConfigFilename = "cfg/selfIP";
+    if (!id.empty())
+    {
+        selfConfigFilename += "-";
+        selfConfigFilename += id;
     }
+    selfConfigFilename += ".cfg";
 
-    ifstream selfConfig("selfIP.cfg");
+    ifstream selfConfig(selfConfigFilename);
     while (!selfConfig.eof())
     {
-        selfConfig.getline(buffer, 40);
+        selfConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            selfIP = buffer;
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                selfIP = helper;
+                helper = strtok(NULL, ":");
+                selfPortStr = helper;
+                selfPort = atoi(helper);
+            }
+            else
+            {
+                selfIP = helper;
+                selfPortStr = PRSONA_PORT_STR;
+                selfPort = atoi(PRSONA_PORT_STR);
+            }
+        }
     }
 
     // Defaults
@@ -388,20 +637,22 @@ int main(int argc, char *argv[])
     bool maliciousServers = true;
     uniform_int_distribution<size_t> distribution(0, numServers - 1);
 
-    if (argc > 1)
+    const char *options[] = {"listening_ports", selfPortStr.c_str(), 0};
+
+    if (argc > 2)
     {
-        bool setting = argv[1][0] == 't' || argv[1][0] == 'T';
+        bool setting = argv[2][0] == 't' || argv[2][0] == 'T';
         maliciousServers = setting;
     }
 
     seed_seq seed(seedStr.begin(), seedStr.end());
     default_random_engine generator(seed);
 
-    cout << "Establishing PRSONA client with the following parameters: " << endl;
-    cout << numServers << " PRSONA servers" << endl;
-    cout << numClients << " PRSONA clients" << endl;
-    cout << "Servers are set to " << (maliciousServers ? "MALICIOUS" : "HBC") << " security" << endl;
-    cout << "This client is at IP address: " << selfIP << endl;
+    cout << "[" << seedStr << "] Establishing PRSONA client with the following parameters: " << endl;
+    cout << "[" << seedStr << "] " << numServers << " PRSONA servers" << endl;
+    cout << "[" << seedStr << "] " << numClients << " PRSONA clients" << endl;
+    cout << "[" << seedStr << "] Servers are set to " << (maliciousServers ? "MALICIOUS" : "HBC") << " security" << endl;
+    cout << "[" << seedStr << "] This client is at IP address: " << selfIP << ":" << selfPort << endl;
     cout << endl;
 
     // Set malicious flags where necessary
@@ -409,11 +660,14 @@ int main(int argc, char *argv[])
         PrsonaBase::set_server_malicious();
 
     // Entities we operate with
+    cout << "[" << seedStr << "] Creating PRSONA client." << endl;
     PrsonaClient *prsonaClient =
-        create_client(&generator, serverIPs, numServers);
+        create_client(&generator, serverIPs, serverPorts, numServers);
     CivetServer server(options);
 
-    PrsonaClientWebSocketHandler wsHandler(prsonaClient, serverIPs, selfIP, &generator);
+    cout << "[" << seedStr << "] Setting up handlers for client." << endl;
+
+    PrsonaClientWebSocketHandler wsHandler(prsonaClient, serverIPs, serverPorts, &generator);
     server.addWebSocketHandler("/ws", wsHandler);
 
     unique_lock<mutex> exitLock(exitSync.mtx);
@@ -428,12 +682,17 @@ int main(int argc, char *argv[])
     AltRemoteControlHandler triggerRepHandler(CLIENT_MAKE_REP_PROOF, &exitSync, "Client will make new votes!");
     server.addHandler(TRIGGER_REP_URI, triggerRepHandler);
 
+    cout << "[" << seedStr << "] Entering main ready loop." << endl;
+
     while (!exitSync.val)
     {
         while (!exitSync.val && !exitSync.val2)
             exitSync.cv.wait(exitLock);
 
         size_t whichServer = distribution(generator);
+        string fullQuery, target;
+        size_t colonLocation;
+        int targetPort;
 
         switch (exitSync.val2)
         {
@@ -441,17 +700,26 @@ int main(int argc, char *argv[])
                 make_vote(
                     generator,
                     serverIPs[whichServer],
+                    serverPorts[whichServer],
                     prsonaClient,
                     serverIPs,
+                    serverPorts,
                     numClients);
                 break;
 
             case CLIENT_MAKE_REP_PROOF:
+                fullQuery = triggerRepHandler.getQuery();
+                colonLocation = fullQuery.find(":");
+
+                target = fullQuery.substr(0, colonLocation);
+                targetPort = stoi(fullQuery.substr(colonLocation + 1));
                 make_reputation_proof(
                     generator,
-                    triggerRepHandler.getQuery(),
+                    target,
+                    targetPort,
                     prsonaClient,
                     serverIPs,
+                    serverPorts,
                     numClients);
                 break;
 

+ 27 - 0
prsona/src/main.cpp

@@ -34,6 +34,31 @@ void print_user_scores(const vector<PrsonaClient>& users)
     std::cout << std::endl;
 }
 
+bool test_proof_output(const vector<Proof>& pi)
+{
+    vector<Proof> copy;
+    stringstream buffer;
+    for (size_t i = 0; i < pi.size(); i++)
+    {
+        Proof currProof;
+        buffer << pi[i];
+        buffer >> currProof;
+        copy.push_back(currProof);
+    }
+
+    bool retval = true;
+    for (size_t i = 0; i < pi.size(); i++)
+    {
+        if (!(copy[i] == pi[i]))
+            cout << "FAILURE at index " << i+1 << " of " << pi.size() << endl;
+        retval = retval && copy[i] == pi[i];
+    }
+
+    cout << "TEST PROOF OUTPUT: " << (retval ? "PASSED" : "FAILED") << endl;
+
+    return retval;
+}
+
 // Time how long it takes to make a proof of valid votes
 vector<double> make_votes(
     default_random_engine& generator,
@@ -480,6 +505,8 @@ int main(int argc, char *argv[])
     Twistpoint elGamalBlindGenerator =
         servers.get_blinding_generator(elGamalBlindGeneratorProof);
 
+    test_proof_output(elGamalBlindGeneratorProof);
+
     cout << "Initialization: adding users to system" << endl << endl;
     vector<PrsonaClient> users;
     for (size_t i = 0; i < numUsers; i++)

+ 134 - 18
prsona/src/networkClient.cpp

@@ -20,6 +20,22 @@ EGCiphertext get_committed_val_from_file<EGCiphertext>(
     return retval;
 }
 
+template <>
+CurveBipoint get_committed_val_from_file<CurveBipoint>(
+    struct synchronization_tool *sync,
+    const char *filename,
+    Proof& pi)
+{
+    std::unique_lock<std::mutex> lck(sync->mtx);
+    std::ifstream valFile(filename);
+
+    CurveBipoint retval;
+    valFile >> pi;
+    valFile >> retval;
+
+    return retval;
+}
+
 template <>
 std::vector<TwistBipoint> get_committed_val_from_file<std::vector<TwistBipoint>>(
     struct synchronization_tool *sync,
@@ -46,9 +62,68 @@ std::vector<TwistBipoint> get_committed_val_from_file<std::vector<TwistBipoint>>
     return retval;
 }
 
+template <>
+std::vector<Twistpoint> get_committed_val_from_file<std::vector<Twistpoint>>(
+    struct synchronization_tool *sync,
+    const char *filename,
+    Proof& pi)
+{
+    std::unique_lock<std::mutex> lck(sync->mtx);
+    std::ifstream valFile(filename);
+
+    valFile >> pi;
+
+    std::vector<Twistpoint> retval;
+
+    BinarySizeT sizeOfVector;
+    valFile >> sizeOfVector;
+    for (size_t i = 0; i < sizeOfVector.val(); i++)
+    {
+        Twistpoint currVote;
+        valFile >> currVote;
+
+        retval.push_back(currVote);
+    }
+
+    return retval;
+}
+
+template <>
+std::vector<std::vector<TwistBipoint>> get_committed_val_from_file<std::vector<std::vector<TwistBipoint>>>(
+    struct synchronization_tool *sync,
+    const char *filename,
+    Proof& pi)
+{
+    std::unique_lock<std::mutex> lck(sync->mtx);
+    std::ifstream valFile(filename);
+
+    valFile >> pi;
+
+    std::vector<std::vector<TwistBipoint>> retval;
+
+    BinarySizeT sizeOfVector;
+    valFile >> sizeOfVector;
+    for (size_t i = 0; i < sizeOfVector.val(); i++)
+    {
+        std::vector<TwistBipoint> currRow;
+        for (size_t j = 0; j < sizeOfVector.val(); j++)
+        {
+            TwistBipoint currVote;
+            valFile >> currVote;
+
+            currRow.push_back(currVote);    
+        }
+        retval.push_back(currRow);
+    }
+
+    return retval;
+}
+
 template <typename T>
 T get_first_committed_val(
-    const std::string& server,
+    std::default_random_engine *rng,
+    const std::string& serverIP,
+    int serverPort,
     Proof& pi,
     const Twistpoint& shortTermPublicKey,
     const char *firstUri)
@@ -68,8 +143,8 @@ T get_first_committed_val(
     {
         struct mg_connection *conn =
             mg_connect_websocket_client(
-                server.c_str(),
-                PRSONA_PORT,
+                serverIP.c_str(),
+                serverPort,
                 USE_SSL,
                 NULL,
                 0,
@@ -81,12 +156,12 @@ T get_first_committed_val(
 
         if (!conn)
         {
-            std::cerr << "Trouble getting encrypted score from server at " << server << std::endl;
+            std::cerr << "Trouble getting encrypted score from server at " << serverIP << ":" << serverPort << std::endl;
             continue;
         }
 
         std::unique_lock<std::mutex> lck(sync.mtx);
-        filename = set_temp_filename(conn);
+        filename = set_temp_filename(*rng, conn);
         sync.val = 0;
 
         mg_websocket_client_write(
@@ -131,8 +206,11 @@ Proof get_commitment_from_file(
 }
 
 void get_additional_commitment(
-    const std::vector<std::string>& servers,
-    const std::string& skip,
+    std::default_random_engine *rng,
+    const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
+    const std::string& skipIP,
+    int skipPort,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
     const char *commitUri)
@@ -140,9 +218,9 @@ void get_additional_commitment(
     std::vector<char *> commitmentFilenames;
     std::vector<struct synchronization_tool *> commitmentSyncs;
 
-    for (size_t i = 0; i < servers.size(); i++)
+    for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (servers[i] == skip)
+        if (serverIPs[i] == skipIP && serverPorts[i] == skipPort)
             continue;
 
         struct synchronization_tool *currSync = new struct synchronization_tool;
@@ -153,8 +231,8 @@ void get_additional_commitment(
         {
             struct mg_connection *conn =
                 mg_connect_websocket_client(
-                    servers[i].c_str(),
-                    PRSONA_PORT,
+                    serverIPs[i].c_str(),
+                    serverPorts[i],
                     USE_SSL,
                     NULL,
                     0,
@@ -166,13 +244,13 @@ void get_additional_commitment(
 
             if (!conn)
             {
-                std::cerr << "Trouble getting commitment from server at " << servers[i] << std::endl;
+                std::cerr << "Trouble getting commitment from server at " << serverIPs[i] << ":" << serverPorts[i] << std::endl;
                 continue;
             }
 
             std::unique_lock<std::mutex> lck(currSync->mtx);
             currSync->val = 0;
-            commitmentFilenames.push_back(set_temp_filename(conn));
+            commitmentFilenames.push_back(set_temp_filename(*rng, conn));
 
             mg_websocket_client_write(
                 conn,
@@ -206,6 +284,7 @@ template <typename T>
 T get_server_committed_val(
     std::default_random_engine *generator,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
     const char *firstUri,
@@ -219,7 +298,9 @@ T get_server_committed_val(
     Proof firstProof;
     T retval =
         get_first_committed_val<T>(
+            generator,
             serverIPs[whichServer],
+            serverPorts[whichServer],
             firstProof,
             shortTermPublicKey,
             firstUri);
@@ -227,8 +308,11 @@ T get_server_committed_val(
     pi.push_back(firstProof);
 
     get_additional_commitment(
+        generator,
         serverIPs,
+        serverPorts,
         serverIPs[whichServer],
+        serverPorts[whichServer],
         pi,
         shortTermPublicKey,
         commitUri);
@@ -239,6 +323,25 @@ T get_server_committed_val(
 template EGCiphertext get_server_committed_val<EGCiphertext>(
     std::default_random_engine *generator,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
+    std::vector<Proof>& pi,
+    const Twistpoint& shortTermPublicKey,
+    const char *firstUri,
+    const char *commitUri);
+
+template CurveBipoint get_server_committed_val<CurveBipoint>(
+    std::default_random_engine *generator,
+    const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
+    std::vector<Proof>& pi,
+    const Twistpoint& shortTermPublicKey,
+    const char *firstUri,
+    const char *commitUri);
+
+template std::vector<Twistpoint> get_server_committed_val<std::vector<Twistpoint>>(
+    std::default_random_engine *generator,
+    const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
     const char *firstUri,
@@ -247,6 +350,16 @@ template EGCiphertext get_server_committed_val<EGCiphertext>(
 template std::vector<TwistBipoint> get_server_committed_val<std::vector<TwistBipoint>>(
     std::default_random_engine *generator,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
+    std::vector<Proof>& pi,
+    const Twistpoint& shortTermPublicKey,
+    const char *firstUri,
+    const char *commitUri);
+
+template std::vector<std::vector<TwistBipoint>> get_server_committed_val<std::vector<std::vector<TwistBipoint>>>(
+    std::default_random_engine *generator,
+    const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     std::vector<Proof>& pi,
     const Twistpoint& shortTermPublicKey,
     const char *firstUri,
@@ -279,6 +392,7 @@ Twistpoint get_generator_from_file(
 Twistpoint get_generator(
     std::default_random_engine *randomGenerator,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     std::vector<Proof>& pi,
     bool fresh)
 {
@@ -298,7 +412,7 @@ Twistpoint get_generator(
     {
         struct mg_connection *conn = mg_connect_websocket_client(
             serverIPs[whichServer].c_str(),
-            PRSONA_PORT,
+            serverPorts[whichServer],
             USE_SSL,
             NULL,
             0,
@@ -315,7 +429,7 @@ Twistpoint get_generator(
         }
 
         std::unique_lock<std::mutex> lck(sync.mtx);
-        filename = set_temp_filename(conn);
+        filename = set_temp_filename(*randomGenerator, conn);
         sync.val = 0;
 
         mg_websocket_client_write(
@@ -344,10 +458,10 @@ Twistpoint get_generator(
 PrsonaClientWebSocketHandler::PrsonaClientWebSocketHandler(
     PrsonaClient *prsonaClient, 
     const std::vector<std::string>& serverIPs,
-    const std::string& selfIP,
+    const std::vector<int>& serverPorts,
     std::default_random_engine *generator)
 : prsonaClient(prsonaClient), serverIPs(serverIPs),
-    selfIP(selfIP), generator(generator)
+    serverPorts(serverPorts), generator(generator)
 { /* */ }
 
 bool PrsonaClientWebSocketHandler::handleConnection(
@@ -370,7 +484,7 @@ void PrsonaClientWebSocketHandler::handleReadyState(
     switch (info->query_string[0])
     {
         case PRSONA_VERIFY_REPUTATION_PROOF:
-            set_temp_filename(conn);
+            set_temp_filename(*generator, conn);
             break;
 
         default:
@@ -462,6 +576,7 @@ void PrsonaClientWebSocketHandler::verify_reputation_proof(
         get_generator(
             generator,
             serverIPs,
+            serverPorts,
             generatorProof,
             true);
 
@@ -474,6 +589,7 @@ void PrsonaClientWebSocketHandler::verify_reputation_proof(
         get_server_committed_val<EGCiphertext>(
             generator,
             serverIPs,
+            serverPorts,
             encryptedScoreProof,
             shortTermPublicKey,
             USER_TALLY_URI,

+ 54 - 21
prsona/src/networkServer.cpp

@@ -9,13 +9,15 @@
 void obtain_update_locks(
     std::unique_lock<std::mutex> &lck,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     const std::string& selfIP,
+    int selfPort,
     struct synchronization_tool *sync)
 {
     size_t i = 0;
     while (i < serverIPs.size())
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
         {
             lck.lock();
             i++;
@@ -25,7 +27,7 @@ void obtain_update_locks(
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 serverIPs[i].c_str(),
-                PRSONA_PORT,
+                serverPorts[i],
                 USE_SSL,
                 NULL,
                 0,
@@ -63,13 +65,15 @@ void obtain_update_locks(
 void release_update_locks(
     std::unique_lock<std::mutex> &lck,
     const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
     const std::string& selfIP,
+    int selfPort,
     struct synchronization_tool *sync)
 {
     ssize_t i = serverIPs.size() - 1;
     while (i >= 0)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
         {
             lck.unlock();
             i--;
@@ -79,7 +83,7 @@ void release_update_locks(
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 serverIPs[i].c_str(),
-                PRSONA_PORT,
+                serverPorts[i],
                 USE_SSL,
                 NULL,
                 0,
@@ -273,7 +277,6 @@ bool read_epoch_update_string(
     userTallyMessageCommits.clear();
     userTallySeedCommits.clear();
 
-
     file >> sizeOfVectorI;
     for (size_t i = 0; i < sizeOfVectorI.val(); i++)
     {
@@ -437,6 +440,7 @@ bool read_epoch_update_string(
 
 void distribute_epoch_updates(
     const std::string& recipient,
+    int recipientPort,
     const std::string& data,
     const struct synchronization_tool* sync)
 {
@@ -446,7 +450,7 @@ void distribute_epoch_updates(
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 recipient.c_str(),
-                PRSONA_PORT,
+                recipientPort,
                 USE_SSL,
                 NULL,
                 0,
@@ -486,12 +490,16 @@ void distribute_epoch_updates(
 
 PrsonaServerWebSocketHandler::PrsonaServerWebSocketHandler(
     PrsonaServer *prsonaServer,
+    std::default_random_engine *rng,
     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)
+    const std::vector<std::string>& serverIPs,
+    const std::vector<int>& serverPorts,
+    const std::string& selfIP,
+    int selfPort)
+: prsonaServer(prsonaServer), rng(rng), updateMtx(updateMtx),
+    epochNum(epochNum), serverIPs(serverIPs), serverPorts(serverPorts),
+    selfIP(selfIP), selfPort(selfPort)
 { /* */ }
 
 bool PrsonaServerWebSocketHandler::handleConnection(
@@ -530,7 +538,7 @@ void PrsonaServerWebSocketHandler::handleReadyState(
         case PRSONA_EPOCH_UPDATE:
         case PRSONA_NEW_USER_UPDATE:
         case PRSONA_RECEIVE_PARTIAL_DECRYPTION:
-            set_temp_filename(conn);
+            set_temp_filename(*rng, conn);
             break;
 
         default:
@@ -560,10 +568,13 @@ bool PrsonaServerWebSocketHandler::handleData(
         return false;
     }
 
-    FILE *currFile = fopen(filename, "ab");
-    fwrite(data, sizeof(char), data_len, currFile);
-    fclose(currFile);
-
+    if (filename)
+    {
+        FILE *currFile = fopen(filename, "ab");
+        fwrite(data, sizeof(char), data_len, currFile);
+        fclose(currFile);    
+    }
+    
     return true;
 }
 
@@ -727,6 +738,7 @@ void PrsonaServerWebSocketHandler::get_num_clients(
     std::stringstream buffer;
     std::string data;
 
+    std::cout << "actual number of clients: " << prsonaServer->get_num_clients() << std::endl;
     BinarySizeT numClients(prsonaServer->get_num_clients());
     buffer << numClients;
     data = buffer.str();
@@ -1012,13 +1024,13 @@ void PrsonaServerWebSocketHandler::distribute_new_user_updates(
     size_t i = 0;
     while (i < serverIPs.size())
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
             continue;
 
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 serverIPs[i].c_str(),
-                PRSONA_PORT,
+                serverPorts[i],
                 USE_SSL,
                 NULL,
                 0,
@@ -1084,13 +1096,13 @@ void PrsonaServerWebSocketHandler::distribute_new_vote(
     size_t i = 0;
     while (i < serverIPs.size())
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
             continue;
 
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 serverIPs[i].c_str(),
-                PRSONA_PORT,
+                serverPorts[i],
                 USE_SSL,
                 NULL,
                 0,
@@ -1132,6 +1144,7 @@ void PrsonaServerWebSocketHandler::distribute_new_vote(
 void PrsonaServerWebSocketHandler::add_new_client(
     struct mg_connection *conn, const char *filename)
 {
+    std::cout << "adding new client" << std::endl;
     struct synchronization_tool updateSync;
 
     std::ifstream file(filename);
@@ -1142,19 +1155,27 @@ void PrsonaServerWebSocketHandler::add_new_client(
     Twistpoint shortTermPublicKey;
     file >> shortTermPublicKey;
 
+    std::cout << "getting locks" << std::endl;
+
     std::unique_lock<std::mutex> lck(*updateMtx, std::defer_lock);
     obtain_update_locks(
         lck,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         &updateSync);
 
+    std::cout << "actually adding to me" << std::endl;
+
     std::vector<Proof> proofOfValidAddition;
     prsonaServer->add_new_client(
         proofOfValidAddition,
         proofOfValidKey,
         shortTermPublicKey);
 
+    std::cout << "giving other servers updates" << std::endl;
+
     std::vector<CurveBipoint> previousVoteTallies;
     std::vector<Twistpoint> currentPseudonyms;
     std::vector<EGCiphertext> currentUserEncryptedTallies;
@@ -1172,12 +1193,18 @@ void PrsonaServerWebSocketHandler::add_new_client(
         currentUserEncryptedTallies,
         voteMatrix);
 
+    std::cout << "releasing locks" << std::endl;
+
     release_update_locks(
         lck,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         &updateSync);
 
+    std::cout << "confirming addition to user" << std::endl;
+
     std::stringstream buffer;
     std::string data;
 
@@ -1233,7 +1260,9 @@ void PrsonaServerWebSocketHandler::receive_vote(
         obtain_update_locks(
             lck,
             serverIPs,
+            serverPorts,
             selfIP,
+            selfPort,
             &distributeSync);
     }
 
@@ -1248,7 +1277,9 @@ void PrsonaServerWebSocketHandler::receive_vote(
         release_update_locks(
             lck,
             serverIPs,
+            serverPorts,
             selfIP,
+            selfPort,
             &distributeSync);
     }
 
@@ -1389,11 +1420,12 @@ void PrsonaServerWebSocketHandler::build_up_midway_pseudonyms(
     epochSync.val = 1;
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
             continue;
 
         distribute_epoch_updates(
             serverIPs[i],
+            serverPorts[i],
             data,
             &epochSync);
     }
@@ -1465,11 +1497,12 @@ void PrsonaServerWebSocketHandler::break_down_midway_pseudonyms(
     epochSync.val = 1;
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
             continue;
 
         distribute_epoch_updates(
             serverIPs[i],
+            serverPorts[i],
             data,
             &epochSync);
     }

+ 9 - 5
prsona/src/networking.cpp

@@ -1,19 +1,21 @@
+#include <random>
 #include <algorithm>
 #include <iostream>
 #include <cstring>
 
 #include "networking.hpp"
 
-std::string random_string(size_t length)
+std::string random_string(std::default_random_engine& generator, size_t length)
 {
-    auto randchar = []() -> char
+    auto randchar = [&]() -> char
     {
         const char charset[] =
         "0123456789_-"
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
         "abcdefghijklmnopqrstuvwxyz";
         const size_t max_index = (sizeof(charset) - 1);
-        return charset[ rand() % max_index ];
+        std::uniform_int_distribution<int> dist(0, max_index - 1);
+        return charset[ dist(generator) ];
     };
     std::string str(length,0);
     std::generate_n(str.begin(), length, randchar);
@@ -21,9 +23,10 @@ std::string random_string(size_t length)
 }
 
 char *set_temp_filename(
+    std::default_random_engine& generator,
     struct mg_connection *conn)
 {
-    std::string filename = random_string(TMP_FILE_SIZE);
+    std::string filename = random_string(generator, TMP_FILE_SIZE);
     
     char *c_filename = new char[TMP_FILE_SIZE+TMP_DIR_SIZE+1];
     strncpy(c_filename, TMP_DIR, TMP_DIR_SIZE);
@@ -31,7 +34,8 @@ char *set_temp_filename(
         c_filename[i + TMP_DIR_SIZE] = filename[i];
     c_filename[TMP_DIR_SIZE + TMP_FILE_SIZE] = 0;
 
-    mg_set_user_connection_data(conn, c_filename);
+    if (conn)
+        mg_set_user_connection_data(conn, c_filename);
 
     return c_filename;
 }

+ 142 - 69
prsona/src/orchestratorMain.cpp

@@ -1,4 +1,5 @@
 #include <iostream>
+#include <random>
 #include <fstream>
 #include <sstream>
 #include <string>
@@ -8,11 +9,13 @@
 #include <chrono>
 #include <thread>
 
+#include "print_helpers.hpp"
 #include "networking.hpp"
 
 using namespace std;
 
 chrono::seconds oneSecond(1); 
+chrono::seconds fiveSeconds(5); 
 
 int clients_websocket_data_handler(
     struct mg_connection *conn,
@@ -21,39 +24,45 @@ int clients_websocket_data_handler(
     size_t data_len,
     void *user_data)
 {
-    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE)
+    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE || (bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
         return false;
 
     if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_BINARY)
     {
-        struct synchronization_tool *synch = (struct synchronization_tool *) user_data;
+        struct synchronization_tool *sync = (struct synchronization_tool *) user_data;
 
-        unique_lock<mutex> lck(synch->mtx);
-        synch->val = atoi(data);
+        unique_lock<mutex> lck(sync->mtx);
+        stringstream buffer;
+        buffer << data;
+        BinarySizeT numClients;
+        buffer >> numClients;
+        std::cout << "raw data from websocket on number clients: " << numClients.val() << std::endl;
+        sync->val = numClients.val();
 
         return false;
     }
 
-    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
-        return false;
-
     std::cerr << "Unknown response when trying to get update lock." << std::endl;
     return false;    
 }
 
-int start_remote_actor(string target, bool server, string output)
+int start_remote_actor(string target, bool server, string id, string output)
 {
     stringstream buffer;
     string command;
 
-    buffer << "ssh tmgurtle@" << target << " \"screen \'~/prsona/prsona/bin/"
-        << (server ? "startServer.sh " : "startClient.sh ") << output << "\'\"" ;
+    // buffer << "ssh tmgurtle@" << target << " \"screen \'~/prsona/prsona/bin/"
+    //     << (server ? "startServer.sh " : "startClient.sh ") << id << " t " << output << "\'\"" ;
+
+    buffer << "bin/" << (server ? "server " : "client ") << id << " T " << output << " &";
     command = buffer.str();
 
+
+
     return system(command.c_str());
 }
 
-void wait_for_servers_ready(string dealer)
+void wait_for_servers_ready(string dealer, int dealerPort)
 {
     bool flag = false;
     while (!flag)
@@ -62,42 +71,44 @@ void wait_for_servers_ready(string dealer)
 
         stringstream sysString;
         string data;
-        char buffer[255];
 
         struct mg_connection *conn =
             mg_connect_client(
                 dealer.c_str(), 
-                PRSONA_PORT,
+                dealerPort,
                 USE_SSL, 
                 NULL,
                 0);
 
         if (!conn)
+        {
+            cerr << "couldn't make connection while waiting for servers ready" << endl;
             continue;
+        }
 
         sysString << "GET " << EPOCH_READY_URI << " HTTP/1.1\r\n";
-        sysString << "Host: " << dealer << "\r\n\r\n";
+        sysString << "Host: " << dealer << ":" << dealerPort << "\r\n\r\n";
         data = sysString.str();
 
         mg_write(conn, data.c_str(), data.length());
-        size_t readLen = mg_read(conn, (uint8_t*) buffer, 254);
-        buffer[readLen] = 0;
+        mg_get_response(conn, NULL, 0, 250);
+        const struct mg_response_info *info = mg_get_response_info(conn);
 
-        if (strstr(buffer, "200"))
+        if (info->status_code == 200)
             flag = true;
 
         mg_close_connection(conn);
     }
 }
 
-void wait_for_clients_ready(string dealer, size_t numClients)
+void wait_for_clients_ready(string dealer, int dealerPort, size_t numClients)
 {
     struct synchronization_tool numClientsSync;
 
     bool flag = false;
     while (!flag)
     {
-        this_thread::sleep_for(oneSecond);
+        this_thread::sleep_for(fiveSeconds);
 
         stringstream sysString;
         string data;
@@ -105,7 +116,7 @@ void wait_for_clients_ready(string dealer, size_t numClients)
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 dealer.c_str(),
-                PRSONA_PORT,
+                dealerPort,
                 USE_SSL,
                 NULL,
                 0,
@@ -116,11 +127,14 @@ void wait_for_clients_ready(string dealer, size_t numClients)
                 &numClientsSync);
 
         if (!conn)
+        {
+            cerr << "couldn't make connection while waiting for clients ready" << endl;
             continue;
+        }
 
         unique_lock<mutex> lck(numClientsSync.mtx);
         numClientsSync.val = 0;
-        numClientsSync.val2 = 1;
+        numClientsSync.val2 = 0;
 
         mg_websocket_client_write(
             conn,
@@ -128,7 +142,7 @@ void wait_for_clients_ready(string dealer, size_t numClients)
             "",
             0);
 
-        while (numClientsSync.val2)
+        while (!numClientsSync.val2)
             numClientsSync.cv.wait(lck);
 
         mg_close_connection(conn);
@@ -138,7 +152,7 @@ void wait_for_clients_ready(string dealer, size_t numClients)
     }
 }
 
-void trigger_epoch(string dealer)
+void trigger_epoch(string dealer, int dealerPort)
 {
     this_thread::sleep_for(oneSecond);
 
@@ -151,7 +165,7 @@ void trigger_epoch(string dealer)
         struct mg_connection *conn =
             mg_connect_client(
                 dealer.c_str(), 
-                PRSONA_PORT,
+                dealerPort,
                 USE_SSL, 
                 NULL,
                 0);
@@ -169,10 +183,10 @@ void trigger_epoch(string dealer)
         flag = true;
     }
 
-    wait_for_servers_ready(dealer);
+    wait_for_servers_ready(dealer, dealerPort);
 }
 
-void trigger_vote(string target)
+void trigger_vote(string target, int port)
 {
     bool flag = false;
     while (!flag)
@@ -183,7 +197,7 @@ void trigger_vote(string target)
         struct mg_connection *conn =
             mg_connect_client(
                 target.c_str(), 
-                PRSONA_PORT,
+                port,
                 USE_SSL, 
                 NULL,
                 0);
@@ -202,7 +216,7 @@ void trigger_vote(string target)
     }
 }
 
-void trigger_reputation_proof(string target, string verifier)
+void trigger_reputation_proof(string target, int targetPort, string verifier, int verifierPort)
 {
     bool flag = false;
     while (!flag)
@@ -213,7 +227,7 @@ void trigger_reputation_proof(string target, string verifier)
         struct mg_connection *conn =
             mg_connect_client(
                 target.c_str(), 
-                PRSONA_PORT,
+                targetPort,
                 USE_SSL, 
                 NULL,
                 0);
@@ -221,7 +235,7 @@ void trigger_reputation_proof(string target, string verifier)
         if (!conn)
             continue;
 
-        sysString << "GET " << TRIGGER_REP_URI << verifier << " HTTP/1.1\r\n";
+        sysString << "GET " << TRIGGER_REP_URI << verifier << ":" << verifierPort << " HTTP/1.1\r\n";
         sysString << "Host: " << target << "\r\n\r\n";
         data = sysString.str();
 
@@ -232,12 +246,12 @@ void trigger_reputation_proof(string target, string verifier)
     }
 }
 
-void execute_experiment(string dealer)
+void execute_experiment(string dealer, int dealerPort)
 {
     size_t line = 1;
 
     char buffer[128];
-    ifstream commands("commands.cfg");
+    ifstream commands("cfg/commands.cfg");
 
     while (!commands.eof())
     {
@@ -253,18 +267,28 @@ void execute_experiment(string dealer)
         switch(buffer[0])
         {
             case 'V':
-                trigger_vote(string(buffer + 2));
+                char *voter, *voterPort;
+                voter = strtok(buffer + 1, " :");
+                voterPort = strtok(NULL, " :");
+
+                trigger_vote(string(voter), atoi(voterPort));
                 break;
 
             case 'R':
-                char *target, *verifier;
-                target = strtok(buffer, " ");
-                verifier = strtok(NULL, " ");
-                trigger_reputation_proof(string(target), string(verifier));
+                char *target, *targetPortStr, *verifier, *verifierPortStr;
+                target = strtok(buffer, " :");
+                targetPortStr = strtok(NULL, " :");
+                verifier = strtok(NULL, " :");
+                verifierPortStr = strtok(NULL, " :");
+                trigger_reputation_proof(
+                    string(target),
+                    atoi(targetPortStr),
+                    string(verifier),
+                    atoi(verifierPortStr));
                 break;
 
             case 'E':
-                trigger_epoch(dealer);
+                trigger_epoch(dealer, dealerPort);
                 break;
 
             default:
@@ -277,7 +301,12 @@ void execute_experiment(string dealer)
 
 int main(int argc, char* argv[])
 {
-    string experimentOutput = random_string(8);
+    string seedStr = "seed";
+
+    seed_seq seed(seedStr.begin(), seedStr.end());
+    default_random_engine rng(seed);
+
+    string experimentOutput = random_string(rng, 8);
 
 #if USE_SSL
     mg_init_library(0);
@@ -286,79 +315,123 @@ int main(int argc, char* argv[])
 #endif
 
     vector<string> serverIPs, clientIPs;
+    vector<int> serverPorts, clientPorts;
     string dealerIP;
+    int dealerPort = 0;
 
-    char buffer[40];
-    ifstream serverConfig("serverIPs.cfg");
+    char buffer[46], *helper;
+    ifstream serverConfig("cfg/serverIPs.cfg");
     while (!serverConfig.eof())
     {
-        serverConfig.getline(buffer, 40);
+        serverConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            serverIPs.push_back(string(buffer));
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                serverIPs.push_back(string(helper));
+                helper = strtok(NULL, ":");
+                serverPorts.push_back(atoi(helper));
+            }
+            else
+            {
+                serverIPs.push_back(string(helper));
+                serverPorts.push_back(atoi(PRSONA_PORT_STR));
+            }
+        }
     }
 
-    ifstream clientConfig("clientIPs.cfg");
+    ifstream clientConfig("cfg/clientIPs.cfg");
     while (!clientConfig.eof())
     {
-        clientConfig.getline(buffer, 40);
+        clientConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            clientIPs.push_back(string(buffer));
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                clientIPs.push_back(string(helper));
+                helper = strtok(NULL, ":");
+                clientPorts.push_back(atoi(helper));
+            }
+            else
+            {
+                clientIPs.push_back(string(helper));
+                clientPorts.push_back(atoi(PRSONA_PORT_STR));
+            }
+        }
     }
 
-    ifstream dealerConfig("dealerIP.cfg");
+    ifstream dealerConfig("cfg/dealerIP.cfg");
     while (!dealerConfig.eof())
     {
-        dealerConfig.getline(buffer, 40);
+        dealerConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            dealerIP = buffer;
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                dealerIP = helper;
+                helper = strtok(NULL, ":");
+                dealerPort = atoi(helper);
+            }
+            else
+            {
+                dealerIP = helper;
+                dealerPort = atoi(PRSONA_PORT_STR);
+            }
+        }
     }
 
     size_t numServers = serverIPs.size();
     size_t numClients = clientIPs.size();
 
-    cout << "This experiment is running with output code: " << experimentOutput << endl;
-    cout << "Starting BGN dealer server." << endl;
+    cout << "[ORC] This experiment is running with output code: " << experimentOutput << endl;
+    cout << "[ORC] Starting BGN dealer server." << endl;
 
     vector<thread> serverStartup, clientStartup;
-    serverStartup.push_back(thread(start_remote_actor, dealerIP, true, experimentOutput));
+    serverStartup.push_back(thread(start_remote_actor, dealerIP, true, "d", experimentOutput));
 
     this_thread::sleep_for(oneSecond);
 
-    cout << "Starting other servers." << endl;
+    cout << "[ORC] Starting other servers." << endl;
 
     for (size_t i = 0; i < numServers; i++)
     {
-        if (serverIPs[i] == dealerIP)
+        if (serverIPs[i] == dealerIP && serverPorts[i] == dealerPort)
             continue;
 
-        serverStartup.push_back(thread(start_remote_actor, serverIPs[i], true, experimentOutput));
+        serverStartup.push_back(thread(start_remote_actor, serverIPs[i], true, "s" + to_string(i), experimentOutput));
     }
 
-    cout << "Waiting for confirmation that servers are ready to continue." << endl;
+    cout << "[ORC] Waiting for confirmation that servers are ready to continue." << endl;
 
     for (size_t i = 0; i < numServers; i++)
         serverStartup[i].join();
 
-    wait_for_servers_ready(dealerIP);
+    wait_for_servers_ready(dealerIP, dealerPort);
 
-    cout << "Starting clients." << endl;
+    cout << "[ORC] Starting clients." << endl;
 
     for (size_t i = 0; i < numClients; i++)
-        clientStartup.push_back(thread(start_remote_actor, clientIPs[i], false, experimentOutput));
+        clientStartup.push_back(thread(start_remote_actor, clientIPs[i], false, "c" + to_string(i), experimentOutput));
 
-    cout << "Waiting for confirmation that servers have all clients logged." << endl;    
+    cout << "[ORC] Waiting for confirmation that servers have all clients logged." << endl;    
 
     for (size_t i = 0; i < numClients; i++)
         clientStartup[i].join();
 
-    wait_for_clients_ready(dealerIP, numClients);
+    wait_for_clients_ready(dealerIP, dealerPort, numClients);
 
-    cout << "Beginning experiment." << endl;
+    cout << "[ORC] Beginning experiment." << endl;
 
-    execute_experiment(dealerIP);
+    execute_experiment(dealerIP, dealerPort);
 
-    cout << "Finishing experiment." << endl;
-    cout << "Sending shutdown commands to clients." << endl;
+    cout << "[ORC] Finishing experiment." << endl;
+    cout << "[ORC] Sending shutdown commands to clients." << endl;
 
     for (size_t i = 0; i < clientIPs.size(); i++)
     {
@@ -368,7 +441,7 @@ int main(int argc, char* argv[])
         struct mg_connection *conn =
             mg_connect_client(
                 clientIPs[i].c_str(), 
-                PRSONA_PORT,
+                clientPorts[i],
                 USE_SSL, 
                 NULL,
                 0);
@@ -381,7 +454,7 @@ int main(int argc, char* argv[])
         mg_close_connection(conn);
     }
 
-    cout << "Sending shutdown commands to servers." << endl;
+    cout << "[ORC] Sending shutdown commands to servers." << endl;
 
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
@@ -391,13 +464,13 @@ int main(int argc, char* argv[])
         struct mg_connection *conn =
             mg_connect_client(
                 serverIPs[i].c_str(), 
-                PRSONA_PORT,
+                serverPorts[i],
                 USE_SSL, 
                 NULL,
                 0);
 
         sysString << "GET " << EXIT_URI << " HTTP/1.1\r\n";
-        sysString << "Host: " << serverIPs[i] << "\r\n\r\n";
+        sysString << "Host: " << serverIPs[i] << ":" << serverPorts[i] << "\r\n\r\n";
         data = sysString.str();
 
         mg_write(conn, data.c_str(), data.length());

+ 24 - 0
prsona/src/proof.cpp

@@ -50,6 +50,30 @@ void Proof::clear()
     responseParts.clear();
 }
 
+bool Proof::operator==(const Proof& b)
+{
+    bool retval = this->hbc == b.hbc;
+    
+    retval = retval && this->curvepointUniversals.size() == b.curvepointUniversals.size();
+    retval = retval && this->curveBipointUniversals.size() == b.curveBipointUniversals.size();
+    retval = retval && this->challengeParts.size() == b.challengeParts.size();
+    retval = retval && this->responseParts.size() == b.responseParts.size();
+
+    for (size_t i = 0; retval && i < this->curvepointUniversals.size(); i++)
+        retval = retval && this->curvepointUniversals[i] == b.curvepointUniversals[i];
+
+    for (size_t i = 0; retval && i < this->curveBipointUniversals.size(); i++)
+        retval = retval && this->curveBipointUniversals[i] == b.curveBipointUniversals[i];
+
+    for (size_t i = 0; retval && i < this->challengeParts.size(); i++)
+        retval = retval && this->challengeParts[i] == b.challengeParts[i];
+
+    for (size_t i = 0; retval && i < this->responseParts.size(); i++)
+        retval = retval && this->responseParts[i] == b.responseParts[i];
+
+    return retval;
+}
+
 std::ostream& operator<<(std::ostream& os, const Proof& output)
 {
     BinaryBool hbc(!output.hbc.empty());

+ 240 - 162
prsona/src/serverMain.cpp

@@ -9,13 +9,9 @@
 
 #include "networkServer.hpp"
 
-#define BGN_TMP_FILE (TMP_DIR "bgn")
-#define GEN_TMP_FILE (TMP_DIR "generator")
-#define EPOCH_GEN_TMP_FILE (TMP_DIR "epoch")
-
 using namespace std;
 
-struct synchronization_tool exitSync, bgnSync, generatorSync, readySync, updateSync, epochSync, tallySync;
+struct synchronization_tool exitSync, readySync;
 mutex updateMtx;
 
 atomic<size_t> epochNum(0);
@@ -28,53 +24,26 @@ void initialize_prsona_classes()
     PrsonaBase::set_client_malicious();
 }
 
-PrsonaServer *create_server_from_bgn_file(size_t numServers)
+PrsonaServer *create_server_from_bgn_file(
+    size_t numServers,
+    struct synchronization_tool *sync,
+    const char *filename)
 {
-    unique_lock<mutex> lck(bgnSync.mtx);
-    ifstream bgnFile(BGN_TMP_FILE);
+    unique_lock<mutex> lck(sync->mtx);
+    ifstream bgnFile(filename);
     BGN privateKey;
     bgnFile >> privateKey;
 
     return new PrsonaServer(numServers, privateKey);
 }
 
-static int bgn_websocket_data_handler(
-    struct mg_connection *conn,
-    int bits,
-    char *data,
-    size_t data_len,
-    void *user_data)
-{
-    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE)
-        return false;
-
-    if ((bits & 0xf) != MG_WEBSOCKET_OPCODE_BINARY && (bits & 0xf) != MG_WEBSOCKET_OPCODE_CONTINUATION)
-    {
-        std::cerr << "Unknown opcode: failing." << std::endl;
-        return false;
-    }
-
-    unique_lock<mutex> lck(bgnSync.mtx);
-    FILE *currFile = fopen(BGN_TMP_FILE, "ab");
-    fwrite(data, sizeof(char), data_len, currFile);
-    fclose(currFile);
-
-    return true;
-}
-
-static void bgn_websocket_close_handler(
-    const struct mg_connection *conn,
-    void *user_data)
-{
-    unique_lock<mutex> lck(bgnSync.mtx);
-    bgnSync.val = 1;
-    bgnSync.cv.notify_all();
-}
-
-Twistpoint update_generator_from_gen_file(Proof& pi)
+Twistpoint update_generator_from_gen_file(
+    Proof& pi,
+    struct synchronization_tool *sync,
+    const char *filename)
 {
-    unique_lock<mutex> lck(generatorSync.mtx);
-    ifstream genFile(GEN_TMP_FILE);
+    unique_lock<mutex> lck(sync->mtx);
+    ifstream genFile(filename);
     Twistpoint retval;
 
     genFile >> pi;
@@ -83,10 +52,13 @@ Twistpoint update_generator_from_gen_file(Proof& pi)
     return retval;
 }
 
-Twistpoint update_data_from_epoch_gen_file(vector<Proof>& pi)
+Twistpoint update_data_from_epoch_gen_file(
+    vector<Proof>& pi,
+    struct synchronization_tool *sync,
+    const char *filename)
 {
-    unique_lock<mutex> lck(epochSync.mtx);
-    ifstream epochFile(EPOCH_GEN_TMP_FILE);
+    unique_lock<mutex> lck(sync->mtx);
+    ifstream epochFile(filename);
     
     Twistpoint retval;
     BinarySizeT sizeOfVector;
@@ -105,39 +77,6 @@ Twistpoint update_data_from_epoch_gen_file(vector<Proof>& pi)
     return retval;
 }
 
-static int generator_websocket_data_handler(
-    struct mg_connection *conn,
-    int bits,
-    char *data,
-    size_t data_len,
-    void *user_data)
-{
-    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE || (bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
-        return false;
-
-    if ((bits & 0xf) != MG_WEBSOCKET_OPCODE_BINARY && (bits & 0xf) != MG_WEBSOCKET_OPCODE_CONTINUATION)
-    {
-        std::cerr << "Unknown opcode: failing." << std::endl;
-        return false;
-    }
-
-    unique_lock<mutex> lck(generatorSync.mtx);
-    FILE *currFile = fopen(GEN_TMP_FILE, "ab");
-    fwrite(data, sizeof(char), data_len, currFile);
-    fclose(currFile);
-
-    return true;
-}
-
-static void generator_websocket_close_handler(
-    const struct mg_connection *conn,
-    void *user_data)
-{
-    unique_lock<mutex> lck(generatorSync.mtx);
-    generatorSync.val = 1;
-    generatorSync.cv.notify_all();
-}
-
 static int epoch_websocket_data_handler(
     struct mg_connection *conn,
     int bits,
@@ -145,12 +84,14 @@ static int epoch_websocket_data_handler(
     size_t data_len,
     void *user_data)
 {
-    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE)
+    if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE  || (bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
         return false;
     if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
     {
-        unique_lock<mutex> lck(epochSync.mtx);
-        epochSync.val++;
+        struct synchronization_tool *sync = (struct synchronization_tool *) user_data;
+        
+        unique_lock<mutex> lck(sync->mtx);
+        sync->val++;
 
         return false;
     }
@@ -161,8 +102,11 @@ static int epoch_websocket_data_handler(
         return false;
     }
 
-    unique_lock<mutex> lck(epochSync.mtx);
-    FILE *currFile = fopen(EPOCH_GEN_TMP_FILE, "ab");
+    struct synchronization_tool *sync = (struct synchronization_tool *) user_data;
+    char *filename = (char *) mg_get_user_connection_data(conn);
+
+    unique_lock<mutex> lck(sync->mtx);
+    FILE *currFile = fopen(filename, "ab");
     fwrite(data, sizeof(char), data_len, currFile);
     fclose(currFile);
 
@@ -173,9 +117,11 @@ static void epoch_websocket_close_handler(
     const struct mg_connection *conn,
     void *user_data)
 {
-    unique_lock<mutex> lck(epochSync.mtx);
-    epochSync.val2 = 0;
-    epochSync.cv.notify_all();
+    struct synchronization_tool *sync = (struct synchronization_tool *) user_data;
+
+    unique_lock<mutex> lck(sync->mtx);
+    sync->val2 = 0;
+    sync->cv.notify_all();
 }
 
 static int tally_websocket_data_handler(
@@ -190,10 +136,12 @@ static int tally_websocket_data_handler(
 
     if ((bits & 0xf) == MG_WEBSOCKET_OPCODE_DATACOMPLETE)
     {
-        unique_lock<mutex> lck(tallySync.mtx);
-        tallySync.val++;
+        struct synchronization_tool *sync = (struct synchronization_tool *) user_data;
+
+        unique_lock<mutex> lck(sync->mtx);
+        sync->val++;
 
-        tallySync.cv.notify_all();
+        sync->cv.notify_all();
 
         return false;
     }
@@ -208,10 +156,13 @@ static int tally_websocket_data_handler(
 }
 
 Twistpoint get_generator(
+    default_random_engine& rng,
     vector<Proof>& pi,
     PrsonaServer *prsonaServer,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     const string& selfIP,
+    int selfPort,
     bool fresh)
 {
     Twistpoint retval = PrsonaServer::EL_GAMAL_GENERATOR;
@@ -226,24 +177,27 @@ Twistpoint get_generator(
 
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
             continue;
 
+        struct synchronization_tool generatorSync;
+        char *genFilename;
+
         bool flag = false;
         while (!flag)
         {
             struct mg_connection *conn =
                 mg_connect_websocket_client(
                     serverIPs[i].c_str(),
-                    PRSONA_PORT,
+                    serverPorts[i],
                     USE_SSL,
                     NULL,
                     0,
                     which,
                     "null",
-                    generator_websocket_data_handler,
-                    generator_websocket_close_handler,
-                    NULL);
+                    file_websocket_data_handler,
+                    file_websocket_close_handler,
+                    &generatorSync);
 
             if (!conn)
             {
@@ -263,7 +217,7 @@ Twistpoint get_generator(
                 data.length());
 
             unique_lock<mutex> lck(generatorSync.mtx);
-            remove(GEN_TMP_FILE);
+            genFilename = set_temp_filename(rng, conn);
             generatorSync.val = 0;
             mg_websocket_client_write(
                 conn,
@@ -280,8 +234,11 @@ Twistpoint get_generator(
         }
 
         Proof currProof;
-        retval = update_generator_from_gen_file(currProof);
+        retval = update_generator_from_gen_file(currProof, &generatorSync, genFilename);
         pi.push_back(currProof);
+
+        remove(genFilename);
+        delete genFilename;
     }
 
     return retval;
@@ -289,10 +246,12 @@ Twistpoint get_generator(
 
 void handout_generator(
     const vector<Proof>& pi,
-    const Twistpoint generator,
+    const Twistpoint& generator,
     PrsonaServer *prsonaServer,
-    const vector<string> serverIPs,
-    string selfIP,
+    const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
+    const string& selfIP,
+    int selfPort,
     bool fresh)
 {
     if (fresh)
@@ -315,7 +274,7 @@ void handout_generator(
 
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
             continue;
 
         bool flag = false;
@@ -324,7 +283,7 @@ void handout_generator(
             struct mg_connection *conn =
                 mg_connect_websocket_client(
                     serverIPs[i].c_str(),
-                    PRSONA_PORT,
+                    serverPorts[i],
                     USE_SSL,
                     NULL,
                     0,
@@ -360,13 +319,16 @@ void handout_generator(
 }
 
 Twistpoint initiate_epoch_updates(
+    default_random_engine& rng,
     const string& recipient,
+    int recipientPort,
     const string& data,
     vector<vector<Proof>>& generatorProofHolder,
     bool isBreakdown)
 {
     Twistpoint retval;
     struct synchronization_tool epochSync;
+    char * epochFilename;
     const char* which = (isBreakdown ? EPOCH_BREAK_DOWN_URI : EPOCH_BUILD_UP_URI);
 
     bool flag = false;
@@ -375,7 +337,7 @@ Twistpoint initiate_epoch_updates(
         struct mg_connection *conn =
             mg_connect_websocket_client(
                 recipient.c_str(),
-                PRSONA_PORT,
+                recipientPort,
                 USE_SSL,
                 NULL,
                 0,
@@ -383,7 +345,7 @@ Twistpoint initiate_epoch_updates(
                 "null",
                 epoch_websocket_data_handler,
                 epoch_websocket_close_handler,
-                NULL);
+                &epochSync);
 
         if (!conn)
         {
@@ -392,7 +354,7 @@ Twistpoint initiate_epoch_updates(
         }
         
         unique_lock<mutex> lck(epochSync.mtx);
-        remove(EPOCH_GEN_TMP_FILE);
+        epochFilename = set_temp_filename(rng, conn);
         epochSync.val = 0;
         epochSync.val2 = 1;
 
@@ -423,17 +385,23 @@ Twistpoint initiate_epoch_updates(
     vector<Proof> generatorProof;
     generatorProofHolder.clear();
 
-    retval = update_data_from_epoch_gen_file(generatorProof);
+    retval = update_data_from_epoch_gen_file(generatorProof, &epochSync, epochFilename);
 
     generatorProofHolder.push_back(generatorProof);
 
+    remove(epochFilename);
+    delete epochFilename;
+
     return retval;
 }
 
 vector<Proof> epoch_build_up(
     PrsonaServer *prsonaServer,
+    default_random_engine& rng,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     const string& selfIP,
+    int selfPort,
     Twistpoint& nextGenerator)
 {
     std::vector<std::vector<std::vector<Proof>>> pi;
@@ -448,7 +416,7 @@ vector<Proof> epoch_build_up(
 
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
         {
             pi.clear();
             permutationCommits.clear();
@@ -497,6 +465,7 @@ vector<Proof> epoch_build_up(
 
                 distribute_epoch_updates(
                     serverIPs[j],
+                    serverPorts[j],
                     data,
                     &epochSync);
             }
@@ -512,7 +481,9 @@ vector<Proof> epoch_build_up(
                 generatorProofHolder[0],
                 nextGenerator);
             nextGenerator = initiate_epoch_updates(
+                rng,
                 serverIPs[i],
+                serverPorts[i],
                 data,
                 generatorProofHolder,
                 false);
@@ -524,8 +495,11 @@ vector<Proof> epoch_build_up(
 
 void epoch_break_down(
     PrsonaServer *prsonaServer,
+    default_random_engine& rng,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     const string& selfIP,
+    int selfPort,
     const vector<Proof>& generatorProof,
     const Twistpoint& nextGenerator)
 {
@@ -553,7 +527,7 @@ void epoch_break_down(
         userTallyMessageCommits.clear();
         userTallySeedCommits.clear();
 
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
         {
             prsonaServer->break_down_midway_pseudonyms(
                 generatorProof,
@@ -592,6 +566,7 @@ void epoch_break_down(
 
                 distribute_epoch_updates(
                     serverIPs[j],
+                    serverPorts[j],
                     data,
                     &epochSync);
             }
@@ -606,7 +581,9 @@ void epoch_break_down(
                 generatorProof,
                 nextGenerator);
             initiate_epoch_updates(
+                rng,
                 serverIPs[i],
+                serverPorts[i],
                 data,
                 unused,
                 true);
@@ -617,15 +594,18 @@ void epoch_break_down(
 void tally_scores(
     PrsonaServer *prsonaServer,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     const string& selfIP,
+    int selfPort,
     const Twistpoint& nextGenerator,
     std::vector<EGCiphertext>& userTallyScores,
     std::vector<CurveBipoint>& serverTallyScores)
 {
+    struct synchronization_tool tallySync;
     tallySync.val = 0;
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
         {
             unique_lock<mutex> lck(tallySync.mtx);
             tallySync.val++;
@@ -639,7 +619,7 @@ void tally_scores(
                 struct mg_connection *conn =
                     mg_connect_websocket_client(
                         serverIPs[i].c_str(),
-                        PRSONA_PORT,
+                        serverPorts[i],
                         USE_SSL,
                         NULL,
                         0,
@@ -647,11 +627,11 @@ void tally_scores(
                         "null",
                         tally_websocket_data_handler,
                         empty_websocket_close_handler,
-                        NULL);
+                        &tallySync);
 
                 if (!conn)
                 {
-                    std::cerr << "Trouble initiating epoch update with server at " << serverIPs[i] << std::endl;
+                    std::cerr << "Trouble initiating epoch update with server at " << serverIPs[i] << ":" << serverPorts[i] << std::endl;
                     continue;
                 }
 
@@ -713,7 +693,9 @@ void tally_scores(
 void distribute_tallied_scores(
     PrsonaServer *prsonaServer,
     const vector<string>& serverIPs,
+    const vector<int>& serverPorts,
     const string& selfIP,
+    int selfPort,
     const Twistpoint& nextGenerator,
     const std::vector<EGCiphertext>& userTallyScores,
     const std::vector<CurveBipoint>& serverTallyScores)
@@ -730,10 +712,11 @@ void distribute_tallied_scores(
 
     data = buffer.str();
 
+    struct synchronization_tool tallySync;
     tallySync.val = 0;
     for (size_t i = 0; i < serverIPs.size(); i++)
     {
-        if (serverIPs[i] == selfIP)
+        if (serverIPs[i] == selfIP && serverPorts[i] == selfPort)
         {
             prsonaServer->receive_tallied_scores(userTallyScores, serverTallyScores);
             unique_lock<mutex> lck(tallySync.mtx);
@@ -748,7 +731,7 @@ void distribute_tallied_scores(
                 struct mg_connection *conn =
                     mg_connect_websocket_client(
                         serverIPs[i].c_str(),
-                        PRSONA_PORT,
+                        serverPorts[i],
                         USE_SSL,
                         NULL,
                         0,
@@ -756,11 +739,11 @@ void distribute_tallied_scores(
                         "null",
                         tally_websocket_data_handler,
                         empty_websocket_close_handler,
-                        NULL);
+                        &tallySync);
 
                 if (!conn)
                 {
-                    std::cerr << "Trouble initiating epoch update with server at " << serverIPs[i] << std::endl;
+                    std::cerr << "Trouble initiating epoch update with server at " << serverIPs[i] << ":" << serverPorts[i] << std::endl;
                     continue;
                 }
 
@@ -790,23 +773,33 @@ void distribute_tallied_scores(
 
 void epoch(
     PrsonaServer *prsonaServer,
+    default_random_engine& rng,
     const vector<string>& serverIPs,
-    const string& selfIP)
+    const vector<int>& serverPorts,
+    const string& selfIP,
+    int selfPort)
 {
     Twistpoint nextGenerator = PrsonaServer::EL_GAMAL_GENERATOR;
+
+    struct synchronization_tool updateSync;
     
     unique_lock<mutex> lck(updateMtx, defer_lock);
     obtain_update_locks(
         lck,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         &updateSync);
 
     vector<Proof> generatorProof =
         epoch_build_up(
             prsonaServer,
+            rng,
             serverIPs,
+            serverPorts,
             selfIP,
+            selfPort,
             nextGenerator);
 
     std::vector<EGCiphertext> currentUserEncryptedTallies;
@@ -815,7 +808,9 @@ void epoch(
     tally_scores(
         prsonaServer,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         nextGenerator,
         currentUserEncryptedTallies,
         currentServerEncryptedTallies);
@@ -823,15 +818,20 @@ void epoch(
     distribute_tallied_scores(
         prsonaServer,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         nextGenerator,
         currentUserEncryptedTallies,
         currentServerEncryptedTallies);
 
     epoch_break_down(
         prsonaServer,
+        rng,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         generatorProof,
         nextGenerator);
 
@@ -840,7 +840,9 @@ void epoch(
     release_update_locks(
         lck,
         serverIPs,
+        serverPorts,
         selfIP,
+        selfPort,
         &updateSync);
 }
 
@@ -908,61 +910,131 @@ int main(int argc, char *argv[])
 #else
     mg_init_library(MG_FEATURES_SSL);
 #endif
-    
-    const char *options[] = {"listening_ports", PRSONA_PORT_STR, 0};
+
+    string id = "";
+    if (argc > 1)
+        id = argv[1];
+
+    string seedStr;
+    if (id.empty())
+        seedStr = "default-server";
+    else
+    {
+        seedStr = id;
+        seedStr += "-server";
+    }
 
     vector<string> serverIPs;
-    string selfIP, dealerIP;
+    vector<int> serverPorts;
+    string selfIP, selfPortStr, dealerIP;
+    int selfPort = 0, dealerPort = 0;
 
-    char buffer[40];
-    ifstream serverConfig("serverIPs.cfg");
+    char buffer[46], *helper;
+    ifstream serverConfig("cfg/serverIPs.cfg");
     while (!serverConfig.eof())
     {
-        serverConfig.getline(buffer, 40);
+        serverConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            serverIPs.push_back(string(buffer));
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                serverIPs.push_back(string(helper));
+                helper = strtok(NULL, ":");
+                serverPorts.push_back(atoi(helper));
+            }
+            else
+            {
+                serverIPs.push_back(string(helper));
+                serverPorts.push_back(atoi(PRSONA_PORT_STR));
+            }
+        }
     }
 
-    ifstream selfConfig("selfIP.cfg");
+    string selfConfigFilename = "cfg/selfIP";
+    if (!id.empty())
+    {
+        selfConfigFilename += "-";
+        selfConfigFilename += id;
+    }
+    selfConfigFilename += ".cfg";
+
+    ifstream selfConfig(selfConfigFilename);
     while (!selfConfig.eof())
     {
-        selfConfig.getline(buffer, 40);
+        selfConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            selfIP = buffer;
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                selfIP = helper;
+                helper = strtok(NULL, ":");
+                selfPortStr = helper;
+                selfPort = atoi(helper);
+            }
+            else
+            {
+                selfIP = helper;
+                selfPortStr = PRSONA_PORT_STR;
+                selfPort = atoi(PRSONA_PORT_STR);
+            }
+        }
     }
 
-    ifstream dealerConfig("dealerIP.cfg");
+    ifstream dealerConfig("cfg/dealerIP.cfg");
     while (!dealerConfig.eof())
     {
-        dealerConfig.getline(buffer, 40);
+        dealerConfig.getline(buffer, 46);
         if (strlen(buffer) > 0)
-            dealerIP = buffer;
+        {
+            helper = buffer;
+            if (strchr(helper, ':'))
+            {
+                helper = strtok(helper, ":");
+                dealerIP = helper;
+                helper = strtok(NULL, ":");
+                dealerPort = atoi(helper);
+            }
+            else
+            {
+                dealerIP = helper;
+                dealerPort = atoi(PRSONA_PORT_STR);
+            }
+        }
     }
 
     // Defaults
     size_t numServers = serverIPs.size();
-    bool bgnDealer = selfIP == dealerIP;
+    bool bgnDealer = selfIP == dealerIP && selfPort == dealerPort;
     bool maliciousServers = true;
 
-    if (argc > 1)
+    const char *options[] = {"listening_ports", selfPortStr.c_str(), 0};
+
+    if (argc > 2)
     {
-        bool setting = argv[1][0] == 't' || argv[1][0] == 'T';
+        bool setting = argv[2][0] == 't' || argv[2][0] == 'T';
         maliciousServers = setting;
     }
 
-    cout << "Establishing PRSONA server with the following parameters: " << endl;
-    cout << numServers << " PRSONA servers" << endl;
-    cout << "This server " << (bgnDealer ? "IS" : "is NOT") << "the trusted BGN dealer" << endl;
-    cout << "Servers are set to " << (maliciousServers ? "MALICIOUS" : "HBC") << " security" << endl;
-    cout << "This server is at IP address: " << selfIP << endl;
-    cout << "The BGN dealer is at IP address: " << dealerIP << endl;
+    seed_seq seed(seedStr.begin(), seedStr.end());
+    default_random_engine rng(seed);
+
+    cout << "[" << seedStr << "] Establishing PRSONA server with the following parameters: " << endl;
+    cout << "[" << seedStr << "] " << numServers << " PRSONA servers" << endl;
+    cout << "[" << seedStr << "] This server " << (bgnDealer ? "IS" : "is NOT") << " the trusted BGN dealer" << endl;
+    cout << "[" << seedStr << "] Servers are set to " << (maliciousServers ? "MALICIOUS" : "HBC") << " security" << endl;
+    cout << "[" << seedStr << "] This server is at IP address: " << selfIP << ":" << selfPort << endl;
+    cout << "[" << seedStr << "] The BGN dealer is at IP address: " << dealerIP << ":" << dealerPort << endl;
     cout << endl;
 
     // Set malicious flags where necessary
     if (maliciousServers)
         PrsonaBase::set_server_malicious();
 
-    cout << "Creating PrsonaServer entity." << endl;
+    cout << "[" << seedStr << "] Creating PrsonaServer entity." << endl;
 
     // Entities we operate with
     PrsonaServer *prsonaServer;
@@ -970,7 +1042,10 @@ int main(int argc, char *argv[])
         prsonaServer = new PrsonaServer(numServers);
     else
     {
-        cout << "Retrieving BGN details." << endl;
+        cout << "[" << seedStr << "] Retrieving BGN details." << endl;
+
+        struct synchronization_tool bgnSync;
+        char *bgnFilename;
 
         bool flag = false;
         while (!flag)
@@ -978,24 +1053,24 @@ int main(int argc, char *argv[])
             struct mg_connection *conn =
                 mg_connect_websocket_client(
                     dealerIP.c_str(),
-                    PRSONA_PORT,
+                    dealerPort,
                     USE_SSL,
                     NULL,
                     0,
                     PRIVATE_BGN_URI,
                     "null",
-                    bgn_websocket_data_handler,
-                    bgn_websocket_close_handler,
-                    NULL);
+                    file_websocket_data_handler,
+                    file_websocket_close_handler,
+                    &bgnSync);
 
             if (!conn)
             {
-                cerr << "Couldn't obtain BGN details." << endl;
+                cerr << "[" << seedStr << "] Couldn't obtain BGN details." << endl;
                 continue;
             }
 
             unique_lock<mutex> lck(bgnSync.mtx);
-            remove(BGN_TMP_FILE);
+            bgnFilename = set_temp_filename(rng, conn);
             bgnSync.val = 0;
             mg_websocket_client_write(
                 conn,
@@ -1011,17 +1086,20 @@ int main(int argc, char *argv[])
             flag = true;
         }
 
-        prsonaServer = create_server_from_bgn_file(numServers);
+        prsonaServer = create_server_from_bgn_file(numServers, &bgnSync, bgnFilename);
+
+        remove(bgnFilename);
+        delete bgnFilename;
     }
 
     CivetServer server(options);
 
-    PrsonaServerWebSocketHandler wsHandler(prsonaServer, &updateMtx, &epochNum, serverIPs, selfIP);
+    PrsonaServerWebSocketHandler wsHandler(prsonaServer, &rng, &updateMtx, &epochNum, serverIPs, serverPorts, selfIP, selfPort);
     server.addWebSocketHandler("/ws", wsHandler);
 
     if (bgnDealer)
     {
-        cout << "Waiting for other servers to check in and retrieve BGN details." << endl;
+        cout << "[" << seedStr << "] Waiting for other servers to check in and retrieve BGN details." << endl;
 
         unique_lock<mutex> lck(readySync.mtx);
         RemoteControlHandler serverReadyHandler(&readySync, "ACK");
@@ -1033,18 +1111,18 @@ int main(int argc, char *argv[])
 
         vector<Proof> pi;
         Twistpoint freshGenerator =
-            get_generator(pi, prsonaServer, serverIPs, selfIP, true);
+            get_generator(rng, pi, prsonaServer, serverIPs, serverPorts, selfIP, selfPort, true);
 
-        handout_generator(pi, freshGenerator, prsonaServer, serverIPs, selfIP, true);
+        handout_generator(pi, freshGenerator, prsonaServer, serverIPs, serverPorts, selfIP, selfPort, true);
 
         Twistpoint blindGenerator =
-            get_generator(pi, prsonaServer, serverIPs, selfIP, false);
+            get_generator(rng, pi, prsonaServer, serverIPs, serverPorts, selfIP, selfPort, false);
 
-        handout_generator(pi, blindGenerator, prsonaServer, serverIPs, selfIP, false);
+        handout_generator(pi, blindGenerator, prsonaServer, serverIPs, serverPorts, selfIP, selfPort, false);
     }
     else
     {
-        cout << "Notifying BGN dealer that this server is ready." << endl;
+        cout << "[" << seedStr << "] Notifying BGN dealer that this server is ready." << endl;
 
         stringstream sysString;
         string data;
@@ -1052,13 +1130,13 @@ int main(int argc, char *argv[])
         struct mg_connection *conn =
             mg_connect_client(
                 dealerIP.c_str(), 
-                PRSONA_PORT,
+                dealerPort,
                 USE_SSL, 
                 NULL,
                 0);
 
         sysString << "GET " << SERVER_READY_URI << " HTTP/1.1\r\n";
-        sysString << "Host: " << dealerIP << "\r\n\r\n";
+        sysString << "Host: " << dealerIP << ":" << dealerPort << "\r\n\r\n";
         data = sysString.str();
 
         mg_write(conn, data.c_str(), data.length());
@@ -1071,7 +1149,7 @@ int main(int argc, char *argv[])
     RemoteControlHandler exitHandler(&exitSync, "Server coming down!");
     server.addHandler(EXIT_URI, exitHandler);
 
-    cout << "Entering main ready loop." << endl;
+    cout << "[" << seedStr << "] Entering main ready loop." << endl;
 
     if (bgnDealer)
     {
@@ -1091,9 +1169,9 @@ int main(int argc, char *argv[])
 
             if (exitSync.val2)
             {
-                cout << "Executing epoch." << endl;
+                cout << "[" << seedStr << "] Executing epoch." << endl;
 
-                epoch(prsonaServer, serverIPs, selfIP);
+                epoch(prsonaServer, rng, serverIPs, serverPorts, selfIP, selfPort);
 
                 exitSync.val2 = 0;
             }
@@ -1105,7 +1183,7 @@ int main(int argc, char *argv[])
             exitSync.cv.wait(exitLock);
     }
 
-    cout << "Shutting down." << endl;
+    cout << "[" << seedStr << "] Shutting down." << endl;
 
     mg_exit_library();
     delete prsonaServer;