diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 62f36cc32b..b2bfb95558 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,6 +70,16 @@ Be sure to include any related GitHub issue references in the commit message. S [GFM syntax](https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown) for referencing issues and commits. +### Formatting Code + +We follow the guidelines outlined by the +[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). +If you use emacs, consider installing +[google-c-style.el](https://raw.githubusercontent.com/google/styleguide/gh-pages/google-c-style.el). +Please run +[cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) +against your changes, to ensure adherence to the guidelines. + ## Reporting Bugs and Creating Issues When opening a new issue, try to roughly follow the commit message format conventions above. \ No newline at end of file diff --git a/bftengine/tests/simpleTest/client.cpp b/bftengine/tests/simpleTest/client.cpp index df7eba0c9e..468baebf55 100644 --- a/bftengine/tests/simpleTest/client.cpp +++ b/bftengine/tests/simpleTest/client.cpp @@ -4,7 +4,7 @@ #include #include -#include "CommFactory.hpp" +#include "CommFactory.hpp" #include "commonDefs.h" #include "SimpleClient.hpp" @@ -14,92 +14,88 @@ using namespace bftEngine; PlainUdpConfig getUDPConfig(uint16_t id); -int main(int argc, char **argv) -{ - const int16_t id = 4; - const int numOfOperations = 2800; - const int readMod = 7; - - SeqNumberGeneratorForClientRequests* pSeqGen = SeqNumberGeneratorForClientRequests::createSeqNumberGeneratorForClientRequests(); - - PlainUdpConfig udpConf = getUDPConfig(id); - - ICommunication* comm = PlainUDPCommunication::create(udpConf); - SimpleClient* client = SimpleClient::createSimpleClient(comm, id, 1, 0); - - comm->Start(); - - uint64_t expectedStateNum = 0; - bool hasExpectedStateNum = false; - uint64_t expectedLastValue = 0; - bool hasExpectedLastValue = false; - - for (int i = 1; i <= numOfOperations; i++) - { - if (i % readMod == 0) // if read - { - char replyBuffer[sizeof(uint64_t)]; - - uint64_t reqId = READ_VAL_REQ; - uint32_t actualReplyLength = 0; - client->sendRequest(true, (char*)&reqId, sizeof(uint64_t), - pSeqGen->generateUniqueSequenceNumberForRequest(), - SimpleClient::INFINITE_TIMEOUT, - sizeof(uint64_t), - replyBuffer, - actualReplyLength); - - assert(actualReplyLength == sizeof(uint64_t)); - - uint64_t retVal = *((uint64_t*)replyBuffer); - - if (hasExpectedLastValue) - assert(retVal == expectedLastValue); - } - else // if write - { - char requestBuffer[sizeof(uint64_t) * 2]; - char replyBuffer[sizeof(uint64_t)]; - - if(hasExpectedStateNum) expectedStateNum++; - - if (!hasExpectedLastValue) hasExpectedLastValue = true; - - expectedLastValue = (i + 1)*(i + 7)*(i + 18); - - uint64_t* pReqId = (uint64_t*)requestBuffer; - uint64_t* pReqVal = (pReqId + 1); - *pReqId = SET_VAL_REQ; - *pReqVal = expectedLastValue; - uint32_t actualReplyLength = 0; - client->sendRequest(false, requestBuffer, sizeof(uint64_t)*2, - pSeqGen->generateUniqueSequenceNumberForRequest(), - SimpleClient::INFINITE_TIMEOUT, - sizeof(uint64_t), - replyBuffer, - actualReplyLength); - - assert(actualReplyLength == sizeof(uint64_t)); - - uint64_t retVal = *((uint64_t*)replyBuffer); - - if (hasExpectedStateNum) - { - assert(retVal == expectedStateNum); - } - else - { - hasExpectedStateNum = true; - expectedStateNum = retVal; - } - } - } - - comm->Stop(); - - delete pSeqGen; - delete client; - delete comm; - - return 0; -} \ No newline at end of file +int main(int argc, char **argv) { + const int16_t id = 4; + const int numOfOperations = 2800; + const int readMod = 7; + + SeqNumberGeneratorForClientRequests* pSeqGen = + SeqNumberGeneratorForClientRequests:: + createSeqNumberGeneratorForClientRequests(); + + PlainUdpConfig udpConf = getUDPConfig(id); + + ICommunication* comm = PlainUDPCommunication::create(udpConf); + SimpleClient* client = SimpleClient::createSimpleClient(comm, id, 1, 0); + + comm->Start(); + + uint64_t expectedStateNum = 0; + bool hasExpectedStateNum = false; + uint64_t expectedLastValue = 0; + bool hasExpectedLastValue = false; + + for (int i = 1; i <= numOfOperations; i++) { + if (i % readMod == 0) { + // if read + char replyBuffer[sizeof(uint64_t)]; + + uint64_t reqId = READ_VAL_REQ; + uint32_t actualReplyLength = 0; + client->sendRequest(true, (char*)&reqId, sizeof(uint64_t), + pSeqGen->generateUniqueSequenceNumberForRequest(), + SimpleClient::INFINITE_TIMEOUT, + sizeof(uint64_t), + replyBuffer, + actualReplyLength); + + assert(actualReplyLength == sizeof(uint64_t)); + + uint64_t retVal = *((uint64_t*)replyBuffer); + + if (hasExpectedLastValue) + assert(retVal == expectedLastValue); + } else { + // if write + char requestBuffer[sizeof(uint64_t) * 2]; + char replyBuffer[sizeof(uint64_t)]; + + if (hasExpectedStateNum) expectedStateNum++; + + if (!hasExpectedLastValue) hasExpectedLastValue = true; + + expectedLastValue = (i + 1)*(i + 7)*(i + 18); + + uint64_t* pReqId = (uint64_t*)requestBuffer; + uint64_t* pReqVal = (pReqId + 1); + *pReqId = SET_VAL_REQ; + *pReqVal = expectedLastValue; + uint32_t actualReplyLength = 0; + client->sendRequest(false, requestBuffer, sizeof(uint64_t)*2, + pSeqGen->generateUniqueSequenceNumberForRequest(), + SimpleClient::INFINITE_TIMEOUT, + sizeof(uint64_t), + replyBuffer, + actualReplyLength); + + assert(actualReplyLength == sizeof(uint64_t)); + + uint64_t retVal = *((uint64_t*)replyBuffer); + + if (hasExpectedStateNum) { + assert(retVal == expectedStateNum); + } else { + hasExpectedStateNum = true; + expectedStateNum = retVal; + } + } + } + + comm->Stop(); + + delete pSeqGen; + delete client; + delete comm; + + return 0; +} diff --git a/bftengine/tests/simpleTest/config.cpp b/bftengine/tests/simpleTest/config.cpp index 9b33356bef..64395c7165 100644 --- a/bftengine/tests/simpleTest/config.cpp +++ b/bftengine/tests/simpleTest/config.cpp @@ -1,7 +1,7 @@ #include #include -#include "CommFactory.hpp" +#include "CommFactory.hpp" #include "ReplicaConfig.hpp" #include @@ -17,7 +17,12 @@ using namespace bftEngine; #define MAX_ITEM_LENGTH_STR "4096" const char* nameOfPublicFile = "public_replicas_data"; -const char* namesOfPrivateFiles[] = { "private_replica_0", "private_replica_1", "private_replica_2", "private_replica_3" }; +const char* namesOfPrivateFiles[] = { + "private_replica_0", + "private_replica_1", + "private_replica_2", + "private_replica_3" +}; const int numOfReplicas = 4; const int fVal = 1; @@ -29,193 +34,210 @@ const uint16_t basePort = 3710; static void readOneLine(FILE *f, int capacity, char * buf) { - fgets(buf, capacity - 1, f); - buf[strlen(buf) - 1] = 0; // strip newline + fgets(buf, capacity - 1, f); + buf[strlen(buf) - 1] = 0; // strip newline } static void ignoreOneLine(FILE *f) { - char buf[8192]; - readOneLine(f, 8191, buf); + char buf[8192]; + readOneLine(f, 8191, buf); } -static IThresholdSigner * createThresholdSigner(FILE * f, int id, IThresholdFactory* factory) -{ - if (id < 1) { - throw std::runtime_error("Expected replica's ID to be strictly greater than zero!"); - } +static IThresholdSigner * createThresholdSigner(FILE * f, + int id, + IThresholdFactory* factory) { + if (id < 1) { + throw std::runtime_error( + "Expected replica's ID to be strictly greater than zero!"); + } - char secretKey[MAX_ITEM_LENGTH]; - ignoreOneLine(f); + char secretKey[MAX_ITEM_LENGTH]; + ignoreOneLine(f); - readOneLine(f, MAX_ITEM_LENGTH, secretKey); - return factory->newSigner(id, secretKey); + readOneLine(f, MAX_ITEM_LENGTH, secretKey); + return factory->newSigner(id, secretKey); } -static IThresholdFactory* createThresholdFactory(FILE* f, int n) -{ - char buf[MAX_ITEM_LENGTH]; - char * curveType = buf; - char cryptosys[MAX_ITEM_LENGTH]; - - ignoreOneLine(f); - readOneLine(f, MAX_ITEM_LENGTH, cryptosys); - readOneLine(f, MAX_ITEM_LENGTH, buf); - - if (strcmp(cryptosys, MULTISIG_BLS_SCHEME) == 0) { - return new BlsThresholdFactory(BLS::Relic::PublicParametersFactory::getByCurveType(curveType)); - } - else if (strcmp(cryptosys, THRESHOLD_BLS_SCHEME) == 0) { - return new BlsThresholdFactory(BLS::Relic::PublicParametersFactory::getByCurveType(curveType)); - } - else { - printf("ERROR: Unsupported cryptosystem: %s\n", cryptosys); - throw std::runtime_error("ERROR: Unsupported cryptosystem"); - } +static IThresholdFactory* createThresholdFactory(FILE* f, int n) { + char buf[MAX_ITEM_LENGTH]; + char * curveType = buf; + char cryptosys[MAX_ITEM_LENGTH]; + + ignoreOneLine(f); + readOneLine(f, MAX_ITEM_LENGTH, cryptosys); + readOneLine(f, MAX_ITEM_LENGTH, buf); + + if (strcmp(cryptosys, MULTISIG_BLS_SCHEME) == 0) { + return new BlsThresholdFactory( + BLS::Relic::PublicParametersFactory::getByCurveType(curveType)); + } else if (strcmp(cryptosys, THRESHOLD_BLS_SCHEME) == 0) { + return new BlsThresholdFactory( + BLS::Relic::PublicParametersFactory::getByCurveType(curveType)); + } else { + printf("ERROR: Unsupported cryptosystem: %s\n", cryptosys); + throw std::runtime_error("ERROR: Unsupported cryptosystem"); + } } -static IThresholdVerifier * createThresholdVerifier(FILE * f, int k, int n, IThresholdFactory* factory) { - char publicKey[MAX_ITEM_LENGTH]; - char verifKey[MAX_ITEM_LENGTH]; +static IThresholdVerifier * createThresholdVerifier( + FILE * f, int k, int n, IThresholdFactory* factory) { + char publicKey[MAX_ITEM_LENGTH]; + char verifKey[MAX_ITEM_LENGTH]; - readOneLine(f, MAX_ITEM_LENGTH, publicKey); + readOneLine(f, MAX_ITEM_LENGTH, publicKey); - ignoreOneLine(f); - std::vector verifKeys; - verifKeys.push_back(""); // signer 0 does not exist - for (int i = 0; i < n; i++) - { - readOneLine(f, MAX_ITEM_LENGTH, verifKey); - verifKeys.push_back(std::string(verifKey)); - } + ignoreOneLine(f); + std::vector verifKeys; + verifKeys.push_back(""); // signer 0 does not exist + for (int i = 0; i < n; i++) { + readOneLine(f, MAX_ITEM_LENGTH, verifKey); + verifKeys.push_back(std::string(verifKey)); + } - // Ignore last comment/empty line - ignoreOneLine(f); + // Ignore last comment/empty line + ignoreOneLine(f); - return factory->newVerifier(k, n, publicKey, verifKeys); + return factory->newVerifier(k, n, publicKey, verifKeys); } static void ignoreThresholdSigner(FILE * f) { - ignoreOneLine(f); - ignoreOneLine(f); + ignoreOneLine(f); + ignoreOneLine(f); } -static bool parseReplicaConfig(uint16_t replicaId, FILE* publicKeysFile, FILE* privateKeysFile, ReplicaConfig& outConfig) -{ +static bool parseReplicaConfig(uint16_t replicaId, + FILE* publicKeysFile, + FILE* privateKeysFile, + ReplicaConfig& outConfig) { + int tempInt = 0; + char tempString[MAX_ITEM_LENGTH]; - int tempInt = 0; - char tempString[MAX_ITEM_LENGTH]; + std::set > publicKeysOfReplicas; - std::set > publicKeysOfReplicas; + // read from publicKeysFile - // read from publicKeysFile + for (int i = 0; i < numOfReplicas; i++) { + fscanf(publicKeysFile, "%" MAX_ITEM_LENGTH_STR "s\n", tempString); - for (int i = 0; i < numOfReplicas; i++) - { - fscanf(publicKeysFile, "%" MAX_ITEM_LENGTH_STR "s\n", tempString); + string name(tempString); - string name(tempString); + string expectedName = string("replica") + std::to_string(i); - string expectedName = string("replica") + std::to_string(i); + if (expectedName != name) return false; - if (expectedName != name) return false; + fscanf(publicKeysFile, "%" MAX_ITEM_LENGTH_STR "s\n", tempString); - fscanf(publicKeysFile, "%" MAX_ITEM_LENGTH_STR "s\n", tempString); + string publicKeyString(tempString); - string publicKeyString(tempString); + publicKeysOfReplicas.insert({i, publicKeyString}); + } - publicKeysOfReplicas.insert({i, publicKeyString}); - } + // Read threshold signatures + IThresholdFactory* slowCommitFactory = nullptr; + IThresholdSigner* thresholdSignerForSlowPathCommit = nullptr; + IThresholdVerifier* thresholdVerifierForSlowPathCommit = nullptr; - // Read threshold signatures - IThresholdFactory* slowCommitFactory = nullptr; - IThresholdSigner* thresholdSignerForSlowPathCommit = nullptr; - IThresholdVerifier* thresholdVerifierForSlowPathCommit = nullptr; + IThresholdFactory* optimisticCommitFactory = nullptr; + IThresholdSigner* thresholdSignerForOptimisticCommit = nullptr; + IThresholdVerifier* thresholdVerifierForOptimisticCommit = nullptr; - IThresholdFactory* optimisticCommitFactory = nullptr; - IThresholdSigner* thresholdSignerForOptimisticCommit = nullptr; - IThresholdVerifier* thresholdVerifierForOptimisticCommit = nullptr; + slowCommitFactory = createThresholdFactory(publicKeysFile, numOfReplicas); + thresholdVerifierForSlowPathCommit = + createThresholdVerifier(publicKeysFile, + numOfReplicas - fVal, + numOfReplicas, + slowCommitFactory); - slowCommitFactory = createThresholdFactory(publicKeysFile, numOfReplicas); - thresholdVerifierForSlowPathCommit = createThresholdVerifier(publicKeysFile, numOfReplicas - fVal, numOfReplicas, slowCommitFactory); + optimisticCommitFactory = createThresholdFactory(publicKeysFile, + numOfReplicas); + thresholdVerifierForOptimisticCommit = + createThresholdVerifier(publicKeysFile, + numOfReplicas, + numOfReplicas, + optimisticCommitFactory); - optimisticCommitFactory = createThresholdFactory(publicKeysFile, numOfReplicas); - thresholdVerifierForOptimisticCommit = createThresholdVerifier(publicKeysFile, numOfReplicas, numOfReplicas, optimisticCommitFactory); + // read from privateKeysFile - // read from privateKeysFile + fscanf(privateKeysFile, "%d\n", &tempInt); + if (tempInt != replicaId) return false; - fscanf(privateKeysFile, "%d\n", &tempInt); - if (tempInt != replicaId) return false; + fscanf(privateKeysFile, "%" MAX_ITEM_LENGTH_STR "s\n", tempString); - fscanf(privateKeysFile, "%" MAX_ITEM_LENGTH_STR "s\n", tempString); + string sigPrivateKey(tempString); - string sigPrivateKey(tempString); + thresholdSignerForSlowPathCommit = + createThresholdSigner(privateKeysFile, replicaId+1, slowCommitFactory); - thresholdSignerForSlowPathCommit = createThresholdSigner(privateKeysFile, replicaId+1, slowCommitFactory); - - thresholdSignerForOptimisticCommit = createThresholdSigner(privateKeysFile, replicaId+1, optimisticCommitFactory); + thresholdSignerForOptimisticCommit = + createThresholdSigner(privateKeysFile, + replicaId+1, + optimisticCommitFactory); - delete slowCommitFactory; - delete optimisticCommitFactory; + delete slowCommitFactory; + delete optimisticCommitFactory; - // set configuration + // set configuration - outConfig.replicaId = replicaId; - outConfig.fVal = 1; - outConfig.cVal = 0; - outConfig.numOfClientProxies = 1; - outConfig.statusReportTimerMillisec = 2000; - outConfig.concurrencyLevel = 1; - outConfig.autoViewChangeEnabled = false; - outConfig.viewChangeTimerMillisec = 60000; + outConfig.replicaId = replicaId; + outConfig.fVal = 1; + outConfig.cVal = 0; + outConfig.numOfClientProxies = 1; + outConfig.statusReportTimerMillisec = 2000; + outConfig.concurrencyLevel = 1; + outConfig.autoViewChangeEnabled = false; + outConfig.viewChangeTimerMillisec = 60000; - outConfig.publicKeysOfReplicas = publicKeysOfReplicas; - outConfig.replicaPrivateKey = sigPrivateKey; + outConfig.publicKeysOfReplicas = publicKeysOfReplicas; + outConfig.replicaPrivateKey = sigPrivateKey; - outConfig.thresholdSignerForExecution = nullptr; - outConfig.thresholdVerifierForExecution = nullptr; - - outConfig.thresholdSignerForSlowPathCommit = thresholdSignerForSlowPathCommit; - outConfig.thresholdVerifierForSlowPathCommit = thresholdVerifierForSlowPathCommit; - - outConfig.thresholdSignerForCommit = nullptr; - outConfig.thresholdVerifierForCommit = nullptr; - - outConfig.thresholdSignerForOptimisticCommit = thresholdSignerForOptimisticCommit; - outConfig.thresholdVerifierForOptimisticCommit = thresholdVerifierForOptimisticCommit; + outConfig.thresholdSignerForExecution = nullptr; + outConfig.thresholdVerifierForExecution = nullptr; - return true; + outConfig.thresholdSignerForSlowPathCommit = + thresholdSignerForSlowPathCommit; + outConfig.thresholdVerifierForSlowPathCommit = + thresholdVerifierForSlowPathCommit; + + outConfig.thresholdSignerForCommit = nullptr; + outConfig.thresholdVerifierForCommit = nullptr; + + outConfig.thresholdSignerForOptimisticCommit = + thresholdSignerForOptimisticCommit; + outConfig.thresholdVerifierForOptimisticCommit = + thresholdVerifierForOptimisticCommit; + + return true; } -void getReplicaConfig(uint16_t replicaId, ReplicaConfig& outConfig) -{ - FILE* publicKeysFile = fopen(nameOfPublicFile, "r"); - if (!publicKeysFile) - throw std::runtime_error("Unable to read public keys"); +void getReplicaConfig(uint16_t replicaId, ReplicaConfig& outConfig) { + FILE* publicKeysFile = fopen(nameOfPublicFile, "r"); + if (!publicKeysFile) + throw std::runtime_error("Unable to read public keys"); - FILE* privateKeysFile = fopen(namesOfPrivateFiles[replicaId], "r"); - if (!privateKeysFile) - throw std::runtime_error("Unable to read private keys"); + FILE* privateKeysFile = fopen(namesOfPrivateFiles[replicaId], "r"); + if (!privateKeysFile) + throw std::runtime_error("Unable to read private keys"); - bool succ = parseReplicaConfig(replicaId, publicKeysFile, privateKeysFile, outConfig); - if (!succ) - throw std::runtime_error("Unable to parse configuration"); + bool succ = parseReplicaConfig( + replicaId, publicKeysFile, privateKeysFile, outConfig); + if (!succ) + throw std::runtime_error("Unable to parse configuration"); } -PlainUdpConfig getUDPConfig(uint16_t id) -{ - std::string ip = "127.0.0.1"; - uint16_t port = basePort + id*2; - uint32_t bufLength = 64000; - - std::unordered_map > nodes; - for (int i = 0; i < (numOfReplicas+1); i++) - nodes.insert({ i, std::make_tuple(ip, basePort + i*2) }); - - PlainUdpConfig retVal(ip, port, bufLength, nodes); - - return retVal; -} \ No newline at end of file +PlainUdpConfig getUDPConfig(uint16_t id) { + std::string ip = "127.0.0.1"; + uint16_t port = basePort + id*2; + uint32_t bufLength = 64000; + + std::unordered_map > nodes; + for (int i = 0; i < (numOfReplicas+1); i++) + nodes.insert({ i, std::make_tuple(ip, basePort + i*2) }); + + PlainUdpConfig retVal(ip, port, bufLength, nodes); + + return retVal; +} diff --git a/bftengine/tests/simpleTest/replica.cpp b/bftengine/tests/simpleTest/replica.cpp index e141f22689..99151ba9c4 100644 --- a/bftengine/tests/simpleTest/replica.cpp +++ b/bftengine/tests/simpleTest/replica.cpp @@ -4,7 +4,7 @@ #include #include -#include "CommFactory.hpp" +#include "CommFactory.hpp" #include "ReplicaConfig.hpp" #include "commonDefs.h" @@ -16,69 +16,73 @@ using namespace bftEngine; void getReplicaConfig(uint16_t replicaId, bftEngine::ReplicaConfig& outConfig); PlainUdpConfig getUDPConfig(uint16_t id); -class SimpleAppState : public RequestsHandler -{ -public: - virtual int execute(uint16_t clientId, bool readOnly, uint32_t requestSize, const char* request, uint32_t maxReplySize, char* outReply, uint32_t& outActualReplySize) override - { - if (readOnly) // read-only request - { - assert(requestSize == sizeof(uint64_t)); - const uint64_t reqId = *((uint64_t*)request); - assert(reqId == READ_VAL_REQ); - - assert(maxReplySize >= sizeof(uint64_t)); - uint64_t* pRet = (uint64_t*)outReply; - *pRet = lastValue; - outActualReplySize = sizeof(uint64_t); - } - else // read-write request - { - assert(requestSize == 2 * sizeof(uint64_t)); - const uint64_t* pReqId = (uint64_t*)request; - assert(*pReqId == SET_VAL_REQ); - const uint64_t* pReqVal = (pReqId + 1); - - stateNum++; - lastValue = *pReqVal; - - assert(maxReplySize >= sizeof(uint64_t)); - uint64_t* pRet = (uint64_t*)outReply; - *pRet = stateNum; - outActualReplySize = sizeof(uint64_t); - } - - return 0; - } - -protected: - // state - uint64_t stateNum = 0; - uint64_t lastValue = 0; +class SimpleAppState : public RequestsHandler { + public: + virtual int execute(uint16_t clientId, + bool readOnly, + uint32_t requestSize, + const char* request, + uint32_t maxReplySize, + char* outReply, + uint32_t& outActualReplySize) override { + if (readOnly) { + // read-only request + assert(requestSize == sizeof(uint64_t)); + const uint64_t reqId = *((uint64_t*)request); + assert(reqId == READ_VAL_REQ); + + assert(maxReplySize >= sizeof(uint64_t)); + uint64_t* pRet = (uint64_t*)outReply; + *pRet = lastValue; + outActualReplySize = sizeof(uint64_t); + } else { + assert(requestSize == 2 * sizeof(uint64_t)); + const uint64_t* pReqId = (uint64_t*)request; + assert(*pReqId == SET_VAL_REQ); + const uint64_t* pReqVal = (pReqId + 1); + + stateNum++; + lastValue = *pReqVal; + + assert(maxReplySize >= sizeof(uint64_t)); + uint64_t* pRet = (uint64_t*)outReply; + *pRet = stateNum; + outActualReplySize = sizeof(uint64_t); + } + + return 0; + } + + protected: + // state + uint64_t stateNum = 0; + uint64_t lastValue = 0; }; -int main(int argc, char **argv) -{ - if (argc < 2) throw std::runtime_error("Unable to read replica id"); - uint16_t id = (argv[1][0] - '0'); - if (id >= 4) throw std::runtime_error("Illegal replica id"); +int main(int argc, char **argv) { + if (argc < 2) throw std::runtime_error("Unable to read replica id"); + uint16_t id = (argv[1][0] - '0'); + if (id >= 4) throw std::runtime_error("Illegal replica id"); - ReplicaConfig replicaConfig; - getReplicaConfig(id, replicaConfig); + ReplicaConfig replicaConfig; + getReplicaConfig(id, replicaConfig); - PlainUdpConfig udpConf = getUDPConfig(id); - + PlainUdpConfig udpConf = getUDPConfig(id); - ICommunication* comm = PlainUDPCommunication::create(udpConf); + ICommunication* comm = PlainUDPCommunication::create(udpConf); - SimpleAppState simpleAppState; + SimpleAppState simpleAppState; - Replica* replica = Replica::createNewReplica(&replicaConfig, &simpleAppState, nullptr, comm, nullptr); + Replica* replica = Replica::createNewReplica(&replicaConfig, + &simpleAppState, + nullptr, + comm, + nullptr); - replica->start(); + replica->start(); - // wait forever... - while (true) std::this_thread::sleep_for(std::chrono::seconds(1)); - - return 0; -} \ No newline at end of file + // wait forever... + while (true) std::this_thread::sleep_for(std::chrono::seconds(1)); + + return 0; +}