From 374424f98fb6c54a08c093a10e7b0de5bf400b35 Mon Sep 17 00:00:00 2001 From: Ravin Perera <33562092+ravinsp@users.noreply.github.com> Date: Wed, 9 Oct 2019 22:26:08 +0530 Subject: [PATCH] Code comments and consistency improvements. (#12) --- CMakeLists.txt | 3 +- README.md | 6 +- src/conf.cpp | 244 ++- src/conf.h | 69 - src/conf.hpp | 90 + src/crypto.cpp | 97 +- src/crypto.h | 35 - src/crypto.hpp | 60 + src/main.cpp | 8 +- src/p2p/message.pb.cc | 1518 +++-------------- src/p2p/message.pb.h | 696 ++++++-- src/p2p/{p2p.h => p2p.hpp} | 0 src/proc.cpp | 27 +- src/proc.h | 32 - src/proc.hpp | 44 + src/shared.h | 52 - src/sock/socket_client.cpp | 2 +- .../{socket_client.h => socket_client.hpp} | 4 +- src/sock/socket_server.cpp | 2 +- .../{socket_server.h => socket_server.hpp} | 2 +- src/sock/socket_session.cpp | 2 +- .../{socket_session.h => socket_session.hpp} | 2 +- ...n_handler.h => socket_session_handler.hpp} | 2 +- src/usr/usr.cpp | 151 +- src/usr/usr.h | 26 - src/usr/usr.hpp | 97 ++ src/{shared.cpp => util.cpp} | 31 +- src/util.hpp | 89 + 28 files changed, 1510 insertions(+), 1881 deletions(-) delete mode 100644 src/conf.h create mode 100644 src/conf.hpp delete mode 100644 src/crypto.h create mode 100644 src/crypto.hpp rename src/p2p/{p2p.h => p2p.hpp} (100%) delete mode 100644 src/proc.h create mode 100644 src/proc.hpp delete mode 100644 src/shared.h rename src/sock/{socket_client.h => socket_client.hpp} (94%) rename src/sock/{socket_server.h => socket_server.hpp} (95%) rename src/sock/{socket_session.h => socket_session.hpp} (97%) rename src/sock/{socket_session_handler.h => socket_session_handler.hpp} (94%) delete mode 100644 src/usr/usr.h create mode 100644 src/usr/usr.hpp rename src/{shared.cpp => util.cpp} (76%) create mode 100644 src/util.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fe45232..3c90de44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,8 @@ add_executable(hpcore src/conf.cpp src/crypto.cpp src/proc.cpp - src/shared.cpp src/usr/usr.cpp - src/shared.cpp + src/util.cpp src/p2p/message.pb.cc src/sock/socket_client.cpp src/sock/socket_server.cpp diff --git a/README.md b/README.md index 741f2d87..1ad23c9e 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Following Instructions are based on Boost [getting started](https://www.boost.or #### Install Protocol buffers Instructions are based on [this](https://github.com/protocolbuffers/protobuf/tree/master/src). -1. Download and extract Protobuf 3.10.0 from [here](https://github.com/protocolbuffers/protobuf/releases/tag/v3.10.0). +1. Download and extract Protobuf 3.10.0 from [here](https://github.com/protocolbuffers/protobuf/releases/download/v3.10.0/protobuf-cpp-3.10.0.tar.gz). 2. Navigate to the extracted Protobuf directory in a terminal. 3. Run `./configure` 4. Run `make && make check` @@ -82,8 +82,8 @@ Handles contract process execution. #### usr Handles user connections and processing of user I/O with the smart contract. Makes use of **crypto** and **sock**. -#### ntn -Handles node-to-node connections and message exchange between nodes. Also handles smart contract node-party-line (npl) I/O. Makes use of **crypto** and **sock**. +#### p2p +Handles peer-to-peer connections and message exchange between nodes. Also handles smart contract node-party-line (npl) I/O. Makes use of **crypto** and **sock**. #### cons Handles consensus and proposal rounds. Makes use of **usr**, **ntn** and **proc** diff --git a/src/conf.cpp b/src/conf.cpp index 96b6b0cc..3cc36d7a 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -8,9 +8,9 @@ #include #include #include -#include "conf.h" -#include "crypto.h" -#include "shared.h" +#include "conf.hpp" +#include "crypto.hpp" +#include "util.hpp" using namespace std; using namespace rapidjson; @@ -18,20 +18,25 @@ using namespace rapidjson; namespace conf { -ContractCtx ctx; -ContractConfig cfg; +contract_ctx ctx; +contract_config cfg; -bool validate_config(); int load_config(); -void save_config(); -void binpair_to_b64(); +int save_config(); +int validate_config(); +int validate_contract_dir_paths(); +int is_schema_valid(Document &d); +int binpair_to_b64(); int b64pair_to_bin(); -bool validate_contract_dir_paths(); -bool is_schema_valid(Document &d); int init() { - if (!validate_contract_dir_paths() || load_config() != 0 || !validate_config()) + // The validations/loading needs to be in this order. + // 1. Validate contract directories + // 2. Read and load the contract config into memory + // 3. Validate the loaded config values + + if (validate_contract_dir_paths() != 0 || load_config() != 0 || validate_config() != 0) return -1; return 0; @@ -39,21 +44,83 @@ int init() int rekey() { + // Load the contract config and re-save with the newly generated keys. + if (load_config() != 0) return -1; crypto::generate_signing_keys(cfg.pubkey, cfg.seckey); - binpair_to_b64(); + if (binpair_to_b64() != 0) + return -1; - save_config(); + if (save_config() != 0) + return -1; cout << "New signing keys generated at " << ctx.configFile << endl; return 0; } +int create_contract() +{ + if (boost::filesystem::exists(ctx.contractDir)) + { + cerr << "Contract dir already exists. Cannot create contract at the same location.\n"; + return -1; + } + + boost::filesystem::create_directories(ctx.configDir); + boost::filesystem::create_directories(ctx.histDir); + boost::filesystem::create_directories(ctx.stateDir); + + //Create config file with default settings. + + //We populate the in-memory struct with default settings and then save it to the file. + + crypto::generate_signing_keys(cfg.pubkey, cfg.seckey); + if (binpair_to_b64() != 0) + return -1; + + cfg.listenip = "0.0.0.0"; + cfg.peerport = 22860; + cfg.roundtime = 1000; + cfg.pubport = 8080; + cfg.pubmaxsize = 65536; + cfg.pubmaxcpm = 100; + + //Save the default settings into the config file. + if (save_config() != 0) + return -1; + + cout << "Contract directory created at " << ctx.contractDir << endl; + + return 0; +} + +void set_contract_dir_paths(string basedir) +{ + if (basedir[basedir.size() - 1] == '/') + basedir = basedir.substr(0, basedir.size() - 1); + + ctx.contractDir = basedir; + ctx.configDir = basedir + "/cfg"; + ctx.configFile = ctx.configDir + "/hp.cfg"; + ctx.histDir = basedir + "/hist"; + ctx.stateDir = basedir + "/state"; +} + + +//------Private functions for this namespace (not exposed via header). + +/** + * Reads the config file on disk and populates the in-memory 'cfg' struct. + * + * @return 0 for successful loading of config. -1 for failure. + */ int load_config() { + // Read the file into json document object. + ifstream ifs(ctx.configFile); IStreamWrapper isw(ifs); @@ -63,13 +130,14 @@ int load_config() cerr << "Invalid config file format. Parser error at position " << d.GetErrorOffset() << endl; return -1; } - else if (!is_schema_valid(d)) + else if (is_schema_valid(d) != 0) { cerr << "Invalid config file format.\n"; return -1; } + ifs.close(); - //Check contract version. + // Check whether the contract version is specified. string cfgversion = d["version"].GetString(); if (cfgversion.empty()) { @@ -77,8 +145,9 @@ int load_config() return -1; } + // Check whether this contract complies with the min version requirement. string minversion = string(_HP_MIN_CONTRACT_VERSION_); - if (shared::version_compare(cfgversion, minversion) == -1) + if (util::version_compare(cfgversion, minversion) == -1) { cerr << "Contract version too old. Minimum " << _HP_MIN_CONTRACT_VERSION_ << " required. " @@ -86,6 +155,8 @@ int load_config() return -1; } + // Load up the values into the struct. + cfg.pubkeyb64 = d["pubkeyb64"].GetString(); cfg.seckeyb64 = d["seckeyb64"].GetString(); cfg.binary = d["binary"].GetString(); @@ -106,14 +177,22 @@ int load_config() cfg.pubmaxsize = d["pubmaxsize"].GetInt(); cfg.pubmaxcpm = d["pubmaxcpm"].GetInt(); + // Convert the b64 keys to binary and keep for later use. if (b64pair_to_bin() != 0) return -1; return 0; } -void save_config() +/** + * Saves the current values of the 'cfg' struct into the config file. + * + * @return 0 for successful save. -1 for failure. + */ +int save_config() { + // Popualte json document with 'cfg' values. + Document d; d.SetObject(); Document::AllocatorType &allocator = d.GetAllocator(); @@ -148,120 +227,121 @@ void save_config() d.AddMember("pubmaxsize", cfg.pubmaxsize, allocator); d.AddMember("pubmaxcpm", cfg.pubmaxcpm, allocator); + + // Write the json doc to file. + ofstream ofs(ctx.configFile); OStreamWrapper osw(ofs); PrettyWriter writer(osw); - d.Accept(writer); -} - -int create_contract() -{ - if (boost::filesystem::exists(ctx.contractDir)) + if (!d.Accept(writer)) { - cerr << "Contract dir already exists. Cannot create contract at the same location.\n"; + cerr << "Writing to config file failed. " << ctx.configFile << endl; return -1; } - - boost::filesystem::create_directories(ctx.configDir); - boost::filesystem::create_directories(ctx.histDir); - boost::filesystem::create_directories(ctx.stateDir); - - //Create config file with default settings. - - crypto::generate_signing_keys(cfg.pubkey, cfg.seckey); - binpair_to_b64(); - - cfg.listenip = "0.0.0.0"; - cfg.peerport = 22860; - cfg.roundtime = 1000; - cfg.pubport = 8080; - cfg.pubmaxsize = 65536; - cfg.pubmaxcpm = 100; - save_config(); - - cout << "Contract directory created at " << ctx.contractDir << endl; - - if (load_config() != 0) - return -1; + ofs.close(); return 0; } -void binpair_to_b64() +/** + * Decode current binary keys in 'cfg' and populate the it with base64 keys. + * + * @return 0 for successful conversion. -1 for failure. + */ +int binpair_to_b64() { - shared::base64_encode((unsigned char *)cfg.pubkey.data(), crypto_sign_PUBLICKEYBYTES, cfg.pubkeyb64); - shared::base64_encode((unsigned char *)cfg.seckey.data(), crypto_sign_SECRETKEYBYTES, cfg.seckeyb64); + if (util::base64_encode((unsigned char *)cfg.pubkey.data(), crypto_sign_PUBLICKEYBYTES, cfg.pubkeyb64) != 0) + { + cerr << "Error encoding public key bytes.\n"; + return -1; + } + + if (util::base64_encode((unsigned char *)cfg.seckey.data(), crypto_sign_SECRETKEYBYTES, cfg.seckeyb64) != 0) + { + cerr << "Error encoding secret key bytes.\n"; + return -1; + } + + return 0; } +/** + * Decode current base64 keys in 'cfg' and populate the it with binary keys. + * + * @return 0 for successful conversion. -1 for failure. + */ int b64pair_to_bin() { unsigned char decoded_pubkey[crypto_sign_PUBLICKEYBYTES]; unsigned char decoded_seckey[crypto_sign_SECRETKEYBYTES]; - if (shared::base64_decode(cfg.pubkeyb64, decoded_pubkey, crypto_sign_PUBLICKEYBYTES) != 0) + if (util::base64_decode(cfg.pubkeyb64, decoded_pubkey, crypto_sign_PUBLICKEYBYTES) != 0) { cerr << "Error decoding base64 public key.\n"; return -1; } - if (shared::base64_decode(cfg.seckeyb64, decoded_seckey, crypto_sign_SECRETKEYBYTES) != 0) + if (util::base64_decode(cfg.seckeyb64, decoded_seckey, crypto_sign_SECRETKEYBYTES) != 0) { cerr << "Error decoding base64 secret key.\n"; return -1; } - shared::replace_string_contents(cfg.pubkey, (char *)decoded_pubkey, crypto_sign_PUBLICKEYBYTES); - shared::replace_string_contents(cfg.seckey, (char *)decoded_seckey, crypto_sign_SECRETKEYBYTES); + // Assign the cfg pubkey/seckey fields with the decoded strings. + util::replace_string_contents(cfg.pubkey, (char *)decoded_pubkey, crypto_sign_PUBLICKEYBYTES); + util::replace_string_contents(cfg.seckey, (char *)decoded_seckey, crypto_sign_SECRETKEYBYTES); return 0; } -bool validate_config() +/** + * Validates the 'cfg' struct for invalid values. + * + * @return 0 for successful validation. -1 for failure. + */ +int validate_config() { + // Check for non-empty signing keys. + // We also check for key pair validity as well in the below code. if (cfg.pubkeyb64.empty() || cfg.seckeyb64.empty()) { cerr << "Signing keys missing. Run with 'rekey' to generate new keys.\n"; - return false; + return -1; } + // Other required fields. if (cfg.binary.empty() || cfg.listenip.empty() || cfg.peerport == 0 || cfg.roundtime == 0 || cfg.pubport == 0 || cfg.pubmaxsize == 0 || cfg.pubmaxcpm == 0) { cerr << "Required configuration fields missing at " << ctx.configFile << endl; - return false; + return -1; } + // Check whether the contract binary actually exists. if (!boost::filesystem::exists(cfg.binary)) { cerr << "Contract binary does not exist: " << cfg.binary << endl; - return false; + return -1; } - //Sign and verify a sample to ensure we have a matching signing key pair. + //Sign and verify a sample message to ensure we have a matching signing key pair. string msg = "hotpocket"; string sigb64 = crypto::sign_b64(msg, cfg.seckeyb64); - if (!crypto::verify_b64(msg, sigb64, cfg.pubkeyb64)) + if (crypto::verify_b64(msg, sigb64, cfg.pubkeyb64) != 0) { cerr << "Invalid signing keys. Run with 'rekey' to generate new keys.\n"; - return false; + return -1; } - return true; + return 0; } -void set_contract_dir_paths(string basedir) -{ - if (basedir[basedir.size() - 1] == '/') - basedir = basedir.substr(0, basedir.size() - 1); - - ctx.contractDir = basedir; - ctx.configDir = basedir + "/cfg"; - ctx.configFile = ctx.configDir + "/hp.cfg"; - ctx.histDir = basedir + "/hist"; - ctx.stateDir = basedir + "/state"; -} - -bool validate_contract_dir_paths() +/** + * Checks for the existence of all contract sub directories. + * + * @return 0 for successful validation. -1 for failure. + */ +int validate_contract_dir_paths() { string dirs[4] = {ctx.contractDir, ctx.configFile, ctx.histDir, ctx.stateDir}; @@ -270,14 +350,19 @@ bool validate_contract_dir_paths() if (!boost::filesystem::exists(dir)) { cerr << dir << " does not exist.\n"; - return false; + return -1; } } - return true; + return 0; } -bool is_schema_valid(Document &d) +/** + * Validates the config json document schema. + * + * @return 0 for successful validation. -1 for failure. + */ +int is_schema_valid(Document &d) { const char *cfg_schema = "{" @@ -312,7 +397,10 @@ bool is_schema_valid(Document &d) SchemaDocument schema(sd); SchemaValidator validator(schema); - return d.Accept(validator); + if (!d.Accept(validator)) + return -1; + + return 0; } } // namespace conf \ No newline at end of file diff --git a/src/conf.h b/src/conf.h deleted file mode 100644 index 34ec228b..00000000 --- a/src/conf.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _HP_CONF_H_ -#define _HP_CONF_H_ - -//Hot Pocket version. Displayed on 'hotpocket version' and written to new contract configs. -#define _HP_VERSION_ "0.1" -//minimum compatible contract config version (this will be used to validate contract configs) -#define _HP_MIN_CONTRACT_VERSION_ "0.1" -//minimum compatible peer message version (this will be used to accept/reject incoming peer connections) -//(Keeping this as int for effcient msg payload and comparison) -#define _HP_MIN_PEERMSG_VERSION_ 1 - -#include -#include - -using namespace std; -using namespace rapidjson; - -namespace conf -{ - -struct ContractCtx -{ - string command; - string contractDir; - string histDir; - string stateDir; - string configDir; - string configFile; -}; - -struct ContractConfig -{ - /* - Config elements which are only initialized in memory (these are not loaded from the config file) - */ - //public key bytes - string pubkey; - //secret key bytes - string seckey; - - /* - Config elements which are loaded from the config file. - */ - string pubkeyb64; - string seckeyb64; - string binary; - string binargs; - string listenip; - vector peers; - vector unl; - unsigned short peerport; - int roundtime; - unsigned short pubport; - int pubmaxsize; - int pubmaxcpm; -}; - -extern ContractCtx ctx; -extern ContractConfig cfg; -int init(); -int rekey(); -int create_contract(); -void set_contract_dir_paths(string basedir); -int load_config(); -void save_config(); - -} // namespace conf - -#endif \ No newline at end of file diff --git a/src/conf.hpp b/src/conf.hpp new file mode 100644 index 00000000..910c150c --- /dev/null +++ b/src/conf.hpp @@ -0,0 +1,90 @@ +#ifndef _HP_CONF_H_ +#define _HP_CONF_H_ + +// Hot Pocket version. Displayed on 'hotpocket version' and written to new contract configs. +#define _HP_VERSION_ "0.1" + +// Minimum compatible contract config version (this will be used to validate contract configs) +#define _HP_MIN_CONTRACT_VERSION_ "0.1" + +// Minimum compatible peer message version (this will be used to accept/reject incoming peer connections) +// (Keeping this as int for effcient msg payload and comparison) +#define _HP_MIN_PEERMSG_VERSION_ 1 + +#include +#include + +using namespace std; +using namespace rapidjson; + +namespace conf +{ + +// Holds contextual information of the currently loaded contract. +struct contract_ctx +{ + + string command; // The CLI command issued to launch HotPocket + + string contractDir; // Contract base directory + string histDir; // Contract history dir + string stateDir; // Contract state dir + string configDir; // Contract config dir + string configFile; // Full path to the contract config file +}; + +// +struct contract_config +{ + // Config elements which are initialized in memory (these are not directly loaded from the config file) + + string pubkey; // Contract public key bytes + string seckey; // Contract secret key bytes + + + // Config elements which are loaded from the config file. + + string pubkeyb64; // Contract base64 public key + string seckeyb64; // Contract base64 secret key + string binary; // Full path to the contract binary + string binargs; // CLI arguments to pass to the contract binary + string listenip; // The IPs to listen on for incoming connections + vector peers; // List of peers in the format ":" + vector unl; // Unique node list (list of base64 public keys) + unsigned short peerport; // Listening port for peer connections + int roundtime; // Consensus round time in ms + unsigned short pubport; // Listening port for public user connections + int pubmaxsize; // User message max size in bytes + int pubmaxcpm; // User message rate +}; + +//Global contract context struct exposed to the application. +extern contract_ctx ctx; + +//Global configuration struct exposed to the application. +extern contract_config cfg; + +/** + * Loads and initializes the contract config for execution. Must be called once during application startup. + * @return 0 for success. -1 for failure. + */ +int init(); + +/** + * Generates and saves new signing keys in the contract config. + */ +int rekey(); + +/** + * Creates a new contract directory with the default contract config. + */ +int create_contract(); + +/** + * Updates the contract context with directory paths based on provided base directory. + */ +void set_contract_dir_paths(string basedir); + +} // namespace conf + +#endif \ No newline at end of file diff --git a/src/crypto.cpp b/src/crypto.cpp index 973b3746..aaf656df 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -1,57 +1,14 @@ #include #include #include -#include "crypto.h" -#include "shared.h" +#include "crypto.hpp" +#include "util.hpp" using namespace std; namespace crypto { -void generate_signing_keys(); -void binpair_to_b64(); -int b64pair_to_bin(); - -string sign(string &msg, string &seckey) -{ - unsigned char sigchars[crypto_sign_BYTES]; - crypto_sign_detached(sigchars, NULL, (unsigned char *)msg.data(), msg.length(), (unsigned char *)seckey.data()); - string sig((char *)sigchars, crypto_sign_BYTES); - return sig; -} - -string sign_b64(string &msg, string &seckeyb64) -{ - unsigned char seckey[crypto_sign_SECRETKEYBYTES]; - shared::base64_decode(seckeyb64, seckey, crypto_sign_SECRETKEYBYTES); - - unsigned char sig[crypto_sign_BYTES]; - crypto_sign_detached(sig, NULL, (unsigned char *)msg.data(), msg.length(), seckey); - string sigb64; - shared::base64_encode(sig, crypto_sign_BYTES, sigb64); - return sigb64; -} - -bool verify(string &msg, string &sig, string &pubkey) -{ - int result = crypto_sign_verify_detached( - (unsigned char *)sig.data(), (unsigned char *)msg.data(), msg.length(), (unsigned char *)pubkey.data()); - return result == 0; -} - -bool verify_b64(string &msg, string &sigb64, string &pubkeyb64) -{ - unsigned char decoded_pubkey[crypto_sign_PUBLICKEYBYTES]; - shared::base64_decode(pubkeyb64, decoded_pubkey, crypto_sign_PUBLICKEYBYTES); - - unsigned char decoded_sig[crypto_sign_BYTES]; - shared::base64_decode(sigb64, decoded_sig, crypto_sign_BYTES); - - int result = crypto_sign_verify_detached(decoded_sig, (unsigned char *)msg.data(), msg.length(), decoded_pubkey); - return result == 0; -} - int init() { if (sodium_init() < 0) @@ -65,12 +22,58 @@ int init() void generate_signing_keys(string &pubkey, string &seckey) { + //Generate key pair using libsodium default algorithm. (Currently using ed25519) + unsigned char pubkeychars[crypto_sign_PUBLICKEYBYTES]; unsigned char seckeychars[crypto_sign_SECRETKEYBYTES]; crypto_sign_keypair(pubkeychars, seckeychars); - shared::replace_string_contents(pubkey, (char *)pubkeychars, crypto_sign_PUBLICKEYBYTES); - shared::replace_string_contents(seckey, (char *)seckeychars, crypto_sign_SECRETKEYBYTES); + util::replace_string_contents(pubkey, (char *)pubkeychars, crypto_sign_PUBLICKEYBYTES); + util::replace_string_contents(seckey, (char *)seckeychars, crypto_sign_SECRETKEYBYTES); +} + +string sign(const string &msg, const string &seckey) +{ + //Generate the signature using libsodium. + + unsigned char sigchars[crypto_sign_BYTES]; + crypto_sign_detached(sigchars, NULL, (unsigned char *)msg.data(), msg.length(), (unsigned char *)seckey.data()); + string sig((char *)sigchars, crypto_sign_BYTES); + return sig; +} + +string sign_b64(const string &msg, const string &seckeyb64) +{ + //Decode b64 string and generate the signature using libsodium. + + unsigned char seckey[crypto_sign_SECRETKEYBYTES]; + util::base64_decode(seckeyb64, seckey, crypto_sign_SECRETKEYBYTES); + + unsigned char sig[crypto_sign_BYTES]; + crypto_sign_detached(sig, NULL, (unsigned char *)msg.data(), msg.length(), seckey); + + string sigb64; + util::base64_encode(sig, crypto_sign_BYTES, sigb64); + return sigb64; +} + +int verify(const string &msg, const string &sig, const string &pubkey) +{ + return crypto_sign_verify_detached( + (unsigned char *)sig.data(), (unsigned char *)msg.data(), msg.length(), (unsigned char *)pubkey.data()); +} + +int verify_b64(const string &msg, const string &sigb64, const string &pubkeyb64) +{ + //Decode b64 string and verify the signature using libsodium. + + unsigned char decoded_pubkey[crypto_sign_PUBLICKEYBYTES]; + util::base64_decode(pubkeyb64, decoded_pubkey, crypto_sign_PUBLICKEYBYTES); + + unsigned char decoded_sig[crypto_sign_BYTES]; + util::base64_decode(sigb64, decoded_sig, crypto_sign_BYTES); + + return crypto_sign_verify_detached(decoded_sig, (unsigned char *)msg.data(), msg.length(), decoded_pubkey); } } // namespace crypto \ No newline at end of file diff --git a/src/crypto.h b/src/crypto.h deleted file mode 100644 index dd6e0e14..00000000 --- a/src/crypto.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _HP_CRYPTO_H_ -#define _HP_CRYPTO_H_ - -using namespace std; - -namespace crypto -{ - -int init(); - -void generate_signing_keys(string &pubkey, string &seckey); - -/** - * Returns the signature bytes for the given message bytes using the provided secret key bytes. - */ -string sign(string &msg, string &seckey); - -/** - * Returns the base64 signature for the given message bytes using the provided base64 secret key. - */ -string sign_b64(string &msg, string &seckeyb64); - -/** - * Verifies the given signature bytes for the message bytes using the provided public key bytes. - */ -bool verify(string &msg, string &sig, string &pubkey); - -/** - * Verifies the given base64 signature with the message bytes using the provided base64 public key. - */ -bool verify_b64(string &msg, string &sigb64, string &pubkeyb64); - -} // namespace crypto - -#endif \ No newline at end of file diff --git a/src/crypto.hpp b/src/crypto.hpp new file mode 100644 index 00000000..3bfb317f --- /dev/null +++ b/src/crypto.hpp @@ -0,0 +1,60 @@ +#ifndef _HP_CRYPTO_H_ +#define _HP_CRYPTO_H_ + +using namespace std; + +namespace crypto +{ + +/** + * Initializes the crypto subsystem. Must be called once during application startup. + * @return 0 for successful initialization. -1 for failure. + */ +int init(); + +/** + * Generates a signing key pair using libsodium and assigns them to the provided strings. + */ +void generate_signing_keys(string &pubkey, string &seckey); + +/** + * Returns the signature bytes for a message. + * + * @param msg Message bytes to sign. + * @param seckey Secret key bytes. + * @return Signature bytes. + */ +string sign(const string &msg, const string &seckey); + +/** + * Returns the base64 signature string for a message. + * + * @param msg Base64 message string to sign. + * @param seckey Base64 secret key string. + * @return Base64 signature string. + */ +string sign_b64(const string &msg, const string &seckeyb64); + +/** + * Verifies the given signature bytes for the message. + * + * @param msg Message bytes. + * @param sig Signature bytes. + * @param pubkey Public key bytes. + * @return 0 for successful verification. -1 for failure. + */ +int verify(const string &msg, const string &sig, const string &pubkey); + +/** + * Verifies the given base64 signature for the message. + * + * @param msg Base64 message string. + * @param sig Base64 signature string. + * @param pubkey Base64 secret key. + * @return 0 for successful verification. -1 for failure. + */ +int verify_b64(const string &msg, const string &sigb64, const string &pubkeyb64); + +} // namespace crypto + +#endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b50b9774..f2d23f30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,9 +4,9 @@ #include #include -#include "conf.h" -#include "crypto.h" -#include "usr/usr.h" +#include "conf.hpp" +#include "crypto.hpp" +#include "usr/usr.hpp" using namespace std; @@ -82,5 +82,5 @@ int parse_cmd(int argc, char **argv) cout << "hpcore (command = run | new | rekey)\n"; cout << "Example: hpcore run ~/mycontract\n"; - return 0; + return -1; } diff --git a/src/p2p/message.pb.cc b/src/p2p/message.pb.cc index 9df6020e..6aa20958 100644 --- a/src/p2p/message.pb.cc +++ b/src/p2p/message.pb.cc @@ -5,7 +5,6 @@ #include -#include #include #include #include @@ -87,7 +86,7 @@ static void InitDefaultsscc_info_HistoryRequest_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_HistoryRequest_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_HistoryRequest_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_HistoryRequest_message_2eproto}, {}}; static void InitDefaultsscc_info_HistoryResponse_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -101,7 +100,7 @@ static void InitDefaultsscc_info_HistoryResponse_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_HistoryResponse_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_HistoryResponse_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_HistoryResponse_message_2eproto}, {}}; static void InitDefaultsscc_info_Message_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -115,7 +114,7 @@ static void InitDefaultsscc_info_Message_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_Message_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_Message_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_Message_message_2eproto}, {}}; static void InitDefaultsscc_info_NPL_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -129,7 +128,7 @@ static void InitDefaultsscc_info_NPL_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_NPL_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_NPL_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_NPL_message_2eproto}, {}}; static void InitDefaultsscc_info_Proposal_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -143,7 +142,7 @@ static void InitDefaultsscc_info_Proposal_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_Proposal_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsscc_info_Proposal_message_2eproto}, { + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, 0, InitDefaultsscc_info_Proposal_message_2eproto}, { &scc_info_State_message_2eproto.base,}}; static void InitDefaultsscc_info_State_message_2eproto() { @@ -158,7 +157,7 @@ static void InitDefaultsscc_info_State_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<2> scc_info_State_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 2, InitDefaultsscc_info_State_message_2eproto}, { + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 2, 0, InitDefaultsscc_info_State_message_2eproto}, { &scc_info_StateDifference_message_2eproto.base, &scc_info_State_PatchEntry_DoNotUse_message_2eproto.base,}}; @@ -173,7 +172,7 @@ static void InitDefaultsscc_info_State_PatchEntry_DoNotUse_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_State_PatchEntry_DoNotUse_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_State_PatchEntry_DoNotUse_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_State_PatchEntry_DoNotUse_message_2eproto}, {}}; static void InitDefaultsscc_info_StateDifference_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -187,7 +186,7 @@ static void InitDefaultsscc_info_StateDifference_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<3> scc_info_StateDifference_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 3, InitDefaultsscc_info_StateDifference_message_2eproto}, { + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 3, 0, InitDefaultsscc_info_StateDifference_message_2eproto}, { &scc_info_StateDifference_CreatedEntry_DoNotUse_message_2eproto.base, &scc_info_StateDifference_UpdatedEntry_DoNotUse_message_2eproto.base, &scc_info_StateDifference_DeletedEntry_DoNotUse_message_2eproto.base,}}; @@ -203,7 +202,7 @@ static void InitDefaultsscc_info_StateDifference_CreatedEntry_DoNotUse_message_2 } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StateDifference_CreatedEntry_DoNotUse_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_StateDifference_CreatedEntry_DoNotUse_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StateDifference_CreatedEntry_DoNotUse_message_2eproto}, {}}; static void InitDefaultsscc_info_StateDifference_DeletedEntry_DoNotUse_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -216,7 +215,7 @@ static void InitDefaultsscc_info_StateDifference_DeletedEntry_DoNotUse_message_2 } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StateDifference_DeletedEntry_DoNotUse_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_StateDifference_DeletedEntry_DoNotUse_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StateDifference_DeletedEntry_DoNotUse_message_2eproto}, {}}; static void InitDefaultsscc_info_StateDifference_UpdatedEntry_DoNotUse_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -229,7 +228,7 @@ static void InitDefaultsscc_info_StateDifference_UpdatedEntry_DoNotUse_message_2 } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StateDifference_UpdatedEntry_DoNotUse_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_StateDifference_UpdatedEntry_DoNotUse_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StateDifference_UpdatedEntry_DoNotUse_message_2eproto}, {}}; static void InitDefaultsscc_info_StateRequest_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -243,7 +242,7 @@ static void InitDefaultsscc_info_StateRequest_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StateRequest_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_StateRequest_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StateRequest_message_2eproto}, {}}; static void InitDefaultsscc_info_StateResponse_message_2eproto() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -257,7 +256,7 @@ static void InitDefaultsscc_info_StateResponse_message_2eproto() { } ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_StateResponse_message_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsscc_info_StateResponse_message_2eproto}, {}}; + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_StateResponse_message_2eproto}, {}}; static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_message_2eproto[13]; static const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* file_level_enum_descriptors_message_2eproto[1]; @@ -547,19 +546,19 @@ Message::Message(const Message& from) _has_bits_(from._has_bits_) { _internal_metadata_.MergeFrom(from._internal_metadata_); version_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_version()) { + if (from._internal_has_version()) { version_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.version_); } publickey_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_publickey()) { + if (from._internal_has_publickey()) { publickey_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.publickey_); } signature_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_signature()) { + if (from._internal_has_signature()) { signature_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.signature_); } content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_content()) { + if (from._internal_has_content()) { content_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.content_); } ::memcpy(×tamp_, &from.timestamp_, @@ -630,7 +629,6 @@ void Message::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* Message::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; @@ -642,14 +640,14 @@ const char* Message::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in // optional string version = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(mutable_version(), ptr, ctx, "p2p.Message.version"); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_mutable_version(), ptr, ctx, "p2p.Message.version"); CHK_(ptr); } else goto handle_unusual; continue; // optional bytes publicKey = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_publickey(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_publickey(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -664,7 +662,7 @@ const char* Message::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in // optional bytes signature = 4; case 4: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_signature(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_signature(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -674,7 +672,7 @@ const char* Message::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in ::PROTOBUF_NAMESPACE_ID::uint64 val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint(&ptr); CHK_(ptr); if (PROTOBUF_PREDICT_TRUE(::p2p::Message_Messagetype_IsValid(val))) { - set_type(static_cast<::p2p::Message_Messagetype>(val)); + _internal_set_type(static_cast<::p2p::Message_Messagetype>(val)); } else { ::PROTOBUF_NAMESPACE_ID::internal::WriteVarint(5, val, mutable_unknown_fields()); } @@ -683,7 +681,7 @@ const char* Message::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::in // optional bytes content = 6; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 50)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_content(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_content(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -707,173 +705,9 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool Message::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.Message) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional string version = 1; - case 1: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (10 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadString( - input, this->mutable_version())); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->version().data(), static_cast(this->version().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.Message.version"); - } else { - goto handle_unusual; - } - break; - } - - // optional bytes publicKey = 2; - case 2: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (18 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_publickey())); - } else { - goto handle_unusual; - } - break; - } - - // optional int32 timestamp = 3; - case 3: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (24 & 0xFF)) { - _Internal::set_has_timestamp(&_has_bits_); - DO_((::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadPrimitive< - ::PROTOBUF_NAMESPACE_ID::int32, ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_INT32>( - input, ×tamp_))); - } else { - goto handle_unusual; - } - break; - } - - // optional bytes signature = 4; - case 4: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (34 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_signature())); - } else { - goto handle_unusual; - } - break; - } - - // optional .p2p.Message.Messagetype type = 5; - case 5: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (40 & 0xFF)) { - int value = 0; - DO_((::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadPrimitive< - int, ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_ENUM>( - input, &value))); - if (::p2p::Message_Messagetype_IsValid(value)) { - set_type(static_cast< ::p2p::Message_Messagetype >(value)); - } else { - mutable_unknown_fields()->AddVarint( - 5, static_cast<::PROTOBUF_NAMESPACE_ID::uint64>(value)); - } - } else { - goto handle_unusual; - } - break; - } - - // optional bytes content = 6; - case 6: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (50 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_content())); - } else { - goto handle_unusual; - } - break; - } - - default: { - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:p2p.Message) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.Message) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void Message::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.Message) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - cached_has_bits = _has_bits_[0]; - // optional string version = 1; - if (cached_has_bits & 0x00000001u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->version().data(), static_cast(this->version().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.Message.version"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteStringMaybeAliased( - 1, this->version(), output); - } - - // optional bytes publicKey = 2; - if (cached_has_bits & 0x00000002u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 2, this->publickey(), output); - } - - // optional int32 timestamp = 3; - if (cached_has_bits & 0x00000010u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32(3, this->timestamp(), output); - } - - // optional bytes signature = 4; - if (cached_has_bits & 0x00000004u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 4, this->signature(), output); - } - - // optional .p2p.Message.Messagetype type = 5; - if (cached_has_bits & 0x00000020u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteEnum( - 5, this->type(), output); - } - - // optional bytes content = 6; - if (cached_has_bits & 0x00000008u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 6, this->content(), output); - } - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.Message) -} ::PROTOBUF_NAMESPACE_ID::uint8* Message::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.Message) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -882,49 +716,47 @@ void Message::SerializeWithCachedSizes( // optional string version = 1; if (cached_has_bits & 0x00000001u) { ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->version().data(), static_cast(this->version().length()), + this->_internal_version().data(), static_cast(this->_internal_version().length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, "p2p.Message.version"); - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteStringToArray( - 1, this->version(), target); + target = stream->WriteStringMaybeAliased( + 1, this->_internal_version(), target); } // optional bytes publicKey = 2; if (cached_has_bits & 0x00000002u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 2, this->publickey(), target); + target = stream->WriteBytesMaybeAliased( + 2, this->_internal_publickey(), target); } // optional int32 timestamp = 3; if (cached_has_bits & 0x00000010u) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(3, this->timestamp(), target); + stream->EnsureSpace(&target); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(3, this->_internal_timestamp(), target); } // optional bytes signature = 4; if (cached_has_bits & 0x00000004u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 4, this->signature(), target); + target = stream->WriteBytesMaybeAliased( + 4, this->_internal_signature(), target); } // optional .p2p.Message.Messagetype type = 5; if (cached_has_bits & 0x00000020u) { + stream->EnsureSpace(&target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteEnumToArray( - 5, this->type(), target); + 5, this->_internal_type(), target); } // optional bytes content = 6; if (cached_has_bits & 0x00000008u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 6, this->content(), target); + target = stream->WriteBytesMaybeAliased( + 6, this->_internal_content(), target); } - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.Message) return target; @@ -934,11 +766,6 @@ size_t Message::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.Message) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -949,44 +776,48 @@ size_t Message::ByteSizeLong() const { if (cached_has_bits & 0x00000001u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->version()); + this->_internal_version()); } // optional bytes publicKey = 2; if (cached_has_bits & 0x00000002u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->publickey()); + this->_internal_publickey()); } // optional bytes signature = 4; if (cached_has_bits & 0x00000004u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->signature()); + this->_internal_signature()); } // optional bytes content = 6; if (cached_has_bits & 0x00000008u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->content()); + this->_internal_content()); } // optional int32 timestamp = 3; if (cached_has_bits & 0x00000010u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size( - this->timestamp()); + this->_internal_timestamp()); } // optional .p2p.Message.Messagetype type = 5; if (cached_has_bits & 0x00000020u) { total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::EnumSize(this->type()); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::EnumSize(this->_internal_type()); } } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -1191,7 +1022,6 @@ void StateDifference::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* StateDifference::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { @@ -1208,7 +1038,7 @@ const char* StateDifference::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC ptr = ctx->ParseMessage(&created_, ptr); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 10); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); } else goto handle_unusual; continue; // map updated = 2; @@ -1220,7 +1050,7 @@ const char* StateDifference::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC ptr = ctx->ParseMessage(&updated_, ptr); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 18); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); } else goto handle_unusual; continue; // map deleted = 3; @@ -1232,7 +1062,7 @@ const char* StateDifference::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPAC ptr = ctx->ParseMessage(&deleted_, ptr); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 26); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); } else goto handle_unusual; continue; default: { @@ -1254,272 +1084,15 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool StateDifference::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.StateDifference) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // map created = 1; - case 1: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (10 & 0xFF)) { - StateDifference_CreatedEntry_DoNotUse::Parser< ::PROTOBUF_NAMESPACE_ID::internal::MapField< - StateDifference_CreatedEntry_DoNotUse, - std::string, std::string, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - 0 >, - ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string > > parser(&created_); - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadMessageNoVirtual( - input, &parser)); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.key().data(), static_cast(parser.key().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.StateDifference.CreatedEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.value().data(), static_cast(parser.value().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.StateDifference.CreatedEntry.value"); - } else { - goto handle_unusual; - } - break; - } - - // map updated = 2; - case 2: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (18 & 0xFF)) { - StateDifference_UpdatedEntry_DoNotUse::Parser< ::PROTOBUF_NAMESPACE_ID::internal::MapField< - StateDifference_UpdatedEntry_DoNotUse, - std::string, std::string, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - 0 >, - ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string > > parser(&updated_); - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadMessageNoVirtual( - input, &parser)); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.key().data(), static_cast(parser.key().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.StateDifference.UpdatedEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.value().data(), static_cast(parser.value().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.StateDifference.UpdatedEntry.value"); - } else { - goto handle_unusual; - } - break; - } - - // map deleted = 3; - case 3: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (26 & 0xFF)) { - StateDifference_DeletedEntry_DoNotUse::Parser< ::PROTOBUF_NAMESPACE_ID::internal::MapField< - StateDifference_DeletedEntry_DoNotUse, - std::string, std::string, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - 0 >, - ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string > > parser(&deleted_); - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadMessageNoVirtual( - input, &parser)); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.key().data(), static_cast(parser.key().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.StateDifference.DeletedEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.value().data(), static_cast(parser.value().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.StateDifference.DeletedEntry.value"); - } else { - goto handle_unusual; - } - break; - } - - default: { - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:p2p.StateDifference) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.StateDifference) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void StateDifference::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.StateDifference) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // map created = 1; - if (!this->created().empty()) { - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer - ConstPtr; - typedef ConstPtr SortItem; - typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst Less; - struct Utf8Check { - static void Check(ConstPtr p) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->first.data(), static_cast(p->first.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.StateDifference.CreatedEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->second.data(), static_cast(p->second.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.StateDifference.CreatedEntry.value"); - } - }; - - if (output->IsSerializationDeterministic() && - this->created().size() > 1) { - ::std::unique_ptr items( - new SortItem[this->created().size()]); - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; - size_type n = 0; - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->created().begin(); - it != this->created().end(); ++it, ++n) { - items[static_cast(n)] = SortItem(&*it); - } - ::std::sort(&items[0], &items[static_cast(n)], Less()); - for (size_type i = 0; i < n; i++) { - StateDifference_CreatedEntry_DoNotUse::Funcs::SerializeToCodedStream(1, items[static_cast(i)]->first, items[static_cast(i)]->second, output); - Utf8Check::Check(&(*items[static_cast(i)])); - } - } else { - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->created().begin(); - it != this->created().end(); ++it) { - StateDifference_CreatedEntry_DoNotUse::Funcs::SerializeToCodedStream(1, it->first, it->second, output); - Utf8Check::Check(&(*it)); - } - } - } - - // map updated = 2; - if (!this->updated().empty()) { - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer - ConstPtr; - typedef ConstPtr SortItem; - typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst Less; - struct Utf8Check { - static void Check(ConstPtr p) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->first.data(), static_cast(p->first.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.StateDifference.UpdatedEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->second.data(), static_cast(p->second.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.StateDifference.UpdatedEntry.value"); - } - }; - - if (output->IsSerializationDeterministic() && - this->updated().size() > 1) { - ::std::unique_ptr items( - new SortItem[this->updated().size()]); - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; - size_type n = 0; - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->updated().begin(); - it != this->updated().end(); ++it, ++n) { - items[static_cast(n)] = SortItem(&*it); - } - ::std::sort(&items[0], &items[static_cast(n)], Less()); - for (size_type i = 0; i < n; i++) { - StateDifference_UpdatedEntry_DoNotUse::Funcs::SerializeToCodedStream(2, items[static_cast(i)]->first, items[static_cast(i)]->second, output); - Utf8Check::Check(&(*items[static_cast(i)])); - } - } else { - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->updated().begin(); - it != this->updated().end(); ++it) { - StateDifference_UpdatedEntry_DoNotUse::Funcs::SerializeToCodedStream(2, it->first, it->second, output); - Utf8Check::Check(&(*it)); - } - } - } - - // map deleted = 3; - if (!this->deleted().empty()) { - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer - ConstPtr; - typedef ConstPtr SortItem; - typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst Less; - struct Utf8Check { - static void Check(ConstPtr p) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->first.data(), static_cast(p->first.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.StateDifference.DeletedEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->second.data(), static_cast(p->second.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.StateDifference.DeletedEntry.value"); - } - }; - - if (output->IsSerializationDeterministic() && - this->deleted().size() > 1) { - ::std::unique_ptr items( - new SortItem[this->deleted().size()]); - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; - size_type n = 0; - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->deleted().begin(); - it != this->deleted().end(); ++it, ++n) { - items[static_cast(n)] = SortItem(&*it); - } - ::std::sort(&items[0], &items[static_cast(n)], Less()); - for (size_type i = 0; i < n; i++) { - StateDifference_DeletedEntry_DoNotUse::Funcs::SerializeToCodedStream(3, items[static_cast(i)]->first, items[static_cast(i)]->second, output); - Utf8Check::Check(&(*items[static_cast(i)])); - } - } else { - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->deleted().begin(); - it != this->deleted().end(); ++it) { - StateDifference_DeletedEntry_DoNotUse::Funcs::SerializeToCodedStream(3, it->first, it->second, output); - Utf8Check::Check(&(*it)); - } - } - } - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.StateDifference) -} ::PROTOBUF_NAMESPACE_ID::uint8* StateDifference::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.StateDifference) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; // map created = 1; - if (!this->created().empty()) { + if (!this->_internal_created().empty()) { typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer ConstPtr; typedef ConstPtr SortItem; @@ -1537,34 +1110,34 @@ void StateDifference::SerializeWithCachedSizes( } }; - if (false && - this->created().size() > 1) { + if (stream->IsSerializationDeterministic() && + this->_internal_created().size() > 1) { ::std::unique_ptr items( - new SortItem[this->created().size()]); + new SortItem[this->_internal_created().size()]); typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; size_type n = 0; for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->created().begin(); - it != this->created().end(); ++it, ++n) { + it = this->_internal_created().begin(); + it != this->_internal_created().end(); ++it, ++n) { items[static_cast(n)] = SortItem(&*it); } ::std::sort(&items[0], &items[static_cast(n)], Less()); for (size_type i = 0; i < n; i++) { - target = StateDifference_CreatedEntry_DoNotUse::Funcs::SerializeToArray(1, items[static_cast(i)]->first, items[static_cast(i)]->second, target); + target = StateDifference_CreatedEntry_DoNotUse::Funcs::InternalSerialize(1, items[static_cast(i)]->first, items[static_cast(i)]->second, target, stream); Utf8Check::Check(&(*items[static_cast(i)])); } } else { for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->created().begin(); - it != this->created().end(); ++it) { - target = StateDifference_CreatedEntry_DoNotUse::Funcs::SerializeToArray(1, it->first, it->second, target); + it = this->_internal_created().begin(); + it != this->_internal_created().end(); ++it) { + target = StateDifference_CreatedEntry_DoNotUse::Funcs::InternalSerialize(1, it->first, it->second, target, stream); Utf8Check::Check(&(*it)); } } } // map updated = 2; - if (!this->updated().empty()) { + if (!this->_internal_updated().empty()) { typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer ConstPtr; typedef ConstPtr SortItem; @@ -1582,34 +1155,34 @@ void StateDifference::SerializeWithCachedSizes( } }; - if (false && - this->updated().size() > 1) { + if (stream->IsSerializationDeterministic() && + this->_internal_updated().size() > 1) { ::std::unique_ptr items( - new SortItem[this->updated().size()]); + new SortItem[this->_internal_updated().size()]); typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; size_type n = 0; for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->updated().begin(); - it != this->updated().end(); ++it, ++n) { + it = this->_internal_updated().begin(); + it != this->_internal_updated().end(); ++it, ++n) { items[static_cast(n)] = SortItem(&*it); } ::std::sort(&items[0], &items[static_cast(n)], Less()); for (size_type i = 0; i < n; i++) { - target = StateDifference_UpdatedEntry_DoNotUse::Funcs::SerializeToArray(2, items[static_cast(i)]->first, items[static_cast(i)]->second, target); + target = StateDifference_UpdatedEntry_DoNotUse::Funcs::InternalSerialize(2, items[static_cast(i)]->first, items[static_cast(i)]->second, target, stream); Utf8Check::Check(&(*items[static_cast(i)])); } } else { for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->updated().begin(); - it != this->updated().end(); ++it) { - target = StateDifference_UpdatedEntry_DoNotUse::Funcs::SerializeToArray(2, it->first, it->second, target); + it = this->_internal_updated().begin(); + it != this->_internal_updated().end(); ++it) { + target = StateDifference_UpdatedEntry_DoNotUse::Funcs::InternalSerialize(2, it->first, it->second, target, stream); Utf8Check::Check(&(*it)); } } } // map deleted = 3; - if (!this->deleted().empty()) { + if (!this->_internal_deleted().empty()) { typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer ConstPtr; typedef ConstPtr SortItem; @@ -1627,35 +1200,35 @@ void StateDifference::SerializeWithCachedSizes( } }; - if (false && - this->deleted().size() > 1) { + if (stream->IsSerializationDeterministic() && + this->_internal_deleted().size() > 1) { ::std::unique_ptr items( - new SortItem[this->deleted().size()]); + new SortItem[this->_internal_deleted().size()]); typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; size_type n = 0; for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->deleted().begin(); - it != this->deleted().end(); ++it, ++n) { + it = this->_internal_deleted().begin(); + it != this->_internal_deleted().end(); ++it, ++n) { items[static_cast(n)] = SortItem(&*it); } ::std::sort(&items[0], &items[static_cast(n)], Less()); for (size_type i = 0; i < n; i++) { - target = StateDifference_DeletedEntry_DoNotUse::Funcs::SerializeToArray(3, items[static_cast(i)]->first, items[static_cast(i)]->second, target); + target = StateDifference_DeletedEntry_DoNotUse::Funcs::InternalSerialize(3, items[static_cast(i)]->first, items[static_cast(i)]->second, target, stream); Utf8Check::Check(&(*items[static_cast(i)])); } } else { for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->deleted().begin(); - it != this->deleted().end(); ++it) { - target = StateDifference_DeletedEntry_DoNotUse::Funcs::SerializeToArray(3, it->first, it->second, target); + it = this->_internal_deleted().begin(); + it != this->_internal_deleted().end(); ++it) { + target = StateDifference_DeletedEntry_DoNotUse::Funcs::InternalSerialize(3, it->first, it->second, target, stream); Utf8Check::Check(&(*it)); } } } - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.StateDifference) return target; @@ -1665,42 +1238,41 @@ size_t StateDifference::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.StateDifference) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; // map created = 1; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->created_size()); + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_created_size()); for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->created().begin(); - it != this->created().end(); ++it) { + it = this->_internal_created().begin(); + it != this->_internal_created().end(); ++it) { total_size += StateDifference_CreatedEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second); } // map updated = 2; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->updated_size()); + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_updated_size()); for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->updated().begin(); - it != this->updated().end(); ++it) { + it = this->_internal_updated().begin(); + it != this->_internal_updated().end(); ++it) { total_size += StateDifference_UpdatedEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second); } // map deleted = 3; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->deleted_size()); + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_deleted_size()); for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->deleted().begin(); - it != this->deleted().end(); ++it) { + it = this->_internal_deleted().begin(); + it != this->_internal_deleted().end(); ++it) { total_size += StateDifference_DeletedEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second); } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -1819,14 +1391,14 @@ State::State(const State& from) _internal_metadata_.MergeFrom(from._internal_metadata_); patch_.MergeFrom(from.patch_); previous_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_previous()) { + if (from._internal_has_previous()) { previous_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.previous_); } current_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_current()) { + if (from._internal_has_current()) { current_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.current_); } - if (from.has_difference()) { + if (from._internal_has_difference()) { difference_ = new ::p2p::StateDifference(*from.difference_); } else { difference_ = nullptr; @@ -1885,7 +1457,6 @@ void State::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* State::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; @@ -1897,21 +1468,21 @@ const char* State::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte // optional bytes previous = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_previous(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_previous(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; // optional bytes current = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_current(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_current(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; // optional .p2p.StateDifference difference = 3; case 3: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - ptr = ctx->ParseMessage(mutable_difference(), ptr); + ptr = ctx->ParseMessage(_internal_mutable_difference(), ptr); CHK_(ptr); } else goto handle_unusual; continue; @@ -1924,7 +1495,7 @@ const char* State::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::inte ptr = ctx->ParseMessage(&patch_, ptr); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 34); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<34>(ptr)); } else goto handle_unusual; continue; default: { @@ -1947,176 +1518,9 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool State::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.State) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional bytes previous = 1; - case 1: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (10 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_previous())); - } else { - goto handle_unusual; - } - break; - } - - // optional bytes current = 2; - case 2: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (18 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_current())); - } else { - goto handle_unusual; - } - break; - } - - // optional .p2p.StateDifference difference = 3; - case 3: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (26 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadMessage( - input, mutable_difference())); - } else { - goto handle_unusual; - } - break; - } - - // map patch = 4; - case 4: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (34 & 0xFF)) { - State_PatchEntry_DoNotUse::Parser< ::PROTOBUF_NAMESPACE_ID::internal::MapField< - State_PatchEntry_DoNotUse, - std::string, std::string, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_STRING, - 0 >, - ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string > > parser(&patch_); - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadMessageNoVirtual( - input, &parser)); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.key().data(), static_cast(parser.key().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.State.PatchEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - parser.value().data(), static_cast(parser.value().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.State.PatchEntry.value"); - } else { - goto handle_unusual; - } - break; - } - - default: { - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:p2p.State) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.State) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void State::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.State) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - cached_has_bits = _has_bits_[0]; - // optional bytes previous = 1; - if (cached_has_bits & 0x00000001u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 1, this->previous(), output); - } - - // optional bytes current = 2; - if (cached_has_bits & 0x00000002u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 2, this->current(), output); - } - - // optional .p2p.StateDifference difference = 3; - if (cached_has_bits & 0x00000004u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteMessageMaybeToArray( - 3, _Internal::difference(this), output); - } - - // map patch = 4; - if (!this->patch().empty()) { - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer - ConstPtr; - typedef ConstPtr SortItem; - typedef ::PROTOBUF_NAMESPACE_ID::internal::CompareByDerefFirst Less; - struct Utf8Check { - static void Check(ConstPtr p) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->first.data(), static_cast(p->first.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.State.PatchEntry.key"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - p->second.data(), static_cast(p->second.length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.State.PatchEntry.value"); - } - }; - - if (output->IsSerializationDeterministic() && - this->patch().size() > 1) { - ::std::unique_ptr items( - new SortItem[this->patch().size()]); - typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; - size_type n = 0; - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->patch().begin(); - it != this->patch().end(); ++it, ++n) { - items[static_cast(n)] = SortItem(&*it); - } - ::std::sort(&items[0], &items[static_cast(n)], Less()); - for (size_type i = 0; i < n; i++) { - State_PatchEntry_DoNotUse::Funcs::SerializeToCodedStream(4, items[static_cast(i)]->first, items[static_cast(i)]->second, output); - Utf8Check::Check(&(*items[static_cast(i)])); - } - } else { - for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->patch().begin(); - it != this->patch().end(); ++it) { - State_PatchEntry_DoNotUse::Funcs::SerializeToCodedStream(4, it->first, it->second, output); - Utf8Check::Check(&(*it)); - } - } - } - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.State) -} ::PROTOBUF_NAMESPACE_ID::uint8* State::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.State) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -2124,27 +1528,26 @@ void State::SerializeWithCachedSizes( cached_has_bits = _has_bits_[0]; // optional bytes previous = 1; if (cached_has_bits & 0x00000001u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 1, this->previous(), target); + target = stream->WriteBytesMaybeAliased( + 1, this->_internal_previous(), target); } // optional bytes current = 2; if (cached_has_bits & 0x00000002u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 2, this->current(), target); + target = stream->WriteBytesMaybeAliased( + 2, this->_internal_current(), target); } // optional .p2p.StateDifference difference = 3; if (cached_has_bits & 0x00000004u) { + stream->EnsureSpace(&target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessageToArray( - 3, _Internal::difference(this), target); + 3, _Internal::difference(this), target, stream); } // map patch = 4; - if (!this->patch().empty()) { + if (!this->_internal_patch().empty()) { typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_pointer ConstPtr; typedef ConstPtr SortItem; @@ -2162,35 +1565,35 @@ void State::SerializeWithCachedSizes( } }; - if (false && - this->patch().size() > 1) { + if (stream->IsSerializationDeterministic() && + this->_internal_patch().size() > 1) { ::std::unique_ptr items( - new SortItem[this->patch().size()]); + new SortItem[this->_internal_patch().size()]); typedef ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::size_type size_type; size_type n = 0; for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->patch().begin(); - it != this->patch().end(); ++it, ++n) { + it = this->_internal_patch().begin(); + it != this->_internal_patch().end(); ++it, ++n) { items[static_cast(n)] = SortItem(&*it); } ::std::sort(&items[0], &items[static_cast(n)], Less()); for (size_type i = 0; i < n; i++) { - target = State_PatchEntry_DoNotUse::Funcs::SerializeToArray(4, items[static_cast(i)]->first, items[static_cast(i)]->second, target); + target = State_PatchEntry_DoNotUse::Funcs::InternalSerialize(4, items[static_cast(i)]->first, items[static_cast(i)]->second, target, stream); Utf8Check::Check(&(*items[static_cast(i)])); } } else { for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->patch().begin(); - it != this->patch().end(); ++it) { - target = State_PatchEntry_DoNotUse::Funcs::SerializeToArray(4, it->first, it->second, target); + it = this->_internal_patch().begin(); + it != this->_internal_patch().end(); ++it) { + target = State_PatchEntry_DoNotUse::Funcs::InternalSerialize(4, it->first, it->second, target, stream); Utf8Check::Check(&(*it)); } } } - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.State) return target; @@ -2200,21 +1603,16 @@ size_t State::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.State) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; // map patch = 4; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->patch_size()); + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->_internal_patch_size()); for (::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >::const_iterator - it = this->patch().begin(); - it != this->patch().end(); ++it) { + it = this->_internal_patch().begin(); + it != this->_internal_patch().end(); ++it) { total_size += State_PatchEntry_DoNotUse::Funcs::ByteSizeLong(it->first, it->second); } @@ -2224,14 +1622,14 @@ size_t State::ByteSizeLong() const { if (cached_has_bits & 0x00000001u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->previous()); + this->_internal_previous()); } // optional bytes current = 2; if (cached_has_bits & 0x00000002u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->current()); + this->_internal_current()); } // optional .p2p.StateDifference difference = 3; @@ -2242,6 +1640,10 @@ size_t State::ByteSizeLong() const { } } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -2281,7 +1683,7 @@ void State::MergeFrom(const State& from) { current_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.current_); } if (cached_has_bits & 0x00000004u) { - mutable_difference()->::p2p::StateDifference::MergeFrom(from.difference()); + _internal_mutable_difference()->::p2p::StateDifference::MergeFrom(from._internal_difference()); } } } @@ -2363,10 +1765,10 @@ Proposal::Proposal(const Proposal& from) outputs_(from.outputs_) { _internal_metadata_.MergeFrom(from._internal_metadata_); lcl_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_lcl()) { + if (from._internal_has_lcl()) { lcl_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.lcl_); } - if (from.has_state()) { + if (from._internal_has_state()) { state_ = new ::p2p::State(*from.state_); } else { state_ = nullptr; @@ -2432,7 +1834,6 @@ void Proposal::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* Proposal::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; @@ -2447,10 +1848,10 @@ const char* Proposal::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(add_connections(), ptr, ctx, "p2p.Proposal.connections"); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_connections(), ptr, ctx, "p2p.Proposal.connections"); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 10); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); } else goto handle_unusual; continue; // repeated string inputs = 2; @@ -2459,10 +1860,10 @@ const char* Proposal::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(add_inputs(), ptr, ctx, "p2p.Proposal.inputs"); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_inputs(), ptr, ctx, "p2p.Proposal.inputs"); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 18); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); } else goto handle_unusual; continue; // repeated string outputs = 3; @@ -2471,10 +1872,10 @@ const char* Proposal::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i ptr -= 1; do { ptr += 1; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(add_outputs(), ptr, ctx, "p2p.Proposal.outputs"); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParserUTF8Verify(_internal_add_outputs(), ptr, ctx, "p2p.Proposal.outputs"); CHK_(ptr); if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad<::PROTOBUF_NAMESPACE_ID::uint8>(ptr) == 26); + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); } else goto handle_unusual; continue; // optional int32 stage = 4; @@ -2496,14 +1897,14 @@ const char* Proposal::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::i // optional .p2p.State state = 6; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 50)) { - ptr = ctx->ParseMessage(mutable_state(), ptr); + ptr = ctx->ParseMessage(_internal_mutable_state(), ptr); CHK_(ptr); } else goto handle_unusual; continue; // optional bytes lcl = 7; case 7: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 58)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_lcl(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_lcl(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -2527,264 +1928,73 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool Proposal::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.Proposal) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // repeated string connections = 1; - case 1: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (10 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadString( - input, this->add_connections())); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->connections(this->connections_size() - 1).data(), - static_cast(this->connections(this->connections_size() - 1).length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.Proposal.connections"); - } else { - goto handle_unusual; - } - break; - } - - // repeated string inputs = 2; - case 2: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (18 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadString( - input, this->add_inputs())); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->inputs(this->inputs_size() - 1).data(), - static_cast(this->inputs(this->inputs_size() - 1).length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.Proposal.inputs"); - } else { - goto handle_unusual; - } - break; - } - - // repeated string outputs = 3; - case 3: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (26 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadString( - input, this->add_outputs())); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->outputs(this->outputs_size() - 1).data(), - static_cast(this->outputs(this->outputs_size() - 1).length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::PARSE, - "p2p.Proposal.outputs"); - } else { - goto handle_unusual; - } - break; - } - - // optional int32 stage = 4; - case 4: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (32 & 0xFF)) { - _Internal::set_has_stage(&_has_bits_); - DO_((::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadPrimitive< - ::PROTOBUF_NAMESPACE_ID::int32, ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_INT32>( - input, &stage_))); - } else { - goto handle_unusual; - } - break; - } - - // optional int32 time = 5; - case 5: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (40 & 0xFF)) { - _Internal::set_has_time(&_has_bits_); - DO_((::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadPrimitive< - ::PROTOBUF_NAMESPACE_ID::int32, ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::TYPE_INT32>( - input, &time_))); - } else { - goto handle_unusual; - } - break; - } - - // optional .p2p.State state = 6; - case 6: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (50 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadMessage( - input, mutable_state())); - } else { - goto handle_unusual; - } - break; - } - - // optional bytes lcl = 7; - case 7: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (58 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_lcl())); - } else { - goto handle_unusual; - } - break; - } - - default: { - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:p2p.Proposal) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.Proposal) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void Proposal::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.Proposal) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // repeated string connections = 1; - for (int i = 0, n = this->connections_size(); i < n; i++) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->connections(i).data(), static_cast(this->connections(i).length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.Proposal.connections"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteString( - 1, this->connections(i), output); - } - - // repeated string inputs = 2; - for (int i = 0, n = this->inputs_size(); i < n; i++) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->inputs(i).data(), static_cast(this->inputs(i).length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.Proposal.inputs"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteString( - 2, this->inputs(i), output); - } - - // repeated string outputs = 3; - for (int i = 0, n = this->outputs_size(); i < n; i++) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->outputs(i).data(), static_cast(this->outputs(i).length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, - "p2p.Proposal.outputs"); - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteString( - 3, this->outputs(i), output); - } - - cached_has_bits = _has_bits_[0]; - // optional int32 stage = 4; - if (cached_has_bits & 0x00000004u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32(4, this->stage(), output); - } - - // optional int32 time = 5; - if (cached_has_bits & 0x00000008u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32(5, this->time(), output); - } - - // optional .p2p.State state = 6; - if (cached_has_bits & 0x00000002u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteMessageMaybeToArray( - 6, _Internal::state(this), output); - } - - // optional bytes lcl = 7; - if (cached_has_bits & 0x00000001u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 7, this->lcl(), output); - } - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.Proposal) -} ::PROTOBUF_NAMESPACE_ID::uint8* Proposal::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.Proposal) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; // repeated string connections = 1; - for (int i = 0, n = this->connections_size(); i < n; i++) { + for (int i = 0, n = this->_internal_connections_size(); i < n; i++) { + const auto& s = this->_internal_connections(i); ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->connections(i).data(), static_cast(this->connections(i).length()), + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, "p2p.Proposal.connections"); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - WriteStringToArray(1, this->connections(i), target); + target = stream->WriteString(1, s, target); } // repeated string inputs = 2; - for (int i = 0, n = this->inputs_size(); i < n; i++) { + for (int i = 0, n = this->_internal_inputs_size(); i < n; i++) { + const auto& s = this->_internal_inputs(i); ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->inputs(i).data(), static_cast(this->inputs(i).length()), + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, "p2p.Proposal.inputs"); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - WriteStringToArray(2, this->inputs(i), target); + target = stream->WriteString(2, s, target); } // repeated string outputs = 3; - for (int i = 0, n = this->outputs_size(); i < n; i++) { + for (int i = 0, n = this->_internal_outputs_size(); i < n; i++) { + const auto& s = this->_internal_outputs(i); ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( - this->outputs(i).data(), static_cast(this->outputs(i).length()), + s.data(), static_cast(s.length()), ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, "p2p.Proposal.outputs"); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - WriteStringToArray(3, this->outputs(i), target); + target = stream->WriteString(3, s, target); } cached_has_bits = _has_bits_[0]; // optional int32 stage = 4; if (cached_has_bits & 0x00000004u) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(4, this->stage(), target); + stream->EnsureSpace(&target); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(4, this->_internal_stage(), target); } // optional int32 time = 5; if (cached_has_bits & 0x00000008u) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(5, this->time(), target); + stream->EnsureSpace(&target); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteInt32ToArray(5, this->_internal_time(), target); } // optional .p2p.State state = 6; if (cached_has_bits & 0x00000002u) { + stream->EnsureSpace(&target); target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: InternalWriteMessageToArray( - 6, _Internal::state(this), target); + 6, _Internal::state(this), target, stream); } // optional bytes lcl = 7; if (cached_has_bits & 0x00000001u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 7, this->lcl(), target); + target = stream->WriteBytesMaybeAliased( + 7, this->_internal_lcl(), target); } - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.Proposal) return target; @@ -2794,37 +2004,32 @@ size_t Proposal::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.Proposal) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; // repeated string connections = 1; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->connections_size()); - for (int i = 0, n = this->connections_size(); i < n; i++) { + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(connections_.size()); + for (int i = 0, n = connections_.size(); i < n; i++) { total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->connections(i)); + connections_.Get(i)); } // repeated string inputs = 2; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->inputs_size()); - for (int i = 0, n = this->inputs_size(); i < n; i++) { + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(inputs_.size()); + for (int i = 0, n = inputs_.size(); i < n; i++) { total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->inputs(i)); + inputs_.Get(i)); } // repeated string outputs = 3; total_size += 1 * - ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(this->outputs_size()); - for (int i = 0, n = this->outputs_size(); i < n; i++) { + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(outputs_.size()); + for (int i = 0, n = outputs_.size(); i < n; i++) { total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->outputs(i)); + outputs_.Get(i)); } cached_has_bits = _has_bits_[0]; @@ -2833,7 +2038,7 @@ size_t Proposal::ByteSizeLong() const { if (cached_has_bits & 0x00000001u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->lcl()); + this->_internal_lcl()); } // optional .p2p.State state = 6; @@ -2847,17 +2052,21 @@ size_t Proposal::ByteSizeLong() const { if (cached_has_bits & 0x00000004u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size( - this->stage()); + this->_internal_stage()); } // optional int32 time = 5; if (cached_has_bits & 0x00000008u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size( - this->time()); + this->_internal_time()); } } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -2895,7 +2104,7 @@ void Proposal::MergeFrom(const Proposal& from) { lcl_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.lcl_); } if (cached_has_bits & 0x00000002u) { - mutable_state()->::p2p::State::MergeFrom(from.state()); + _internal_mutable_state()->::p2p::State::MergeFrom(from._internal_state()); } if (cached_has_bits & 0x00000004u) { stage_ = from.stage_; @@ -2929,9 +2138,9 @@ void Proposal::InternalSwap(Proposal* other) { using std::swap; _internal_metadata_.Swap(&other->_internal_metadata_); swap(_has_bits_[0], other->_has_bits_[0]); - connections_.InternalSwap(CastToBase(&other->connections_)); - inputs_.InternalSwap(CastToBase(&other->inputs_)); - outputs_.InternalSwap(CastToBase(&other->outputs_)); + connections_.InternalSwap(&other->connections_); + inputs_.InternalSwap(&other->inputs_); + outputs_.InternalSwap(&other->outputs_); lcl_.Swap(&other->lcl_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); swap(state_, other->state_); @@ -2970,11 +2179,11 @@ NPL::NPL(const NPL& from) _has_bits_(from._has_bits_) { _internal_metadata_.MergeFrom(from._internal_metadata_); data_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_data()) { + if (from._internal_has_data()) { data_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.data_); } lcl_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (from.has_lcl()) { + if (from._internal_has_lcl()) { lcl_.AssignWithDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from.lcl_); } // @@protoc_insertion_point(copy_constructor:p2p.NPL) @@ -3024,7 +2233,6 @@ void NPL::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* NPL::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure _Internal::HasBits has_bits{}; @@ -3036,14 +2244,14 @@ const char* NPL::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::intern // optional bytes data = 1; case 1: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_data(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_data(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; // optional bytes lcl = 2; case 2: if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(mutable_lcl(), ptr, ctx); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(_internal_mutable_lcl(), ptr, ctx); CHK_(ptr); } else goto handle_unusual; continue; @@ -3067,88 +2275,9 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool NPL::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.NPL) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - switch (::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::GetTagFieldNumber(tag)) { - // optional bytes data = 1; - case 1: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (10 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_data())); - } else { - goto handle_unusual; - } - break; - } - - // optional bytes lcl = 2; - case 2: { - if (static_cast< ::PROTOBUF_NAMESPACE_ID::uint8>(tag) == (18 & 0xFF)) { - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::ReadBytes( - input, this->mutable_lcl())); - } else { - goto handle_unusual; - } - break; - } - - default: { - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - break; - } - } - } -success: - // @@protoc_insertion_point(parse_success:p2p.NPL) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.NPL) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void NPL::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.NPL) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - cached_has_bits = _has_bits_[0]; - // optional bytes data = 1; - if (cached_has_bits & 0x00000001u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 1, this->data(), output); - } - - // optional bytes lcl = 2; - if (cached_has_bits & 0x00000002u) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesMaybeAliased( - 2, this->lcl(), output); - } - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.NPL) -} ::PROTOBUF_NAMESPACE_ID::uint8* NPL::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.NPL) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; @@ -3156,21 +2285,19 @@ void NPL::SerializeWithCachedSizes( cached_has_bits = _has_bits_[0]; // optional bytes data = 1; if (cached_has_bits & 0x00000001u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 1, this->data(), target); + target = stream->WriteBytesMaybeAliased( + 1, this->_internal_data(), target); } // optional bytes lcl = 2; if (cached_has_bits & 0x00000002u) { - target = - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBytesToArray( - 2, this->lcl(), target); + target = stream->WriteBytesMaybeAliased( + 2, this->_internal_lcl(), target); } - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.NPL) return target; @@ -3180,11 +2307,6 @@ size_t NPL::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.NPL) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; @@ -3195,17 +2317,21 @@ size_t NPL::ByteSizeLong() const { if (cached_has_bits & 0x00000001u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->data()); + this->_internal_data()); } // optional bytes lcl = 2; if (cached_has_bits & 0x00000002u) { total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::BytesSize( - this->lcl()); + this->_internal_lcl()); } } + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -3331,7 +2457,6 @@ void StateRequest::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* StateRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { @@ -3357,55 +2482,16 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool StateRequest::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.StateRequest) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - } -success: - // @@protoc_insertion_point(parse_success:p2p.StateRequest) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.StateRequest) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void StateRequest::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.StateRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.StateRequest) -} ::PROTOBUF_NAMESPACE_ID::uint8* StateRequest::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.StateRequest) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.StateRequest) return target; @@ -3415,15 +2501,14 @@ size_t StateRequest::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.StateRequest) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -3534,7 +2619,6 @@ void StateResponse::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* StateResponse::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { @@ -3560,55 +2644,16 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool StateResponse::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.StateResponse) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - } -success: - // @@protoc_insertion_point(parse_success:p2p.StateResponse) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.StateResponse) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void StateResponse::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.StateResponse) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.StateResponse) -} ::PROTOBUF_NAMESPACE_ID::uint8* StateResponse::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.StateResponse) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.StateResponse) return target; @@ -3618,15 +2663,14 @@ size_t StateResponse::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.StateResponse) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -3737,7 +2781,6 @@ void HistoryRequest::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* HistoryRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { @@ -3763,55 +2806,16 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool HistoryRequest::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.HistoryRequest) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - } -success: - // @@protoc_insertion_point(parse_success:p2p.HistoryRequest) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.HistoryRequest) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void HistoryRequest::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.HistoryRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.HistoryRequest) -} ::PROTOBUF_NAMESPACE_ID::uint8* HistoryRequest::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.HistoryRequest) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.HistoryRequest) return target; @@ -3821,15 +2825,14 @@ size_t HistoryRequest::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.HistoryRequest) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; @@ -3940,7 +2943,6 @@ void HistoryResponse::Clear() { _internal_metadata_.Clear(); } -#if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* HistoryResponse::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { #define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure while (!ctx->Done(&ptr)) { @@ -3966,55 +2968,16 @@ failure: goto success; #undef CHK_ } -#else // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER -bool HistoryResponse::MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) { -#define DO_(EXPRESSION) if (!PROTOBUF_PREDICT_TRUE(EXPRESSION)) goto failure - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - // @@protoc_insertion_point(parse_start:p2p.HistoryResponse) - for (;;) { - ::std::pair<::PROTOBUF_NAMESPACE_ID::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u); - tag = p.first; - if (!p.second) goto handle_unusual; - handle_unusual: - if (tag == 0) { - goto success; - } - DO_(::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SkipField( - input, tag, _internal_metadata_.mutable_unknown_fields())); - } -success: - // @@protoc_insertion_point(parse_success:p2p.HistoryResponse) - return true; -failure: - // @@protoc_insertion_point(parse_failure:p2p.HistoryResponse) - return false; -#undef DO_ -} -#endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - -void HistoryResponse::SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const { - // @@protoc_insertion_point(serialize_start:p2p.HistoryResponse) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (_internal_metadata_.have_unknown_fields()) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFields( - _internal_metadata_.unknown_fields(), output); - } - // @@protoc_insertion_point(serialize_end:p2p.HistoryResponse) -} ::PROTOBUF_NAMESPACE_ID::uint8* HistoryResponse::InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const { + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { // @@protoc_insertion_point(serialize_to_array_start:p2p.HistoryResponse) ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; (void) cached_has_bits; - if (_internal_metadata_.have_unknown_fields()) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields(), target); + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target, stream); } // @@protoc_insertion_point(serialize_to_array_end:p2p.HistoryResponse) return target; @@ -4024,15 +2987,14 @@ size_t HistoryResponse::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:p2p.HistoryResponse) size_t total_size = 0; - if (_internal_metadata_.have_unknown_fields()) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::ComputeUnknownFieldsSize( - _internal_metadata_.unknown_fields()); - } ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); SetCachedSize(cached_size); return total_size; diff --git a/src/p2p/message.pb.h b/src/p2p/message.pb.h index 26b1afc8..517da12d 100644 --- a/src/p2p/message.pb.h +++ b/src/p2p/message.pb.h @@ -8,12 +8,12 @@ #include #include -#if PROTOBUF_VERSION < 3009000 +#if PROTOBUF_VERSION < 3010000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif -#if 3009002 < PROTOBUF_MIN_PROTOC_VERSION +#if 3010000 < PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. @@ -221,16 +221,9 @@ class Message : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -312,6 +305,9 @@ class Message : }; // optional string version = 1; bool has_version() const; + private: + bool _internal_has_version() const; + public: void clear_version(); const std::string& version() const; void set_version(const std::string& value); @@ -321,9 +317,17 @@ class Message : std::string* mutable_version(); std::string* release_version(); void set_allocated_version(std::string* version); + private: + const std::string& _internal_version() const; + void _internal_set_version(const std::string& value); + std::string* _internal_mutable_version(); + public: // optional bytes publicKey = 2; bool has_publickey() const; + private: + bool _internal_has_publickey() const; + public: void clear_publickey(); const std::string& publickey() const; void set_publickey(const std::string& value); @@ -333,9 +337,17 @@ class Message : std::string* mutable_publickey(); std::string* release_publickey(); void set_allocated_publickey(std::string* publickey); + private: + const std::string& _internal_publickey() const; + void _internal_set_publickey(const std::string& value); + std::string* _internal_mutable_publickey(); + public: // optional bytes signature = 4; bool has_signature() const; + private: + bool _internal_has_signature() const; + public: void clear_signature(); const std::string& signature() const; void set_signature(const std::string& value); @@ -345,9 +357,17 @@ class Message : std::string* mutable_signature(); std::string* release_signature(); void set_allocated_signature(std::string* signature); + private: + const std::string& _internal_signature() const; + void _internal_set_signature(const std::string& value); + std::string* _internal_mutable_signature(); + public: // optional bytes content = 6; bool has_content() const; + private: + bool _internal_has_content() const; + public: void clear_content(); const std::string& content() const; void set_content(const std::string& value); @@ -357,18 +377,37 @@ class Message : std::string* mutable_content(); std::string* release_content(); void set_allocated_content(std::string* content); + private: + const std::string& _internal_content() const; + void _internal_set_content(const std::string& value); + std::string* _internal_mutable_content(); + public: // optional int32 timestamp = 3; bool has_timestamp() const; + private: + bool _internal_has_timestamp() const; + public: void clear_timestamp(); ::PROTOBUF_NAMESPACE_ID::int32 timestamp() const; void set_timestamp(::PROTOBUF_NAMESPACE_ID::int32 value); + private: + ::PROTOBUF_NAMESPACE_ID::int32 _internal_timestamp() const; + void _internal_set_timestamp(::PROTOBUF_NAMESPACE_ID::int32 value); + public: // optional .p2p.Message.Messagetype type = 5; bool has_type() const; + private: + bool _internal_has_type() const; + public: void clear_type(); ::p2p::Message_Messagetype type() const; void set_type(::p2p::Message_Messagetype value); + private: + ::p2p::Message_Messagetype _internal_type() const; + void _internal_set_type(::p2p::Message_Messagetype value); + public: // @@protoc_insertion_point(class_scope:p2p.Message) private: @@ -589,16 +628,9 @@ class StateDifference : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -640,7 +672,16 @@ class StateDifference : }; // map created = 1; int created_size() const; + private: + int _internal_created_size() const; + public: void clear_created(); + private: + const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& + _internal_created() const; + ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* + _internal_mutable_created(); + public: const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& created() const; ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* @@ -648,7 +689,16 @@ class StateDifference : // map updated = 2; int updated_size() const; + private: + int _internal_updated_size() const; + public: void clear_updated(); + private: + const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& + _internal_updated() const; + ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* + _internal_mutable_updated(); + public: const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& updated() const; ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* @@ -656,7 +706,16 @@ class StateDifference : // map deleted = 3; int deleted_size() const; + private: + int _internal_deleted_size() const; + public: void clear_deleted(); + private: + const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& + _internal_deleted() const; + ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* + _internal_mutable_deleted(); + public: const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& deleted() const; ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* @@ -809,16 +868,9 @@ class State : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -861,7 +913,16 @@ class State : }; // map patch = 4; int patch_size() const; + private: + int _internal_patch_size() const; + public: void clear_patch(); + private: + const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& + _internal_patch() const; + ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* + _internal_mutable_patch(); + public: const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& patch() const; ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* @@ -869,6 +930,9 @@ class State : // optional bytes previous = 1; bool has_previous() const; + private: + bool _internal_has_previous() const; + public: void clear_previous(); const std::string& previous() const; void set_previous(const std::string& value); @@ -878,9 +942,17 @@ class State : std::string* mutable_previous(); std::string* release_previous(); void set_allocated_previous(std::string* previous); + private: + const std::string& _internal_previous() const; + void _internal_set_previous(const std::string& value); + std::string* _internal_mutable_previous(); + public: // optional bytes current = 2; bool has_current() const; + private: + bool _internal_has_current() const; + public: void clear_current(); const std::string& current() const; void set_current(const std::string& value); @@ -890,14 +962,26 @@ class State : std::string* mutable_current(); std::string* release_current(); void set_allocated_current(std::string* current); + private: + const std::string& _internal_current() const; + void _internal_set_current(const std::string& value); + std::string* _internal_mutable_current(); + public: // optional .p2p.StateDifference difference = 3; bool has_difference() const; + private: + bool _internal_has_difference() const; + public: void clear_difference(); const ::p2p::StateDifference& difference() const; ::p2p::StateDifference* release_difference(); ::p2p::StateDifference* mutable_difference(); void set_allocated_difference(::p2p::StateDifference* difference); + private: + const ::p2p::StateDifference& _internal_difference() const; + ::p2p::StateDifference* _internal_mutable_difference(); + public: // @@protoc_insertion_point(class_scope:p2p.State) private: @@ -995,16 +1079,9 @@ class Proposal : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1049,6 +1126,9 @@ class Proposal : }; // repeated string connections = 1; int connections_size() const; + private: + int _internal_connections_size() const; + public: void clear_connections(); const std::string& connections(int index) const; std::string* mutable_connections(int index); @@ -1063,9 +1143,16 @@ class Proposal : void add_connections(const char* value, size_t size); const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& connections() const; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_connections(); + private: + const std::string& _internal_connections(int index) const; + std::string* _internal_add_connections(); + public: // repeated string inputs = 2; int inputs_size() const; + private: + int _internal_inputs_size() const; + public: void clear_inputs(); const std::string& inputs(int index) const; std::string* mutable_inputs(int index); @@ -1080,9 +1167,16 @@ class Proposal : void add_inputs(const char* value, size_t size); const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& inputs() const; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_inputs(); + private: + const std::string& _internal_inputs(int index) const; + std::string* _internal_add_inputs(); + public: // repeated string outputs = 3; int outputs_size() const; + private: + int _internal_outputs_size() const; + public: void clear_outputs(); const std::string& outputs(int index) const; std::string* mutable_outputs(int index); @@ -1097,9 +1191,16 @@ class Proposal : void add_outputs(const char* value, size_t size); const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& outputs() const; ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_outputs(); + private: + const std::string& _internal_outputs(int index) const; + std::string* _internal_add_outputs(); + public: // optional bytes lcl = 7; bool has_lcl() const; + private: + bool _internal_has_lcl() const; + public: void clear_lcl(); const std::string& lcl() const; void set_lcl(const std::string& value); @@ -1109,26 +1210,52 @@ class Proposal : std::string* mutable_lcl(); std::string* release_lcl(); void set_allocated_lcl(std::string* lcl); + private: + const std::string& _internal_lcl() const; + void _internal_set_lcl(const std::string& value); + std::string* _internal_mutable_lcl(); + public: // optional .p2p.State state = 6; bool has_state() const; + private: + bool _internal_has_state() const; + public: void clear_state(); const ::p2p::State& state() const; ::p2p::State* release_state(); ::p2p::State* mutable_state(); void set_allocated_state(::p2p::State* state); + private: + const ::p2p::State& _internal_state() const; + ::p2p::State* _internal_mutable_state(); + public: // optional int32 stage = 4; bool has_stage() const; + private: + bool _internal_has_stage() const; + public: void clear_stage(); ::PROTOBUF_NAMESPACE_ID::int32 stage() const; void set_stage(::PROTOBUF_NAMESPACE_ID::int32 value); + private: + ::PROTOBUF_NAMESPACE_ID::int32 _internal_stage() const; + void _internal_set_stage(::PROTOBUF_NAMESPACE_ID::int32 value); + public: // optional int32 time = 5; bool has_time() const; + private: + bool _internal_has_time() const; + public: void clear_time(); ::PROTOBUF_NAMESPACE_ID::int32 time() const; void set_time(::PROTOBUF_NAMESPACE_ID::int32 value); + private: + ::PROTOBUF_NAMESPACE_ID::int32 _internal_time() const; + void _internal_set_time(::PROTOBUF_NAMESPACE_ID::int32 value); + public: // @@protoc_insertion_point(class_scope:p2p.Proposal) private: @@ -1224,16 +1351,9 @@ class NPL : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1273,6 +1393,9 @@ class NPL : }; // optional bytes data = 1; bool has_data() const; + private: + bool _internal_has_data() const; + public: void clear_data(); const std::string& data() const; void set_data(const std::string& value); @@ -1282,9 +1405,17 @@ class NPL : std::string* mutable_data(); std::string* release_data(); void set_allocated_data(std::string* data); + private: + const std::string& _internal_data() const; + void _internal_set_data(const std::string& value); + std::string* _internal_mutable_data(); + public: // optional bytes lcl = 2; bool has_lcl() const; + private: + bool _internal_has_lcl() const; + public: void clear_lcl(); const std::string& lcl() const; void set_lcl(const std::string& value); @@ -1294,6 +1425,11 @@ class NPL : std::string* mutable_lcl(); std::string* release_lcl(); void set_allocated_lcl(std::string* lcl); + private: + const std::string& _internal_lcl() const; + void _internal_set_lcl(const std::string& value); + std::string* _internal_mutable_lcl(); + public: // @@protoc_insertion_point(class_scope:p2p.NPL) private: @@ -1384,16 +1520,9 @@ class StateRequest : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1514,16 +1643,9 @@ class StateResponse : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1644,16 +1766,9 @@ class HistoryRequest : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1774,16 +1889,9 @@ class HistoryResponse : bool IsInitialized() const final; size_t ByteSizeLong() const final; - #if GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - #else - bool MergePartialFromCodedStream( - ::PROTOBUF_NAMESPACE_ID::io::CodedInputStream* input) final; - #endif // GOOGLE_PROTOBUF_ENABLE_EXPERIMENTAL_PARSER - void SerializeWithCachedSizes( - ::PROTOBUF_NAMESPACE_ID::io::CodedOutputStream* output) const final; ::PROTOBUF_NAMESPACE_ID::uint8* InternalSerializeWithCachedSizesToArray( - ::PROTOBUF_NAMESPACE_ID::uint8* target) const final; + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; int GetCachedSize() const final { return _cached_size_.Get(); } private: @@ -1838,8 +1946,12 @@ class HistoryResponse : // Message // optional string version = 1; +inline bool Message::_internal_has_version() const { + bool value = (_has_bits_[0] & 0x00000001u) != 0; + return value; +} inline bool Message::has_version() const { - return (_has_bits_[0] & 0x00000001u) != 0; + return _internal_has_version(); } inline void Message::clear_version() { version_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -1847,12 +1959,22 @@ inline void Message::clear_version() { } inline const std::string& Message::version() const { // @@protoc_insertion_point(field_get:p2p.Message.version) - return version_.GetNoArena(); + return _internal_version(); } inline void Message::set_version(const std::string& value) { + _internal_set_version(value); + // @@protoc_insertion_point(field_set:p2p.Message.version) +} +inline std::string* Message::mutable_version() { + // @@protoc_insertion_point(field_mutable:p2p.Message.version) + return _internal_mutable_version(); +} +inline const std::string& Message::_internal_version() const { + return version_.GetNoArena(); +} +inline void Message::_internal_set_version(const std::string& value) { _has_bits_[0] |= 0x00000001u; version_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.Message.version) } inline void Message::set_version(std::string&& value) { _has_bits_[0] |= 0x00000001u; @@ -1872,9 +1994,8 @@ inline void Message::set_version(const char* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.Message.version) } -inline std::string* Message::mutable_version() { +inline std::string* Message::_internal_mutable_version() { _has_bits_[0] |= 0x00000001u; - // @@protoc_insertion_point(field_mutable:p2p.Message.version) return version_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* Message::release_version() { @@ -1896,8 +2017,12 @@ inline void Message::set_allocated_version(std::string* version) { } // optional bytes publicKey = 2; +inline bool Message::_internal_has_publickey() const { + bool value = (_has_bits_[0] & 0x00000002u) != 0; + return value; +} inline bool Message::has_publickey() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return _internal_has_publickey(); } inline void Message::clear_publickey() { publickey_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -1905,12 +2030,22 @@ inline void Message::clear_publickey() { } inline const std::string& Message::publickey() const { // @@protoc_insertion_point(field_get:p2p.Message.publicKey) - return publickey_.GetNoArena(); + return _internal_publickey(); } inline void Message::set_publickey(const std::string& value) { + _internal_set_publickey(value); + // @@protoc_insertion_point(field_set:p2p.Message.publicKey) +} +inline std::string* Message::mutable_publickey() { + // @@protoc_insertion_point(field_mutable:p2p.Message.publicKey) + return _internal_mutable_publickey(); +} +inline const std::string& Message::_internal_publickey() const { + return publickey_.GetNoArena(); +} +inline void Message::_internal_set_publickey(const std::string& value) { _has_bits_[0] |= 0x00000002u; publickey_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.Message.publicKey) } inline void Message::set_publickey(std::string&& value) { _has_bits_[0] |= 0x00000002u; @@ -1930,9 +2065,8 @@ inline void Message::set_publickey(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.Message.publicKey) } -inline std::string* Message::mutable_publickey() { +inline std::string* Message::_internal_mutable_publickey() { _has_bits_[0] |= 0x00000002u; - // @@protoc_insertion_point(field_mutable:p2p.Message.publicKey) return publickey_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* Message::release_publickey() { @@ -1954,26 +2088,40 @@ inline void Message::set_allocated_publickey(std::string* publickey) { } // optional int32 timestamp = 3; +inline bool Message::_internal_has_timestamp() const { + bool value = (_has_bits_[0] & 0x00000010u) != 0; + return value; +} inline bool Message::has_timestamp() const { - return (_has_bits_[0] & 0x00000010u) != 0; + return _internal_has_timestamp(); } inline void Message::clear_timestamp() { timestamp_ = 0; _has_bits_[0] &= ~0x00000010u; } -inline ::PROTOBUF_NAMESPACE_ID::int32 Message::timestamp() const { - // @@protoc_insertion_point(field_get:p2p.Message.timestamp) +inline ::PROTOBUF_NAMESPACE_ID::int32 Message::_internal_timestamp() const { return timestamp_; } -inline void Message::set_timestamp(::PROTOBUF_NAMESPACE_ID::int32 value) { +inline ::PROTOBUF_NAMESPACE_ID::int32 Message::timestamp() const { + // @@protoc_insertion_point(field_get:p2p.Message.timestamp) + return _internal_timestamp(); +} +inline void Message::_internal_set_timestamp(::PROTOBUF_NAMESPACE_ID::int32 value) { _has_bits_[0] |= 0x00000010u; timestamp_ = value; +} +inline void Message::set_timestamp(::PROTOBUF_NAMESPACE_ID::int32 value) { + _internal_set_timestamp(value); // @@protoc_insertion_point(field_set:p2p.Message.timestamp) } // optional bytes signature = 4; +inline bool Message::_internal_has_signature() const { + bool value = (_has_bits_[0] & 0x00000004u) != 0; + return value; +} inline bool Message::has_signature() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return _internal_has_signature(); } inline void Message::clear_signature() { signature_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -1981,12 +2129,22 @@ inline void Message::clear_signature() { } inline const std::string& Message::signature() const { // @@protoc_insertion_point(field_get:p2p.Message.signature) - return signature_.GetNoArena(); + return _internal_signature(); } inline void Message::set_signature(const std::string& value) { + _internal_set_signature(value); + // @@protoc_insertion_point(field_set:p2p.Message.signature) +} +inline std::string* Message::mutable_signature() { + // @@protoc_insertion_point(field_mutable:p2p.Message.signature) + return _internal_mutable_signature(); +} +inline const std::string& Message::_internal_signature() const { + return signature_.GetNoArena(); +} +inline void Message::_internal_set_signature(const std::string& value) { _has_bits_[0] |= 0x00000004u; signature_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.Message.signature) } inline void Message::set_signature(std::string&& value) { _has_bits_[0] |= 0x00000004u; @@ -2006,9 +2164,8 @@ inline void Message::set_signature(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.Message.signature) } -inline std::string* Message::mutable_signature() { +inline std::string* Message::_internal_mutable_signature() { _has_bits_[0] |= 0x00000004u; - // @@protoc_insertion_point(field_mutable:p2p.Message.signature) return signature_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* Message::release_signature() { @@ -2030,27 +2187,41 @@ inline void Message::set_allocated_signature(std::string* signature) { } // optional .p2p.Message.Messagetype type = 5; +inline bool Message::_internal_has_type() const { + bool value = (_has_bits_[0] & 0x00000020u) != 0; + return value; +} inline bool Message::has_type() const { - return (_has_bits_[0] & 0x00000020u) != 0; + return _internal_has_type(); } inline void Message::clear_type() { type_ = 0; _has_bits_[0] &= ~0x00000020u; } -inline ::p2p::Message_Messagetype Message::type() const { - // @@protoc_insertion_point(field_get:p2p.Message.type) +inline ::p2p::Message_Messagetype Message::_internal_type() const { return static_cast< ::p2p::Message_Messagetype >(type_); } -inline void Message::set_type(::p2p::Message_Messagetype value) { +inline ::p2p::Message_Messagetype Message::type() const { + // @@protoc_insertion_point(field_get:p2p.Message.type) + return _internal_type(); +} +inline void Message::_internal_set_type(::p2p::Message_Messagetype value) { assert(::p2p::Message_Messagetype_IsValid(value)); _has_bits_[0] |= 0x00000020u; type_ = value; +} +inline void Message::set_type(::p2p::Message_Messagetype value) { + _internal_set_type(value); // @@protoc_insertion_point(field_set:p2p.Message.type) } // optional bytes content = 6; +inline bool Message::_internal_has_content() const { + bool value = (_has_bits_[0] & 0x00000008u) != 0; + return value; +} inline bool Message::has_content() const { - return (_has_bits_[0] & 0x00000008u) != 0; + return _internal_has_content(); } inline void Message::clear_content() { content_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -2058,12 +2229,22 @@ inline void Message::clear_content() { } inline const std::string& Message::content() const { // @@protoc_insertion_point(field_get:p2p.Message.content) - return content_.GetNoArena(); + return _internal_content(); } inline void Message::set_content(const std::string& value) { + _internal_set_content(value); + // @@protoc_insertion_point(field_set:p2p.Message.content) +} +inline std::string* Message::mutable_content() { + // @@protoc_insertion_point(field_mutable:p2p.Message.content) + return _internal_mutable_content(); +} +inline const std::string& Message::_internal_content() const { + return content_.GetNoArena(); +} +inline void Message::_internal_set_content(const std::string& value) { _has_bits_[0] |= 0x00000008u; content_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.Message.content) } inline void Message::set_content(std::string&& value) { _has_bits_[0] |= 0x00000008u; @@ -2083,9 +2264,8 @@ inline void Message::set_content(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.Message.content) } -inline std::string* Message::mutable_content() { +inline std::string* Message::_internal_mutable_content() { _has_bits_[0] |= 0x00000008u; - // @@protoc_insertion_point(field_mutable:p2p.Message.content) return content_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* Message::release_content() { @@ -2117,57 +2297,90 @@ inline void Message::set_allocated_content(std::string* content) { // StateDifference // map created = 1; -inline int StateDifference::created_size() const { +inline int StateDifference::_internal_created_size() const { return created_.size(); } +inline int StateDifference::created_size() const { + return _internal_created_size(); +} inline void StateDifference::clear_created() { created_.Clear(); } inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& +StateDifference::_internal_created() const { + return created_.GetMap(); +} +inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& StateDifference::created() const { // @@protoc_insertion_point(field_map:p2p.StateDifference.created) - return created_.GetMap(); + return _internal_created(); +} +inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* +StateDifference::_internal_mutable_created() { + return created_.MutableMap(); } inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* StateDifference::mutable_created() { // @@protoc_insertion_point(field_mutable_map:p2p.StateDifference.created) - return created_.MutableMap(); + return _internal_mutable_created(); } // map updated = 2; -inline int StateDifference::updated_size() const { +inline int StateDifference::_internal_updated_size() const { return updated_.size(); } +inline int StateDifference::updated_size() const { + return _internal_updated_size(); +} inline void StateDifference::clear_updated() { updated_.Clear(); } inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& +StateDifference::_internal_updated() const { + return updated_.GetMap(); +} +inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& StateDifference::updated() const { // @@protoc_insertion_point(field_map:p2p.StateDifference.updated) - return updated_.GetMap(); + return _internal_updated(); +} +inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* +StateDifference::_internal_mutable_updated() { + return updated_.MutableMap(); } inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* StateDifference::mutable_updated() { // @@protoc_insertion_point(field_mutable_map:p2p.StateDifference.updated) - return updated_.MutableMap(); + return _internal_mutable_updated(); } // map deleted = 3; -inline int StateDifference::deleted_size() const { +inline int StateDifference::_internal_deleted_size() const { return deleted_.size(); } +inline int StateDifference::deleted_size() const { + return _internal_deleted_size(); +} inline void StateDifference::clear_deleted() { deleted_.Clear(); } inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& +StateDifference::_internal_deleted() const { + return deleted_.GetMap(); +} +inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& StateDifference::deleted() const { // @@protoc_insertion_point(field_map:p2p.StateDifference.deleted) - return deleted_.GetMap(); + return _internal_deleted(); +} +inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* +StateDifference::_internal_mutable_deleted() { + return deleted_.MutableMap(); } inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* StateDifference::mutable_deleted() { // @@protoc_insertion_point(field_mutable_map:p2p.StateDifference.deleted) - return deleted_.MutableMap(); + return _internal_mutable_deleted(); } // ------------------------------------------------------------------- @@ -2177,8 +2390,12 @@ StateDifference::mutable_deleted() { // State // optional bytes previous = 1; +inline bool State::_internal_has_previous() const { + bool value = (_has_bits_[0] & 0x00000001u) != 0; + return value; +} inline bool State::has_previous() const { - return (_has_bits_[0] & 0x00000001u) != 0; + return _internal_has_previous(); } inline void State::clear_previous() { previous_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -2186,12 +2403,22 @@ inline void State::clear_previous() { } inline const std::string& State::previous() const { // @@protoc_insertion_point(field_get:p2p.State.previous) - return previous_.GetNoArena(); + return _internal_previous(); } inline void State::set_previous(const std::string& value) { + _internal_set_previous(value); + // @@protoc_insertion_point(field_set:p2p.State.previous) +} +inline std::string* State::mutable_previous() { + // @@protoc_insertion_point(field_mutable:p2p.State.previous) + return _internal_mutable_previous(); +} +inline const std::string& State::_internal_previous() const { + return previous_.GetNoArena(); +} +inline void State::_internal_set_previous(const std::string& value) { _has_bits_[0] |= 0x00000001u; previous_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.State.previous) } inline void State::set_previous(std::string&& value) { _has_bits_[0] |= 0x00000001u; @@ -2211,9 +2438,8 @@ inline void State::set_previous(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.State.previous) } -inline std::string* State::mutable_previous() { +inline std::string* State::_internal_mutable_previous() { _has_bits_[0] |= 0x00000001u; - // @@protoc_insertion_point(field_mutable:p2p.State.previous) return previous_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* State::release_previous() { @@ -2235,8 +2461,12 @@ inline void State::set_allocated_previous(std::string* previous) { } // optional bytes current = 2; +inline bool State::_internal_has_current() const { + bool value = (_has_bits_[0] & 0x00000002u) != 0; + return value; +} inline bool State::has_current() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return _internal_has_current(); } inline void State::clear_current() { current_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -2244,12 +2474,22 @@ inline void State::clear_current() { } inline const std::string& State::current() const { // @@protoc_insertion_point(field_get:p2p.State.current) - return current_.GetNoArena(); + return _internal_current(); } inline void State::set_current(const std::string& value) { + _internal_set_current(value); + // @@protoc_insertion_point(field_set:p2p.State.current) +} +inline std::string* State::mutable_current() { + // @@protoc_insertion_point(field_mutable:p2p.State.current) + return _internal_mutable_current(); +} +inline const std::string& State::_internal_current() const { + return current_.GetNoArena(); +} +inline void State::_internal_set_current(const std::string& value) { _has_bits_[0] |= 0x00000002u; current_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.State.current) } inline void State::set_current(std::string&& value) { _has_bits_[0] |= 0x00000002u; @@ -2269,9 +2509,8 @@ inline void State::set_current(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.State.current) } -inline std::string* State::mutable_current() { +inline std::string* State::_internal_mutable_current() { _has_bits_[0] |= 0x00000002u; - // @@protoc_insertion_point(field_mutable:p2p.State.current) return current_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* State::release_current() { @@ -2293,19 +2532,27 @@ inline void State::set_allocated_current(std::string* current) { } // optional .p2p.StateDifference difference = 3; +inline bool State::_internal_has_difference() const { + bool value = (_has_bits_[0] & 0x00000004u) != 0; + PROTOBUF_ASSUME(!value || difference_ != nullptr); + return value; +} inline bool State::has_difference() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return _internal_has_difference(); } inline void State::clear_difference() { if (difference_ != nullptr) difference_->Clear(); _has_bits_[0] &= ~0x00000004u; } -inline const ::p2p::StateDifference& State::difference() const { +inline const ::p2p::StateDifference& State::_internal_difference() const { const ::p2p::StateDifference* p = difference_; - // @@protoc_insertion_point(field_get:p2p.State.difference) return p != nullptr ? *p : *reinterpret_cast( &::p2p::_StateDifference_default_instance_); } +inline const ::p2p::StateDifference& State::difference() const { + // @@protoc_insertion_point(field_get:p2p.State.difference) + return _internal_difference(); +} inline ::p2p::StateDifference* State::release_difference() { // @@protoc_insertion_point(field_release:p2p.State.difference) _has_bits_[0] &= ~0x00000004u; @@ -2313,15 +2560,18 @@ inline ::p2p::StateDifference* State::release_difference() { difference_ = nullptr; return temp; } -inline ::p2p::StateDifference* State::mutable_difference() { +inline ::p2p::StateDifference* State::_internal_mutable_difference() { _has_bits_[0] |= 0x00000004u; if (difference_ == nullptr) { auto* p = CreateMaybeMessage<::p2p::StateDifference>(GetArenaNoVirtual()); difference_ = p; } - // @@protoc_insertion_point(field_mutable:p2p.State.difference) return difference_; } +inline ::p2p::StateDifference* State::mutable_difference() { + // @@protoc_insertion_point(field_mutable:p2p.State.difference) + return _internal_mutable_difference(); +} inline void State::set_allocated_difference(::p2p::StateDifference* difference) { ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == nullptr) { @@ -2342,21 +2592,32 @@ inline void State::set_allocated_difference(::p2p::StateDifference* difference) } // map patch = 4; -inline int State::patch_size() const { +inline int State::_internal_patch_size() const { return patch_.size(); } +inline int State::patch_size() const { + return _internal_patch_size(); +} inline void State::clear_patch() { patch_.Clear(); } inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& +State::_internal_patch() const { + return patch_.GetMap(); +} +inline const ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >& State::patch() const { // @@protoc_insertion_point(field_map:p2p.State.patch) - return patch_.GetMap(); + return _internal_patch(); +} +inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* +State::_internal_mutable_patch() { + return patch_.MutableMap(); } inline ::PROTOBUF_NAMESPACE_ID::Map< std::string, std::string >* State::mutable_patch() { // @@protoc_insertion_point(field_mutable_map:p2p.State.patch) - return patch_.MutableMap(); + return _internal_mutable_patch(); } // ------------------------------------------------------------------- @@ -2364,15 +2625,25 @@ State::mutable_patch() { // Proposal // repeated string connections = 1; -inline int Proposal::connections_size() const { +inline int Proposal::_internal_connections_size() const { return connections_.size(); } +inline int Proposal::connections_size() const { + return _internal_connections_size(); +} inline void Proposal::clear_connections() { connections_.Clear(); } +inline std::string* Proposal::add_connections() { + // @@protoc_insertion_point(field_add_mutable:p2p.Proposal.connections) + return _internal_add_connections(); +} +inline const std::string& Proposal::_internal_connections(int index) const { + return connections_.Get(index); +} inline const std::string& Proposal::connections(int index) const { // @@protoc_insertion_point(field_get:p2p.Proposal.connections) - return connections_.Get(index); + return _internal_connections(index); } inline std::string* Proposal::mutable_connections(int index) { // @@protoc_insertion_point(field_mutable:p2p.Proposal.connections) @@ -2396,8 +2667,7 @@ inline void Proposal::set_connections(int index, const char* value, size_t size) reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:p2p.Proposal.connections) } -inline std::string* Proposal::add_connections() { - // @@protoc_insertion_point(field_add_mutable:p2p.Proposal.connections) +inline std::string* Proposal::_internal_add_connections() { return connections_.Add(); } inline void Proposal::add_connections(const std::string& value) { @@ -2429,15 +2699,25 @@ Proposal::mutable_connections() { } // repeated string inputs = 2; -inline int Proposal::inputs_size() const { +inline int Proposal::_internal_inputs_size() const { return inputs_.size(); } +inline int Proposal::inputs_size() const { + return _internal_inputs_size(); +} inline void Proposal::clear_inputs() { inputs_.Clear(); } +inline std::string* Proposal::add_inputs() { + // @@protoc_insertion_point(field_add_mutable:p2p.Proposal.inputs) + return _internal_add_inputs(); +} +inline const std::string& Proposal::_internal_inputs(int index) const { + return inputs_.Get(index); +} inline const std::string& Proposal::inputs(int index) const { // @@protoc_insertion_point(field_get:p2p.Proposal.inputs) - return inputs_.Get(index); + return _internal_inputs(index); } inline std::string* Proposal::mutable_inputs(int index) { // @@protoc_insertion_point(field_mutable:p2p.Proposal.inputs) @@ -2461,8 +2741,7 @@ inline void Proposal::set_inputs(int index, const char* value, size_t size) { reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:p2p.Proposal.inputs) } -inline std::string* Proposal::add_inputs() { - // @@protoc_insertion_point(field_add_mutable:p2p.Proposal.inputs) +inline std::string* Proposal::_internal_add_inputs() { return inputs_.Add(); } inline void Proposal::add_inputs(const std::string& value) { @@ -2494,15 +2773,25 @@ Proposal::mutable_inputs() { } // repeated string outputs = 3; -inline int Proposal::outputs_size() const { +inline int Proposal::_internal_outputs_size() const { return outputs_.size(); } +inline int Proposal::outputs_size() const { + return _internal_outputs_size(); +} inline void Proposal::clear_outputs() { outputs_.Clear(); } +inline std::string* Proposal::add_outputs() { + // @@protoc_insertion_point(field_add_mutable:p2p.Proposal.outputs) + return _internal_add_outputs(); +} +inline const std::string& Proposal::_internal_outputs(int index) const { + return outputs_.Get(index); +} inline const std::string& Proposal::outputs(int index) const { // @@protoc_insertion_point(field_get:p2p.Proposal.outputs) - return outputs_.Get(index); + return _internal_outputs(index); } inline std::string* Proposal::mutable_outputs(int index) { // @@protoc_insertion_point(field_mutable:p2p.Proposal.outputs) @@ -2526,8 +2815,7 @@ inline void Proposal::set_outputs(int index, const char* value, size_t size) { reinterpret_cast(value), size); // @@protoc_insertion_point(field_set_pointer:p2p.Proposal.outputs) } -inline std::string* Proposal::add_outputs() { - // @@protoc_insertion_point(field_add_mutable:p2p.Proposal.outputs) +inline std::string* Proposal::_internal_add_outputs() { return outputs_.Add(); } inline void Proposal::add_outputs(const std::string& value) { @@ -2559,55 +2847,83 @@ Proposal::mutable_outputs() { } // optional int32 stage = 4; +inline bool Proposal::_internal_has_stage() const { + bool value = (_has_bits_[0] & 0x00000004u) != 0; + return value; +} inline bool Proposal::has_stage() const { - return (_has_bits_[0] & 0x00000004u) != 0; + return _internal_has_stage(); } inline void Proposal::clear_stage() { stage_ = 0; _has_bits_[0] &= ~0x00000004u; } -inline ::PROTOBUF_NAMESPACE_ID::int32 Proposal::stage() const { - // @@protoc_insertion_point(field_get:p2p.Proposal.stage) +inline ::PROTOBUF_NAMESPACE_ID::int32 Proposal::_internal_stage() const { return stage_; } -inline void Proposal::set_stage(::PROTOBUF_NAMESPACE_ID::int32 value) { +inline ::PROTOBUF_NAMESPACE_ID::int32 Proposal::stage() const { + // @@protoc_insertion_point(field_get:p2p.Proposal.stage) + return _internal_stage(); +} +inline void Proposal::_internal_set_stage(::PROTOBUF_NAMESPACE_ID::int32 value) { _has_bits_[0] |= 0x00000004u; stage_ = value; +} +inline void Proposal::set_stage(::PROTOBUF_NAMESPACE_ID::int32 value) { + _internal_set_stage(value); // @@protoc_insertion_point(field_set:p2p.Proposal.stage) } // optional int32 time = 5; +inline bool Proposal::_internal_has_time() const { + bool value = (_has_bits_[0] & 0x00000008u) != 0; + return value; +} inline bool Proposal::has_time() const { - return (_has_bits_[0] & 0x00000008u) != 0; + return _internal_has_time(); } inline void Proposal::clear_time() { time_ = 0; _has_bits_[0] &= ~0x00000008u; } -inline ::PROTOBUF_NAMESPACE_ID::int32 Proposal::time() const { - // @@protoc_insertion_point(field_get:p2p.Proposal.time) +inline ::PROTOBUF_NAMESPACE_ID::int32 Proposal::_internal_time() const { return time_; } -inline void Proposal::set_time(::PROTOBUF_NAMESPACE_ID::int32 value) { +inline ::PROTOBUF_NAMESPACE_ID::int32 Proposal::time() const { + // @@protoc_insertion_point(field_get:p2p.Proposal.time) + return _internal_time(); +} +inline void Proposal::_internal_set_time(::PROTOBUF_NAMESPACE_ID::int32 value) { _has_bits_[0] |= 0x00000008u; time_ = value; +} +inline void Proposal::set_time(::PROTOBUF_NAMESPACE_ID::int32 value) { + _internal_set_time(value); // @@protoc_insertion_point(field_set:p2p.Proposal.time) } // optional .p2p.State state = 6; +inline bool Proposal::_internal_has_state() const { + bool value = (_has_bits_[0] & 0x00000002u) != 0; + PROTOBUF_ASSUME(!value || state_ != nullptr); + return value; +} inline bool Proposal::has_state() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return _internal_has_state(); } inline void Proposal::clear_state() { if (state_ != nullptr) state_->Clear(); _has_bits_[0] &= ~0x00000002u; } -inline const ::p2p::State& Proposal::state() const { +inline const ::p2p::State& Proposal::_internal_state() const { const ::p2p::State* p = state_; - // @@protoc_insertion_point(field_get:p2p.Proposal.state) return p != nullptr ? *p : *reinterpret_cast( &::p2p::_State_default_instance_); } +inline const ::p2p::State& Proposal::state() const { + // @@protoc_insertion_point(field_get:p2p.Proposal.state) + return _internal_state(); +} inline ::p2p::State* Proposal::release_state() { // @@protoc_insertion_point(field_release:p2p.Proposal.state) _has_bits_[0] &= ~0x00000002u; @@ -2615,15 +2931,18 @@ inline ::p2p::State* Proposal::release_state() { state_ = nullptr; return temp; } -inline ::p2p::State* Proposal::mutable_state() { +inline ::p2p::State* Proposal::_internal_mutable_state() { _has_bits_[0] |= 0x00000002u; if (state_ == nullptr) { auto* p = CreateMaybeMessage<::p2p::State>(GetArenaNoVirtual()); state_ = p; } - // @@protoc_insertion_point(field_mutable:p2p.Proposal.state) return state_; } +inline ::p2p::State* Proposal::mutable_state() { + // @@protoc_insertion_point(field_mutable:p2p.Proposal.state) + return _internal_mutable_state(); +} inline void Proposal::set_allocated_state(::p2p::State* state) { ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == nullptr) { @@ -2644,8 +2963,12 @@ inline void Proposal::set_allocated_state(::p2p::State* state) { } // optional bytes lcl = 7; +inline bool Proposal::_internal_has_lcl() const { + bool value = (_has_bits_[0] & 0x00000001u) != 0; + return value; +} inline bool Proposal::has_lcl() const { - return (_has_bits_[0] & 0x00000001u) != 0; + return _internal_has_lcl(); } inline void Proposal::clear_lcl() { lcl_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -2653,12 +2976,22 @@ inline void Proposal::clear_lcl() { } inline const std::string& Proposal::lcl() const { // @@protoc_insertion_point(field_get:p2p.Proposal.lcl) - return lcl_.GetNoArena(); + return _internal_lcl(); } inline void Proposal::set_lcl(const std::string& value) { + _internal_set_lcl(value); + // @@protoc_insertion_point(field_set:p2p.Proposal.lcl) +} +inline std::string* Proposal::mutable_lcl() { + // @@protoc_insertion_point(field_mutable:p2p.Proposal.lcl) + return _internal_mutable_lcl(); +} +inline const std::string& Proposal::_internal_lcl() const { + return lcl_.GetNoArena(); +} +inline void Proposal::_internal_set_lcl(const std::string& value) { _has_bits_[0] |= 0x00000001u; lcl_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.Proposal.lcl) } inline void Proposal::set_lcl(std::string&& value) { _has_bits_[0] |= 0x00000001u; @@ -2678,9 +3011,8 @@ inline void Proposal::set_lcl(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.Proposal.lcl) } -inline std::string* Proposal::mutable_lcl() { +inline std::string* Proposal::_internal_mutable_lcl() { _has_bits_[0] |= 0x00000001u; - // @@protoc_insertion_point(field_mutable:p2p.Proposal.lcl) return lcl_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* Proposal::release_lcl() { @@ -2706,8 +3038,12 @@ inline void Proposal::set_allocated_lcl(std::string* lcl) { // NPL // optional bytes data = 1; +inline bool NPL::_internal_has_data() const { + bool value = (_has_bits_[0] & 0x00000001u) != 0; + return value; +} inline bool NPL::has_data() const { - return (_has_bits_[0] & 0x00000001u) != 0; + return _internal_has_data(); } inline void NPL::clear_data() { data_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -2715,12 +3051,22 @@ inline void NPL::clear_data() { } inline const std::string& NPL::data() const { // @@protoc_insertion_point(field_get:p2p.NPL.data) - return data_.GetNoArena(); + return _internal_data(); } inline void NPL::set_data(const std::string& value) { + _internal_set_data(value); + // @@protoc_insertion_point(field_set:p2p.NPL.data) +} +inline std::string* NPL::mutable_data() { + // @@protoc_insertion_point(field_mutable:p2p.NPL.data) + return _internal_mutable_data(); +} +inline const std::string& NPL::_internal_data() const { + return data_.GetNoArena(); +} +inline void NPL::_internal_set_data(const std::string& value) { _has_bits_[0] |= 0x00000001u; data_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.NPL.data) } inline void NPL::set_data(std::string&& value) { _has_bits_[0] |= 0x00000001u; @@ -2740,9 +3086,8 @@ inline void NPL::set_data(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.NPL.data) } -inline std::string* NPL::mutable_data() { +inline std::string* NPL::_internal_mutable_data() { _has_bits_[0] |= 0x00000001u; - // @@protoc_insertion_point(field_mutable:p2p.NPL.data) return data_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* NPL::release_data() { @@ -2764,8 +3109,12 @@ inline void NPL::set_allocated_data(std::string* data) { } // optional bytes lcl = 2; +inline bool NPL::_internal_has_lcl() const { + bool value = (_has_bits_[0] & 0x00000002u) != 0; + return value; +} inline bool NPL::has_lcl() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return _internal_has_lcl(); } inline void NPL::clear_lcl() { lcl_.ClearToEmptyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); @@ -2773,12 +3122,22 @@ inline void NPL::clear_lcl() { } inline const std::string& NPL::lcl() const { // @@protoc_insertion_point(field_get:p2p.NPL.lcl) - return lcl_.GetNoArena(); + return _internal_lcl(); } inline void NPL::set_lcl(const std::string& value) { + _internal_set_lcl(value); + // @@protoc_insertion_point(field_set:p2p.NPL.lcl) +} +inline std::string* NPL::mutable_lcl() { + // @@protoc_insertion_point(field_mutable:p2p.NPL.lcl) + return _internal_mutable_lcl(); +} +inline const std::string& NPL::_internal_lcl() const { + return lcl_.GetNoArena(); +} +inline void NPL::_internal_set_lcl(const std::string& value) { _has_bits_[0] |= 0x00000002u; lcl_.SetNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:p2p.NPL.lcl) } inline void NPL::set_lcl(std::string&& value) { _has_bits_[0] |= 0x00000002u; @@ -2798,9 +3157,8 @@ inline void NPL::set_lcl(const void* value, size_t size) { ::std::string(reinterpret_cast(value), size)); // @@protoc_insertion_point(field_set_pointer:p2p.NPL.lcl) } -inline std::string* NPL::mutable_lcl() { +inline std::string* NPL::_internal_mutable_lcl() { _has_bits_[0] |= 0x00000002u; - // @@protoc_insertion_point(field_mutable:p2p.NPL.lcl) return lcl_.MutableNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); } inline std::string* NPL::release_lcl() { diff --git a/src/p2p/p2p.h b/src/p2p/p2p.hpp similarity index 100% rename from src/p2p/p2p.h rename to src/p2p/p2p.hpp diff --git a/src/proc.cpp b/src/proc.cpp index 72daca67..527b419c 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -7,11 +7,11 @@ #include #include #include -#include "proc.h" -#include "conf.h" +#include "proc.hpp" +#include "conf.hpp" using namespace std; -using namespace shared; +using namespace util; namespace proc { @@ -22,7 +22,6 @@ namespace proc int contract_pid; int write_to_stdin(ContractExecArgs &args); -bool is_contract_running(); int exec_contract(ContractExecArgs &args) { @@ -35,19 +34,19 @@ int exec_contract(ContractExecArgs &args) int pid = fork(); if (pid > 0) { - //HotPocket process. + // HotPocket process. contract_pid = pid; } else if (pid == 0) { - //Contract process. - //Set up the process environment and overlay the contract binary program with execv(). + // Contract process. + // Set up the process environment and overlay the contract binary program with execv(). - //Set the contract process working directory. + // Set the contract process working directory. chdir(conf::ctx.contractDir.data()); - //Write the contract input message from HotPocket to the stdin (0) of the contract process. + // Write the contract input message from HotPocket to the stdin (0) of the contract process. write_to_stdin(args); char *execv_args[] = {conf::cfg.binary.data(), conf::cfg.binargs.data(), NULL}; @@ -76,6 +75,8 @@ int exec_contract(ContractExecArgs &args) */ int write_to_stdin(ContractExecArgs &args) { + //Populate the json document with contract args. + Document d; d.SetObject(); Document::AllocatorType &allocator = d.GetAllocator(); @@ -107,13 +108,16 @@ int write_to_stdin(ContractExecArgs &args) Value unl(kArrayType); for (string &node : conf::cfg.unl) unl.PushBack(StringRef(node.data()), allocator); - d.AddMember("unl", unl, allocator); + d.AddMember("unl", unl, allocator); StringBuffer buffer; Writer writer(buffer); d.Accept(writer); + + // Get the json string that should be written to contract input pipe. const char *json = buffer.GetString(); + // Establish contract input pipe. int stdinpipe[2]; if (pipe(stdinpipe) != 0) { @@ -121,9 +125,12 @@ int write_to_stdin(ContractExecArgs &args) return -1; } + // Redirect pipe read-end to the contract std input so the + // contract process can read from our pipe. dup2(stdinpipe[0], STDIN_FILENO); close(stdinpipe[0]); + // Write the json message and close write fd. write(stdinpipe[1], json, buffer.GetSize()); close(stdinpipe[1]); diff --git a/src/proc.h b/src/proc.h deleted file mode 100644 index 5d98aa57..00000000 --- a/src/proc.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _HP_PROC_H_ -#define _HP_PROC_H_ - -#include -#include -#include "shared.h" - -using namespace std; -using namespace shared; - -namespace proc -{ - -struct ContractExecArgs -{ - map &users; - map &peers; - uint64_t timestamp; - - ContractExecArgs(map &_users, map &_peers, uint64_t _timestamp) - : users(_users), peers(_peers) - { - timestamp = _timestamp; - } -}; - -int exec_contract(ContractExecArgs &args); -bool is_contract_running(); - -} // namespace proc - -#endif \ No newline at end of file diff --git a/src/proc.hpp b/src/proc.hpp new file mode 100644 index 00000000..e0f79fe0 --- /dev/null +++ b/src/proc.hpp @@ -0,0 +1,44 @@ +#ifndef _HP_PROC_H_ +#define _HP_PROC_H_ + +#include +#include +#include "util.hpp" + +using namespace std; +using namespace util; + +namespace proc +{ + +/** + * Holds information that should be passed into the contract process. + */ +struct ContractExecArgs +{ + map &users; // Map of authenticated contract users indexed by user pubkey. + map &peers; // Map of connected peers indexed by node pubkey. + uint64_t timestamp; // Current HotPocket timestamp. + + ContractExecArgs(map &_users, map &_peers, uint64_t _timestamp) + : users(_users), peers(_peers) + { + timestamp = _timestamp; + } +}; + +/** + * Executes the contract process and passes the specified arguments. + * + * @return 0 on successful process creation. -1 on failure or contract process is already running. + */ +int exec_contract(ContractExecArgs &args); + +/** + * Checks whether the contract process is running at this moment. + */ +bool is_contract_running(); + +} // namespace proc + +#endif \ No newline at end of file diff --git a/src/shared.h b/src/shared.h deleted file mode 100644 index 39725a3c..00000000 --- a/src/shared.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _HP_SHARED_H_ -#define _HP_SHARED_H_ - -#include -#include - -using namespace std; - -namespace shared -{ - -struct ContractUser -{ - string pubkeyb64; - int inpipe[2]; - int outpipe[2]; - string outbuffer; - - ContractUser(string _pubkeyb64, int _inpipe[2], int _outpipe[2]) - { - pubkeyb64 = _pubkeyb64; - inpipe[0] = _inpipe[0]; - inpipe[1] = _inpipe[1]; - outpipe[0] = _outpipe[0]; - outpipe[1] = _outpipe[1]; - } -}; - -struct PeerNode -{ - string pubkeyb64; - int inpipe[2]; - int outpipe[2]; - - PeerNode(string _pubkeyb64, int _inpipe[2], int _outpipe[2]) - { - pubkeyb64 = _pubkeyb64; - inpipe[0] = _inpipe[0]; - inpipe[1] = _inpipe[1]; - outpipe[0] = _outpipe[0]; - outpipe[1] = _outpipe[1]; - } -}; - -int base64_encode(unsigned char *bin, size_t bin_len, string &encoded_string); -int base64_decode(string &base64_str, unsigned char *decoded, size_t decoded_len); -void replace_string_contents(string &str, const char* bytes, size_t bytes_len); -int version_compare(string &v1, string &v2); - -} // namespace usr - -#endif \ No newline at end of file diff --git a/src/sock/socket_client.cpp b/src/sock/socket_client.cpp index 1ee785da..33cacf30 100644 --- a/src/sock/socket_client.cpp +++ b/src/sock/socket_client.cpp @@ -1,5 +1,5 @@ #include -#include "socket_client.h" +#include "socket_client.hpp" using tcp = net::ip::tcp; using error = boost::system::error_code; diff --git a/src/sock/socket_client.h b/src/sock/socket_client.hpp similarity index 94% rename from src/sock/socket_client.h rename to src/sock/socket_client.hpp index 8c7a544e..f5b9c830 100644 --- a/src/sock/socket_client.h +++ b/src/sock/socket_client.hpp @@ -3,8 +3,8 @@ #include #include -#include "socket_session.h" -#include "socket_session_handler.h" +#include "socket_session.hpp" +#include "socket_session_handler.hpp" namespace beast = boost::beast; namespace net = boost::asio; diff --git a/src/sock/socket_server.cpp b/src/sock/socket_server.cpp index f2296375..ab444df2 100644 --- a/src/sock/socket_server.cpp +++ b/src/sock/socket_server.cpp @@ -4,7 +4,7 @@ #include #include #include -#include "socket_server.h" +#include "socket_server.hpp" namespace net = boost::asio; // namespace asio diff --git a/src/sock/socket_server.h b/src/sock/socket_server.hpp similarity index 95% rename from src/sock/socket_server.h rename to src/sock/socket_server.hpp index 2b51003e..c16770c2 100644 --- a/src/sock/socket_server.h +++ b/src/sock/socket_server.hpp @@ -2,7 +2,7 @@ #define _SOCK_SERVER_LISTENER_H_ #include -#include "socket_session_handler.h" +#include "socket_session_handler.hpp" namespace net = boost::asio; // namespace asio diff --git a/src/sock/socket_session.cpp b/src/sock/socket_session.cpp index 4f78b63b..0af25209 100644 --- a/src/sock/socket_session.cpp +++ b/src/sock/socket_session.cpp @@ -1,7 +1,7 @@ #include #include #include -#include "socket_session.h" +#include "socket_session.hpp" namespace net = boost::asio; diff --git a/src/sock/socket_session.h b/src/sock/socket_session.hpp similarity index 97% rename from src/sock/socket_session.h rename to src/sock/socket_session.hpp index 14d5c217..73500f5a 100644 --- a/src/sock/socket_session.h +++ b/src/sock/socket_session.hpp @@ -5,7 +5,7 @@ #include #include #include -#include "socket_session_handler.h" +#include "socket_session_handler.hpp" namespace beast = boost::beast; namespace net = boost::asio; diff --git a/src/sock/socket_session_handler.h b/src/sock/socket_session_handler.hpp similarity index 94% rename from src/sock/socket_session_handler.h rename to src/sock/socket_session_handler.hpp index dc16cdaa..3f07c7ad 100644 --- a/src/sock/socket_session_handler.h +++ b/src/sock/socket_session_handler.hpp @@ -1,7 +1,7 @@ #ifndef _SOCK_SESSION_HANDLER_H_ #define _SOCK_SESSION_HANDLER_H_ -#include "socket_session.h" +#include "socket_session.hpp" #include using error = boost::system::error_code; diff --git a/src/usr/usr.cpp b/src/usr/usr.cpp index 78dcaadc..84071e19 100644 --- a/src/usr/usr.cpp +++ b/src/usr/usr.cpp @@ -8,34 +8,67 @@ #include #include #include -#include "../shared.h" -#include "../conf.h" -#include "../crypto.h" -#include "usr.h" +#include "../util.hpp" +#include "../conf.hpp" +#include "../crypto.hpp" +#include "usr.hpp" using namespace std; -using namespace shared; +using namespace util; using namespace rapidjson; namespace usr { -map users; +/** + * Global user list. (Exposed to other sub systems) + */ +map users; + +/** + * Json schema doc used for user challenge-response json validation. + */ Document challenge_response_schemadoc; -void create_user_challenge(string &msg, string &challenge) +int init() { + //We initialize the response schema doc from this json string so we can + //use the schema repeatedly for all challenge-response validations. + + const char *challenge_response_schema = + "{" + "\"type\": \"object\"," + "\"required\": [ \"type\", \"challenge\", \"sig\", \"pubkey\" ]," + "\"properties\": {" + "\"type\": { \"type\": \"string\" }," + "\"challenge\": { \"type\": \"string\" }," + "\"sig\": { \"type\": \"string\" }," + "\"pubkey\": { \"type\": \"string\" }" + "}" + "}"; + challenge_response_schemadoc.Parse(challenge_response_schema); + + return 0; +} + +void create_user_challenge(string &msg, string &challengeb64) +{ + //Use libsodium to generate the random challenge bytes. unsigned char challenge_bytes[USER_CHALLENGE_LEN]; randombytes_buf(challenge_bytes, USER_CHALLENGE_LEN); - base64_encode(challenge_bytes, USER_CHALLENGE_LEN, challenge); + //We pass the b64 challenge string separately to the caller even though + //we also include it in the challenge msg as well. + base64_encode(challenge_bytes, USER_CHALLENGE_LEN, challengeb64); + + //Construct the challenge msg json. Document d; d.SetObject(); Document::AllocatorType &allocator = d.GetAllocator(); d.AddMember("version", StringRef(_HP_VERSION_), allocator); - d.AddMember("type", "public_challenge", allocator); - d.AddMember("challenge", StringRef(challenge.data()), allocator); + d.AddMember("type", MSG_PUBLIC_CHALLENGE, allocator); + d.AddMember("challenge", StringRef(challengeb64.data()), allocator); StringBuffer buffer; Writer writer(buffer); @@ -43,86 +76,117 @@ void create_user_challenge(string &msg, string &challenge) msg = buffer.GetString(); } -bool verify_user_challenge_response(string &response, string &original_challenge, string &extracted_pubkeyb64) +int verify_user_challenge_response(const string &response, const string &original_challenge, string &extracted_pubkeyb64) { + //We load response raw bytes into json document and validate the schema. Document d; d.Parse(response.data()); + //Validate json scheme. + //This has a cost. But we have to do this first. Otherwise field value + //extraction will fail in subsequent steps if the message is malformed. SchemaDocument schema(challenge_response_schemadoc); SchemaValidator validator(schema); if (!d.Accept(validator)) { cerr << "User challenge resposne schema invalid.\n"; - return false; + return -1; } + //Validate msg type. string type = d["type"].GetString(); - if (type != "challenge_response") + if (type != MSG_CHALLENGE_RESP) { cerr << "User challenge response type invalid. 'challenge_response' expeced.\n"; - return false; + return -1; } + //Compare the response challenge string with the original issued challenge. string challenge = d["challenge"].GetString(); - string sigb64 = d["sig"].GetString(); - string pubkeyb64 = d["pubkey"].GetString(); - if (challenge != original_challenge) { cerr << "User challenge resposne: challenge mismatch.\n"; - return false; + return -1; } - if (!crypto::verify_b64(original_challenge, sigb64, pubkeyb64)) + //Verify the challenge signature. We do this last due to signature verification cost. + string sigb64 = d["sig"].GetString(); + extracted_pubkeyb64 = d["pubkey"].GetString(); + if (crypto::verify_b64(original_challenge, sigb64, extracted_pubkeyb64) != 0) { cerr << "User challenge response signature verification failed.\n"; - return false; + return -1; } - extracted_pubkeyb64 = pubkeyb64; - return true; + return 0; } -void add_user(string &pubkeyb64) +int add_user(const string &pubkeyb64) { if (users.count(pubkeyb64) == 1) { cerr << pubkeyb64 << " already exist. Cannot add user.\n"; - return; + return -1; } + //Establish the I/O pipes for [User <--> SC] channel. + + //inpipe: User will write input to this and contract will read user-input from this. int inpipe[2]; - int outpipe[2]; - if (pipe(inpipe) != 0 || pipe(outpipe) != 0) + if (pipe(inpipe) != 0) { - cerr << "User pipe creation failed. pubkey:" << pubkeyb64 << endl; - return; + cerr << "User in pipe creation failed. pubkey:" << pubkeyb64 << endl; + return -1; } - users.insert(pair(pubkeyb64, ContractUser(pubkeyb64, inpipe, outpipe))); + //outpipe: Contract will write output for the user to this and user will read from this. + int outpipe[2]; + if (pipe(outpipe) != 0) + { + cerr << "User out pipe creation failed. pubkey:" << pubkeyb64 << endl; + + //We need to close 'inpipe' in case outpipe failed. + close(inpipe[0]); + close(inpipe[1]); + + return -1; + } + + users.insert(pair(pubkeyb64, contract_user(pubkeyb64, inpipe, outpipe))); + return 0; } -void remove_user(string &pubkeyb64) +int remove_user(const string &pubkeyb64) { if (users.count(pubkeyb64) == 0) { cerr << pubkeyb64 << " does not exist. Cannot remove user.\n"; - return; + return -1; } auto itr = users.find(pubkeyb64); - ContractUser user = itr->second; + contract_user user = itr->second; + + //Close the User <--> SC I/O pipes. close(user.inpipe[0]); close(user.inpipe[1]); close(user.outpipe[0]); close(user.outpipe[1]); users.erase(itr); + return 0; } -//Read per-user outputs produced by the contract process. int read_contract_user_outputs() { + //Read any outputs that has been written by the contract process + //from all the user outpipes and store in the outbuffer of each user. + //User outbuffer will be read by the consensus process later when it wishes so. + + //Future optmization: Read and populate user buffers parallely. + //Currently this is sequential for simplicity which will not scale well + //when there are large number of users connected to the same HP node. + for (auto &[pk, user] : users) { int fdout = user.outpipe[0]; @@ -135,7 +199,7 @@ int read_contract_user_outputs() read(fdout, data, bytes_available); //Populate the user output buffer with new data - shared::replace_string_contents(user.outbuffer, data, bytes_available); + util::replace_string_contents(user.outbuffer, data, bytes_available); cout << "Read " + to_string(bytes_available) << " bytes into user output buffer. user:" + user.pubkeyb64 << endl; } @@ -144,23 +208,4 @@ int read_contract_user_outputs() return 0; } -int init() -{ - const char *challenge_response_schema = - "{" - "\"type\": \"object\"," - "\"required\": [ \"type\", \"challenge\", \"sig\", \"pubkey\" ]," - "\"properties\": {" - "\"type\": { \"type\": \"string\" }," - "\"challenge\": { \"type\": \"string\" }," - "\"sig\": { \"type\": \"string\" }," - "\"pubkey\": { \"type\": \"string\" }" - "}" - "}"; - - challenge_response_schemadoc.Parse(challenge_response_schema); - - return 0; -} - } // namespace usr \ No newline at end of file diff --git a/src/usr/usr.h b/src/usr/usr.h deleted file mode 100644 index cdd0e987..00000000 --- a/src/usr/usr.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _HP_USR_H_ -#define _HP_USR_H_ - -#define USER_CHALLENGE_LEN 16 - -#include -#include -#include -#include "../shared.h" - -using namespace std; -using namespace shared; - -namespace usr -{ -extern map users; - -int init(); -void create_user_challenge(string &msg, string &challenge); -bool verify_user_challenge_response(string &response, string &original_challenge, string &extracted_pubkey); -void add_user(string &pubkeyb64); -void remove_user(string &pubkeyb64); - -} // namespace usr - -#endif \ No newline at end of file diff --git a/src/usr/usr.hpp b/src/usr/usr.hpp new file mode 100644 index 00000000..b914fda7 --- /dev/null +++ b/src/usr/usr.hpp @@ -0,0 +1,97 @@ +#ifndef _HP_USR_H_ +#define _HP_USR_H_ + +// Length of user random challenge bytes. +#define USER_CHALLENGE_LEN 16 + +// Message type for the user challenge. +#define MSG_PUBLIC_CHALLENGE "public_challenge" + +// Message type for the user challenge response. +#define MSG_CHALLENGE_RESP "challenge_response" + +#include +#include +#include +#include "../util.hpp" + +using namespace std; +using namespace util; + +/** + * Maintains the global user list with pending input outputs and manages user connections. + */ +namespace usr +{ + +/** + * Global authenticated (challenge-verified) user list. + */ +extern map users; + +/** + * Initializes the usr subsystem. Must be called once during application startup. + * @return 0 for successful initialization. -1 for failure. + */ +int init(); + +/** + * Constructs user challenge message json and the challenge string required for + * initial user challenge handshake. This gets called when a user gets establishes + * a web sockets connection to HP. + * + * @param msg String reference to copy the generated json message string into. + * Message format: + * { + * "version": "", + * "type": "public_challenge", + * "challenge": "" + * } + * @param challenge String reference to copy the generated base64 challenge string into. + */ +void create_user_challenge(string &msg, string &challengeb64); + +/** + * Verifies the user challenge response with the original challenge issued to the user + * and the user public contained in the response. + * + * @param response The response bytes to verify. This will be parsed as json. + * Accepted response format: + * { + * "type": "challenge_response", + * "challenge": "", + * "sig": "", + * "pubkey": "" + * } + * @param original_challenge The original base64 challenge string issued to the user. + * @return 0 if challenge response is verified. -1 if challenge not met or an error occurs. + */ +int verify_user_challenge_response(const string &response, const string &original_challenge, string &extracted_pubkey); + +/** + * Adds the specified public key into the global user list. + * This should get called after the challenge handshake is verified. + * + * @return 0 on successful additions. -1 on failure. + */ +int add_user(const string &pubkeyb64); + +/** + * Removes the specified public key from the global user list. + * This must get called when a user disconnects from HP. + * + * @return 0 on successful removals. -1 on failure. + */ +int remove_user(const string &pubkeyb64); + +/** + * Read all per-user outputs produced by the contract process and store them in + * the user buffer for later processing. + * + * @return 0 on success. -1 on failure. + */ +int read_contract_user_outputs(); + +} // namespace usr + +#endif \ No newline at end of file diff --git a/src/shared.cpp b/src/util.cpp similarity index 76% rename from src/shared.cpp rename to src/util.cpp index f5beba17..c3620741 100644 --- a/src/shared.cpp +++ b/src/util.cpp @@ -3,17 +3,24 @@ using namespace std; -namespace shared +namespace util { -void replace_string_contents(string &str, const char *bytes, size_t bytes_len); - -int base64_encode(unsigned char *bin, size_t bin_len, string &encoded_string) +void replace_string_contents(string &str, const char *bytes, size_t bytes_len) { + if (str.length() > 0) + str.clear(); + str.append(bytes, bytes_len); +} + +int base64_encode(const unsigned char *bin, size_t bin_len, string &encoded_string) +{ + // Get length of encoded result from sodium. const size_t base64_len = sodium_base64_encoded_len(bin_len, sodium_base64_VARIANT_ORIGINAL); char base64chars[base64_len]; - char *encoded_str_char = sodium_bin2base64( + // Get encoded string. + const char *encoded_str_char = sodium_bin2base64( base64chars, base64_len, bin, bin_len, sodium_base64_VARIANT_ORIGINAL); @@ -21,11 +28,12 @@ int base64_encode(unsigned char *bin, size_t bin_len, string &encoded_string) if (encoded_str_char == NULL) return -1; + // Assign the encoded char* onto the provided string reference. replace_string_contents(encoded_string, base64chars, base64_len); return 0; } -int base64_decode(string &base64_str, unsigned char *decoded, size_t decoded_len) +int base64_decode(const string &base64_str, unsigned char *decoded, size_t decoded_len) { const char *b64_end; size_t bin_len; @@ -41,17 +49,10 @@ int base64_decode(string &base64_str, unsigned char *decoded, size_t decoded_len return 0; } -void replace_string_contents(string &str, const char *bytes, size_t bytes_len) -{ - if (str.length() > 0) - str.clear(); - str.append(bytes, bytes_len); -} - // v1 < v2 -> -1 // v1 == v2 -> 0 // v1 > v2 -> +1 -int version_compare(string &v1, string &v2) +int version_compare(const string &v1, const string &v2) { size_t i = 0, j = 0; while (i < v1.length() || j < v2.length()) @@ -80,4 +81,4 @@ int version_compare(string &v1, string &v2) return 0; } -} // namespace shared \ No newline at end of file +} // namespace util \ No newline at end of file diff --git a/src/util.hpp b/src/util.hpp new file mode 100644 index 00000000..b7e7ce5e --- /dev/null +++ b/src/util.hpp @@ -0,0 +1,89 @@ +#ifndef _HP_UTIL_H_ +#define _HP_UTIL_H_ + +#include +#include + +using namespace std; + +namespace util +{ + +/** + * Holds information about an authenticated (challenge-verified) user + * connected to the HotPocket node. + */ +struct contract_user +{ + string pubkeyb64; // Base64 user public key + int inpipe[2]; // Pipe to receive user input + int outpipe[2]; // Pipe to receive output produced by the contract + string outbuffer; // Holds the contract output to be processed by consensus rounds + + contract_user(const string &_pubkeyb64, int _inpipe[2], int _outpipe[2]) + { + pubkeyb64 = _pubkeyb64; + inpipe[0] = _inpipe[0]; + inpipe[1] = _inpipe[1]; + outpipe[0] = _outpipe[0]; + outpipe[1] = _outpipe[1]; + } +}; + +/** + * Holds information about a HotPocket peer connected to this node. + */ +struct peer_node +{ + string pubkeyb64; // Base64 peer public key + int inpipe[2]; // NPL pipe from HP to SC + int outpipe[2]; // NPL pipe from SC to HP + + peer_node(const string &_pubkeyb64, int _inpipe[2], int _outpipe[2]) + { + pubkeyb64 = _pubkeyb64; + inpipe[0] = _inpipe[0]; + inpipe[1] = _inpipe[1]; + outpipe[0] = _outpipe[0]; + outpipe[1] = _outpipe[1]; + } +}; + +/** + * Encodes provided bytes to base64 string. + * + * @param bin Bytes to encode. + * @param bin_len Bytes length. + * @param encoded_string String reference to assign the base64 encoded output. + */ +int base64_encode(const unsigned char *bin, size_t bin_len, string &encoded_string); + +/** + * Decodes provided base64 string into bytes. + * + * @param base64_str Base64 string to decode. + * @param decoded Decoded bytes. + * @param decoded_len Decoded bytes length. + */ +int base64_decode(const string &base64_str, unsigned char *decoded, size_t decoded_len); + +/** + * Replaces contents of the given string with provided bytes. + * + * @param str String reference to replace contents. + * @param bytes Bytes to write into the string. + * @param bytes_len Bytes length. + */ +void replace_string_contents(string &str, const char* bytes, size_t bytes_len); + +/** + * Compare two version strings in the format of "1.12.3". + * v1 < v2 -> returns -1 + * v1 == v2 -> returns 0 + * v1 > v2 -> returns +1 + */ +int version_compare(const string &v1, const string &v2); + +} // namespace usr + +#endif \ No newline at end of file