Added bson support for user message protocol. (#99)

This commit is contained in:
Ravin Perera
2020-07-02 21:40:55 +05:30
committed by GitHub
parent 8103ef7af6
commit 96f23cb0ff
47 changed files with 1424 additions and 810 deletions

View File

@@ -44,10 +44,12 @@ add_executable(hpcore
src/comm/comm_session.cpp
src/comm/comm_server.cpp
src/comm/comm_client.cpp
src/fbschema/common_helpers.cpp
src/fbschema/p2pmsg_helpers.cpp
src/fbschema/ledger_helpers.cpp
src/jsonschema/usrmsg_helpers.cpp
src/msg/fbuf/common_helpers.cpp
src/msg/fbuf/p2pmsg_helpers.cpp
src/msg/fbuf/ledger_helpers.cpp
src/msg/json/usrmsg_json.cpp
src/msg/bson/usrmsg_bson.cpp
src/msg/usrmsg_parser.cpp
src/p2p/peer_session_handler.cpp
src/p2p/p2p.cpp
src/usr/user_session_handler.cpp

View File

@@ -11,6 +11,7 @@ A C++ version of hotpocket designed for production envrionments, original protot
* Crypto - Libsodium https://github.com/jedisct1/libsodium
* Websockets - Server: [Websocketd (forked)](https://github.com/codetsunami/websocketd) | Client: [Websocat](https://github.com/vi/websocat) | Pipe: [netcat (OpenBSD)](https://man.openbsd.org/nc.1)
* RapidJSON - http://rapidjson.org
* jsoncons (for BSON) - https://github.com/danielaparker/jsoncons
* P2P Protocol - https://google.github.io/flatbuffers
* Fuse filesystem - https://github.com/libfuse/libfuse
* Boost - https://www.boost.org
@@ -44,6 +45,12 @@ Following Instructions are based on Boost [getting started](https://www.boost.or
2. Navigate to the extracted directory.
3. Run `sudo cp -r include/rapidjson /usr/local/include/`
#### Install jsoncons
1. Download and extract jsoncons v0.153.3 source from [here](https://github.com/danielaparker/jsoncons/archive/v0.153.3.zip).
2. Navigate to the extracted directory.
3. Run `sudo cp -r include/jsoncons /usr/local/include/`
4. Run `sudo mkdir -p /usr/local/include/jsoncons_ext/ && sudo cp -r include/jsoncons_ext/bson /usr/local/include/jsoncons_ext/`
#### Install FlatBuffers
Instructions are based on [this](https://google.github.io/flatbuffers/).
@@ -61,7 +68,7 @@ make
##### Compiling FlatBuffers message definitions
Example: When you make a change to `p2pmsg_content_.fbc` defnition file, you need to run this:
`flatc -o src/fbschema/ --gen-mutable --cpp src/fbschema/p2pmsg_content.fbs`
`flatc -o src/msg/fbuf/ --gen-mutable --cpp src/msg/fbuf/p2pmsg_content.fbs`
#### Install libfuse
1. `sudo apt-get install -y meson ninja-build pkg-config`

View File

@@ -6,7 +6,6 @@ const readline = require('readline')
// sodium has a trigger when it's ready, we will wait and execute from there
sodium.ready.then(main).catch((e) => { console.log(e) })
function main() {
var keys = sodium.crypto_sign_keypair()
@@ -34,15 +33,6 @@ function main() {
rejectUnauthorized: false
})
/* anatomy of a public challenge
{
version: '0.1',
type: 'public_challenge',
challenge: '<hex string>'
}
*/
// if the console ctrl + c's us we should close ws gracefully
process.once('SIGINT', function (code) {
console.log('SIGINT received...');
@@ -83,7 +73,8 @@ function main() {
type: 'handshake_response',
challenge: m.challenge,
sig: Buffer.from(sigbytes).toString('hex'),
pubkey: pkhex
pubkey: pkhex,
protocol: 'json'
}
ws.send(JSON.stringify(response))

View File

@@ -7,19 +7,52 @@
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
},
"base64-js": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
"integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
},
"bson": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/bson/-/bson-4.0.4.tgz",
"integrity": "sha512-Ioi3TD0/1V3aI8+hPfC56TetYmzfq2H07jJa9A1lKTxWsFtHtYdLMGMXjtGEg9v0f72NSM07diRQEUNYhLupIA==",
"requires": {
"buffer": "^5.1.0",
"long": "^4.0.0"
}
},
"buffer": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.6.0.tgz",
"integrity": "sha512-/gDYp/UtU0eA1ys8bOs9J6a+E/KWIY+DZ+Q2WESNUA0jFRsJOc0SNUO6xJ5SGA1xueg3NL65W6s+NY5l9cunuw==",
"requires": {
"base64-js": "^1.0.2",
"ieee754": "^1.1.4"
}
},
"ieee754": {
"version": "1.1.13",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
},
"libsodium": {
"version": "0.7.5",
"resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.5.tgz",
"integrity": "sha512-0YVU2QJc5sDR5HHkGCaliYImS7pGeXi11fiOfm4DirBd96PJVZIn3LJa06ZOFjLNsWkL3UbNjYhLRUOABPL9vw=="
"version": "0.7.6",
"resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.6.tgz",
"integrity": "sha512-hPb/04sEuLcTRdWDtd+xH3RXBihpmbPCsKW/Jtf4PsvdyKh+D6z2D2gvp/5BfoxseP+0FCOg66kE+0oGUE/loQ=="
},
"libsodium-wrappers": {
"version": "0.7.5",
"resolved": "https://registry.npmjs.org/libsodium-wrappers/-/libsodium-wrappers-0.7.5.tgz",
"integrity": "sha512-QE9Q+FxLLGdJRiJTuC2GB3LEHZeHX/VcbMQeNPdAixEKo86JPy6bOWND1XmMLu0tjWUu0xIY0YpJYQApxIZwbQ==",
"version": "0.7.6",
"resolved": "https://registry.npmjs.org/libsodium-wrappers/-/libsodium-wrappers-0.7.6.tgz",
"integrity": "sha512-OUO2CWW5bHdLr6hkKLHIKI4raEkZrf3QHkhXsJ1yCh6MZ3JDA7jFD3kCATNquuGSG6MjjPHQIQms0y0gBDzjQg==",
"requires": {
"libsodium": "0.7.5"
"libsodium": "0.7.6"
}
},
"long": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
"integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
},
"ws": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.1.2.tgz",

View File

@@ -1,6 +1,7 @@
{
"dependencies": {
"libsodium-wrappers": "0.7.5",
"ws": "7.1.2"
"libsodium-wrappers": "0.7.6",
"ws": "7.1.2",
"bson": "4.0.4"
}
}

View File

@@ -1,109 +1,127 @@
//
// HotPocket client example code adopted from:
// https://github.com/codetsunami/hotpocket/blob/master/hp_client.js
//
// Usage:
// node text-client.js [json|bson]
// node text-client.js [json|bson] [<port>]
// node text-client.js [json|bson] [<ip>] [<port>]
const fs = require('fs')
const ws_api = require('ws');
const sodium = require('libsodium-wrappers')
const readline = require('readline')
// sodium has a trigger when it's ready, we will wait and execute from there
sodium.ready.then(main).catch((e) => { console.log(e) })
const bson = require('bson');
const { exit } = require('process');
function main() {
var keys = sodium.crypto_sign_keypair()
// We use json protocol for messages until handshake completion.
let is_json = true;
if (process.argv.length < 3) {
console.log("Not enough arguments. 'protocol: [json|bson] required")
return;
}
const protocol = process.argv[2];
if (protocol != 'json' && protocol != 'bson') {
console.log("Not enough arguments. 'protocol: [json|bson] required")
return;
}
// check for client keys
if (!fs.existsSync('.hp_client_keys')) {
let server = 'wss://localhost:8080'
if (process.argv.length == 4) server = 'wss://localhost:' + process.argv[3]
if (process.argv.length == 5) server = 'wss://' + process.argv[3] + ':' + process.argv[4]
const ws = new ws_api(server, {
rejectUnauthorized: false
})
let keys = {};
const key_file = '.hp_client_keys';
if (!fs.existsSync(key_file)) {
keys = sodium.crypto_sign_keypair();
keys.privateKey = sodium.to_hex(keys.privateKey)
keys.publicKey = sodium.to_hex(keys.publicKey)
fs.writeFileSync('.hp_client_keys', JSON.stringify(keys))
fs.writeFileSync(key_file, JSON.stringify(keys))
} else {
keys = JSON.parse(fs.readFileSync('.hp_client_keys'))
keys = JSON.parse(fs.readFileSync(key_file))
keys.privateKey = Uint8Array.from(Buffer.from(keys.privateKey, 'hex'))
keys.publicKey = Uint8Array.from(Buffer.from(keys.publicKey, 'hex'))
}
var server = 'wss://localhost:8080'
if (process.argv.length == 3) server = 'wss://localhost:' + process.argv[2]
if (process.argv.length == 4) server = 'wss://' + process.argv[2] + ':' + process.argv[3]
var ws = new ws_api(server, {
rejectUnauthorized: false
})
/* anatomy of a public challenge
{
version: '0.1',
type: 'public_challenge',
challenge: '<hex string>'
}
*/
const pkhex = 'ed' + Buffer.from(keys.publicKey).toString('hex');
console.log('My public key is: ' + pkhex);
// if the console ctrl + c's us we should close ws gracefully
process.once('SIGINT', function (code) {
process.once('SIGINT', function () {
console.log('SIGINT received...');
ws.close()
ws.close();
});
function encode_buffer(buffer) {
return is_json ? buffer.toString('hex') : buffer;
}
function serialize_object(obj) {
return is_json ? Buffer.from(JSON.stringify(obj)) : bson.serialize(obj);
}
function deserialize_message(m) {
return is_json ? JSON.parse(m) : bson.deserialize(m);
}
function create_handshake_response(challenge) {
const sig_bytes = sodium.crypto_sign_detached(challenge, keys.privateKey);
return {
type: 'handshake_response',
challenge: challenge,
sig: encode_buffer(Buffer.from(sig_bytes)),
pubkey: pkhex,
protocol: protocol
}
}
function create_input_container(inp) {
let inp_container = {
if (inp.length == 0)
return null;
const inp_container = {
nonce: (new Date()).getTime().toString(),
input: Buffer.from(inp).toString('hex'),
max_lcl_seqno: 9999999
input: encode_buffer(Buffer.from(inp)),
max_lcl_seqno: 999999999
}
let inp_container_bytes = JSON.stringify(inp_container);
let sig_bytes = sodium.crypto_sign_detached(inp_container_bytes, keys.privateKey);
let signed_inp_container = {
const inp_container_bytes = serialize_object(inp_container);
const sig_bytes = Buffer.from(sodium.crypto_sign_detached(inp_container_bytes, keys.privateKey));
const signed_inp_container = {
type: "contract_input",
input_container: inp_container_bytes.toString('hex'),
sig: Buffer.from(sig_bytes).toString('hex')
input_container: encode_buffer(inp_container_bytes),
sig: encode_buffer(sig_bytes)
}
return JSON.stringify(signed_inp_container);
return signed_inp_container;
}
function create_read_request_container(inp) {
if (inp.length == 0)
return "";
return null;
let container = {
return {
type: "contract_read_request",
content: Buffer.from(inp).toString('hex'),
content: encode_buffer(Buffer.from(inp))
}
return JSON.stringify(container);
}
function create_status_request() {
let statreq = { type: 'stat' }
return JSON.stringify(statreq);
return { type: 'stat' };
}
function handle_public_challange(m) {
let pkhex = 'ed' + Buffer.from(keys.publicKey).toString('hex');
console.log('My public key is: ' + pkhex);
function handle_handshake_challange(m) {
// sign the challenge and send back the response
var sigbytes = sodium.crypto_sign_detached(m.challenge, keys.privateKey);
var response = {
type: 'handshake_response',
challenge: m.challenge,
sig: Buffer.from(sigbytes).toString('hex'),
pubkey: pkhex
}
ws.send(JSON.stringify(response))
const response = create_handshake_response(m.challenge);
ws.send(serialize_object(response));
is_json = (protocol == 'json');
// start listening for stdin
const rl = readline.createInterface({
@@ -111,23 +129,22 @@ function main() {
output: process.stdout
});
console.log("Ready to accept inputs.")
console.log("Ready to accept inputs.");
// Capture user input from the console.
var input_pump = () => {
const input_pump = () => {
rl.question('', (inp) => {
let msgtosend = "";
let msg;
if (inp == "stat")
msgtosend = create_status_request();
msg = create_status_request();
else if (inp.startsWith("read "))
msgtosend = create_read_request_container(inp.substr(5));
msg = create_read_request_container(inp.substr(5));
else
msgtosend = create_input_container(inp);
msg = create_input_container(inp);
if (msgtosend.length > 0)
ws.send(msgtosend)
if (msg != null)
ws.send(serialize_object(msg))
input_pump();
})
@@ -135,24 +152,25 @@ function main() {
input_pump();
}
ws.on('message', (data) => {
ws.on('message', (received_msg) => {
try {
m = JSON.parse(data)
m = deserialize_message(received_msg);
} catch (e) {
console.log("Exception: " + data);
return
console.log("Exception deserializing: " + received_msg);
return;
}
if (m.type == 'handshake_challenge') {
handle_public_challange(m);
handle_handshake_challange(m);
}
else if (m.type == 'contract_output' || m.type == 'contract_read_response') {
console.log(Buffer.from(m.content, 'hex').toString());
const contract_reply = is_json ? Buffer.from(m.content, 'hex').toString() : m.content.toString();
console.log(contract_reply);
}
else if (m.type == 'contract_input_status') {
if (m.status != "accepted")
console.log("Input status: " + m.status);
console.log("Input status: " + m.status + " | reason: " + m.reason);
}
else {
console.log(m);
@@ -162,5 +180,9 @@ function main() {
ws.on('close', () => {
console.log('Server disconnected.');
exit();
});
}
// sodium has a trigger when it's ready, we will wait and execute from there
sodium.ready.then(main).catch((e) => { console.log(e) })

View File

@@ -71,6 +71,13 @@ namespace comm
}
else if (read_len > 0)
{
if (!is_binary)
{
read_buffer.resize(read_len);
if (read(read_fd, read_buffer.data(), read_len) < read_len)
return -1;
}
int res = on_message(std::string_view(read_buffer.data(), read_len));
read_buffer.clear(); // Clear the buffer after read operation.
read_buffer_filled_size = 0;
@@ -91,6 +98,12 @@ namespace comm
return peer_sess_handler.on_message(*this, message);
}
int comm_session::send(const std::vector<uint8_t> &message) const
{
std::string_view sv(reinterpret_cast<const char *>(message.data()), message.size());
send(sv);
}
int comm_session::send(std::string_view message) const
{
if (state == SESSION_STATE::CLOSED)

View File

@@ -58,6 +58,7 @@ public:
const bool is_binary, const bool is_inbound, const uint64_t (&metric_thresholds)[4]);
int on_connect();
int attempt_read(const uint64_t max_msg_size);
int send(const std::vector<uint8_t> &message) const;
int send(std::string_view message) const;
void close(const bool invoke_handler = true);

View File

@@ -3,9 +3,10 @@
#include "../usr/usr.hpp"
#include "../usr/user_input.hpp"
#include "../p2p/p2p.hpp"
#include "../fbschema/p2pmsg_helpers.hpp"
#include "../fbschema/common_helpers.hpp"
#include "../jsonschema/usrmsg_helpers.hpp"
#include "../msg/fbuf/p2pmsg_helpers.hpp"
#include "../msg/fbuf/common_helpers.hpp"
#include "../msg/usrmsg_parser.hpp"
#include "../msg/usrmsg_common.hpp"
#include "../p2p/peer_session_handler.hpp"
#include "../hplog.hpp"
#include "../crypto.hpp"
@@ -16,8 +17,7 @@
#include "ledger_handler.hpp"
#include "cons.hpp"
namespace p2pmsg = fbschema::p2pmsg;
namespace jusrmsg = jsonschema::usrmsg;
namespace p2pmsg = msg::fbuf::p2pmsg;
namespace cons
{
@@ -126,9 +126,9 @@ namespace cons
std::lock_guard<std::mutex> lock(p2p::ctx.collected_msgs.npl_messages_mutex);
for (const auto &npl : p2p::ctx.collected_msgs.npl_messages)
{
const fbschema::p2pmsg::Container *container = fbschema::p2pmsg::GetContainer(npl.data());
const msg::fbuf::p2pmsg::Container *container = msg::fbuf::p2pmsg::GetContainer(npl.data());
// Only the npl messages with a valid lcl will be passed down to the contract. lcl should match the previous round's lcl
if (fbschema::flatbuff_bytes_to_sv(container->lcl()) != ctx.lcl)
if (msg::fbuf::flatbuff_bytes_to_sv(container->lcl()) != ctx.lcl)
continue;
ctx.candidate_npl_messages.push_back(std::move(npl));
@@ -325,12 +325,12 @@ namespace cons
for (auto &[sid, user] : usr::ctx.users)
{
std::list<usr::user_submitted_message> usermsgs;
usermsgs.splice(usermsgs.end(), user.submitted_inputs);
std::list<usr::user_input> user_inputs;
user_inputs.splice(user_inputs.end(), user.submitted_inputs);
// We should create an entry for each user pubkey, even if the user has no inputs. This is
// because this data map will be used to track connected users as well in addition to inputs.
nup.user_messages.try_emplace(user.pubkey, std::move(usermsgs));
nup.user_inputs.try_emplace(user.pubkey, std::move(user_inputs));
}
flatbuffers::FlatBufferBuilder fbuf(1024);
@@ -338,7 +338,7 @@ namespace cons
p2p::broadcast_message(fbuf, true);
LOG_DBG << "NUP sent."
<< " users:" << nup.user_messages.size();
<< " users:" << nup.user_inputs.size();
}
/**
@@ -354,7 +354,7 @@ namespace cons
std::lock_guard<std::mutex> nups_lock(p2p::ctx.collected_msgs.nonunl_proposals_mutex);
for (const p2p::nonunl_proposal &p : p2p::ctx.collected_msgs.nonunl_proposals)
{
for (const auto &[pubkey, umsgs] : p.user_messages)
for (const auto &[pubkey, umsgs] : p.user_inputs)
{
// Locate this user's socket session in case we need to send any status messages regarding user inputs.
const comm::comm_session *session = usr::get_session_by_pubkey(pubkey);
@@ -367,21 +367,23 @@ namespace cons
size_t total_input_len = 0;
bool appbill_balance_exceeded = false;
for (const usr::user_submitted_message &umsg : umsgs)
for (const usr::user_input &umsg : umsgs)
{
msg::usrmsg::usrmsg_parser parser(umsg.protocol);
const char *reject_reason = NULL;
const std::string sig_hash = crypto::get_hash(umsg.sig);
// Check for duplicate messages using hash of the signature.
if (ctx.recent_userinput_hashes.try_emplace(sig_hash))
{
// Verify the signature of the message content.
if (crypto::verify(umsg.content, umsg.sig, pubkey) == 0)
// Verify the signature of the input_container.
if (crypto::verify(umsg.input_container, umsg.sig, pubkey) == 0)
{
std::string nonce;
std::string input;
uint64_t max_lcl_seqno;
jusrmsg::extract_input_container(input, nonce, max_lcl_seqno, umsg.content);
parser.extract_input_container(input, nonce, max_lcl_seqno, umsg.input_container);
// Ignore the input if our ledger has passed the input TTL.
if (max_lcl_seqno > ctx.led_seq_no)
@@ -406,37 +408,38 @@ namespace cons
// Abandon processing further inputs from this user when we find out
// an input cannot be processed with the account balance.
appbill_balance_exceeded = true;
reject_reason = jusrmsg::REASON_APPBILL_BALANCE_EXCEEDED;
reject_reason = msg::usrmsg::REASON_APPBILL_BALANCE_EXCEEDED;
}
}
else
{
reject_reason = jusrmsg::REASON_APPBILL_BALANCE_EXCEEDED;
reject_reason = msg::usrmsg::REASON_APPBILL_BALANCE_EXCEEDED;
}
}
else
{
LOG_DBG << "User message bad max ledger seq expired.";
reject_reason = jusrmsg::REASON_MAX_LEDGER_EXPIRED;
reject_reason = msg::usrmsg::REASON_MAX_LEDGER_EXPIRED;
}
}
else
{
LOG_DBG << "User message bad signature.";
reject_reason = jusrmsg::REASON_BAD_SIG;
reject_reason = msg::usrmsg::REASON_BAD_SIG;
}
}
else
{
LOG_DBG << "Duplicate user message.";
reject_reason = jusrmsg::REASON_DUPLICATE_MSG;
reject_reason = msg::usrmsg::REASON_DUPLICATE_MSG;
}
// Send the request status result if this user is connected to us.
if (session != NULL)
{
usr::send_input_status(*session,
reject_reason == NULL ? jusrmsg::STATUS_ACCEPTED : jusrmsg::STATUS_REJECTED,
usr::send_input_status(parser,
*session,
reject_reason == NULL ? msg::usrmsg::STATUS_ACCEPTED : msg::usrmsg::STATUS_REJECTED,
reject_reason == NULL ? "" : reject_reason,
umsg.sig);
}
@@ -816,10 +819,12 @@ namespace cons
std::string outputtosend;
outputtosend.swap(cand_output.output);
std::string msg;
jusrmsg::create_contract_output_container(msg, outputtosend);
const usr::connected_user &user = user_itr->second;
msg::usrmsg::usrmsg_parser parser(user.protocol);
std::vector<uint8_t> msg;
parser.create_contract_output_container(msg, outputtosend);
user.session.send(msg);
}
}

View File

@@ -2,9 +2,9 @@
#include "../conf.hpp"
#include "../crypto.hpp"
#include "../p2p/p2p.hpp"
#include "../fbschema/common_helpers.hpp"
#include "../fbschema/ledger_helpers.hpp"
#include "../fbschema/p2pmsg_helpers.hpp"
#include "../msg/fbuf/common_helpers.hpp"
#include "../msg/fbuf/ledger_helpers.hpp"
#include "../msg/fbuf/p2pmsg_helpers.hpp"
#include "../hplog.hpp"
#include "ledger_handler.hpp"
#include "cons.hpp"
@@ -12,7 +12,7 @@
namespace cons
{
namespace p2pmsg = fbschema::p2pmsg;
namespace p2pmsg = msg::fbuf::p2pmsg;
/**
* Create and save ledger from the given proposal message.
@@ -37,7 +37,7 @@ const std::tuple<const uint64_t, std::string> save_ledger(const p2p::proposal &p
//Serialize lcl using flatbuffer ledger schema.
flatbuffers::FlatBufferBuilder builder(1024);
const std::string_view ledger_str = fbschema::ledger::create_ledger_from_proposal(builder, proposal, led_seq_no);
const std::string_view ledger_str = msg::fbuf::ledger::create_ledger_from_proposal(builder, proposal, led_seq_no);
//Get binary hash of the the serialized lcl.
const std::string lcl = crypto::get_hash(ledger_str);
@@ -185,10 +185,10 @@ const ledger_history load_ledger()
if (file.read(buffer.data(), size))
{
const uint8_t *ledger_buf_ptr = reinterpret_cast<const uint8_t *>(buffer.data());
const fbschema::ledger::Ledger *ledger = fbschema::ledger::GetLedger(ledger_buf_ptr);
const msg::fbuf::ledger::Ledger *ledger = msg::fbuf::ledger::GetLedger(ledger_buf_ptr);
ledger_cache_entry c;
c.lcl = file_name;
c.state = fbschema::flatbuff_bytes_to_sv(ledger->state());
c.state = msg::fbuf::flatbuff_bytes_to_sv(ledger->state());
ldg_hist.cache.emplace(seq_no, std::move(c)); //lcl_cache -> [seq_no-hash]
}

View File

@@ -1,55 +0,0 @@
#ifndef _HP_JSONSCHEMA_USRMSG_HELPERS_
#define _HP_JSONSCHEMA_USRMSG_HELPERS_
#include "../pchheader.hpp"
namespace jsonschema::usrmsg
{
// Message field names exposed out of this namespace.
extern const char* const FLD_TYPE;
// Message types
constexpr const char* MSGTYPE_HANDSHAKE_CHALLENGE = "handshake_challenge";
constexpr const char* MSGTYPE_HANDSHAKE_RESPONSE = "handshake_response";
constexpr const char* MSGTYPE_CONTRACT_READ_REQUEST = "contract_read_request";
constexpr const char* MSGTYPE_CONTRACT_READ_RESPONSE = "contract_read_response";
constexpr const char* MSGTYPE_CONTRACT_INPUT = "contract_input";
constexpr const char* MSGTYPE_CONTRACT_INPUT_STATUS = "contract_input_status";
constexpr const char* MSGTYPE_CONTRACT_OUTPUT = "contract_output";
constexpr const char* MSGTYPE_STAT = "stat";
constexpr const char* MSGTYPE_STAT_RESPONSE = "stat_response";
constexpr const char* MSGTYPE_UNKNOWN = "unknown";
constexpr const char *STATUS_ACCEPTED = "accepted";
constexpr const char *STATUS_REJECTED = "rejected";
constexpr const char *REASON_BAD_MSG_FORMAT = "bad_msg_format";
constexpr const char *REASON_INVALID_MSG_TYPE = "invalid_msg_type";
constexpr const char *REASON_DUPLICATE_MSG = "dup_msg";
constexpr const char *REASON_BAD_SIG = "bad_sig";
constexpr const char *REASON_APPBILL_BALANCE_EXCEEDED = "appbill_balance_exceeded";
constexpr const char *REASON_MAX_LEDGER_EXPIRED = "max_ledger_expired";
void create_user_challenge(std::string &msg, std::string &challengehex);
void create_status_response(std::string &msg);
void create_contract_input_status(std::string &msg, std::string_view status, std::string_view reason, std::string_view input_sig);
void create_contract_read_response_container(std::string &msg, std::string_view content);
void create_contract_output_container(std::string &msg, std::string_view content);
int verify_user_challenge_response(std::string &extracted_pubkeyhex, std::string_view response, std::string_view original_challenge);
int extract_read_request(std::string &extracted_content, const rapidjson::Document &d);
int extract_signed_input_container(std::string &extracted_input_container, std::string &extracted_sig, const rapidjson::Document &d);
int extract_input_container(std::string &input, std::string &nonce, uint64_t &max_lcl_seqno, std::string_view contentjson);
int parse_user_message(rapidjson::Document &d, std::string_view message);
} // namespace jsonschema::usrmsg
#endif

View File

@@ -0,0 +1,252 @@
#include "../../pchheader.hpp"
#include "../../util.hpp"
#include "../../cons/cons.hpp"
#include "../../hplog.hpp"
#include "../usrmsg_common.hpp"
#include "usrmsg_bson.hpp"
namespace msg::usrmsg::bson
{
/**
* Constructs a status response message.
* @param msg String reference to copy the generated bson message into.
* Message format:
* {
* "type": "stat_response",
* "lcl": "<lcl id>",
* "lcl_seqno": <integer>
* }
*/
void create_status_response(std::vector<uint8_t> &msg)
{
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_TYPE);
encoder.string_value(msg::usrmsg::MSGTYPE_STAT_RESPONSE);
encoder.key(msg::usrmsg::FLD_LCL);
encoder.string_value(cons::ctx.lcl);
encoder.key(msg::usrmsg::FLD_LCL_SEQ);
encoder.int64_value(cons::ctx.led_seq_no);
encoder.end_object();
encoder.flush();
}
/**
* Constructs a contract input status message.
* @param msg String reference to copy the generated bson message into.
* Message format:
* {
* "type": "contract_input_status",
* "status": "<accepted|rejected>",
* "reason": "<reson>",
* "input_sig": <signature of original input message>
* }
* @param is_accepted Whether the original message was accepted or not.
* @param reason Rejected reason. Empty if accepted.
* @param input_sig Binary signature of the original input message which generated this result.
*/
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status, std::string_view reason, std::string_view input_sig)
{
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_TYPE);
encoder.string_value(msg::usrmsg::MSGTYPE_CONTRACT_INPUT_STATUS);
encoder.key(msg::usrmsg::FLD_STATUS);
encoder.string_value(status);
encoder.key(msg::usrmsg::FLD_REASON);
encoder.string_value(reason);
encoder.key(msg::usrmsg::FLD_INPUT_SIG);
encoder.byte_string_value(input_sig);
encoder.end_object();
encoder.flush();
}
/**
* Constructs a contract read response message.
* @param msg String reference to copy the generated bson message into.
* Message format:
* {
* "type": "contract_read_response",
* "content": <contract output>
* }
* @param content The contract binary output content to be put in the message.
*/
void create_contract_read_response_container(std::vector<uint8_t> &msg, std::string_view content)
{
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_TYPE);
encoder.string_value(msg::usrmsg::MSGTYPE_CONTRACT_READ_RESPONSE);
encoder.key(msg::usrmsg::FLD_CONTENT);
encoder.byte_string_value(content);
encoder.end_object();
encoder.flush();
}
/**
* Constructs a contract output container message.
* @param msg String reference to copy the generated bson message into.
* Message format:
* {
* "type": "contract_output",
* "lcl": "<lcl id>"
* "lcl_seqno": <integer>,
* "content": <contract output>
* }
* @param content The contract binary output content to be put in the message.
*/
void create_contract_output_container(std::vector<uint8_t> &msg, std::string_view content)
{
jsoncons::bson::bson_bytes_encoder encoder(msg);
encoder.begin_object();
encoder.key(msg::usrmsg::FLD_TYPE);
encoder.string_value(msg::usrmsg::MSGTYPE_CONTRACT_OUTPUT);
encoder.key(msg::usrmsg::FLD_LCL);
encoder.string_value(cons::ctx.lcl);
encoder.key(msg::usrmsg::FLD_LCL_SEQ);
encoder.int64_value(cons::ctx.led_seq_no);
encoder.key(msg::usrmsg::FLD_CONTENT);
encoder.byte_string_value(content);
encoder.end_object();
encoder.flush();
}
/**
* Parses a bson message sent by a user.
* @param d BSON document to which the parsed bson should be loaded.
* @param message The message to parse.
* Accepted message format:
* {
* 'type': '<message type>'
* ...
* }
* @return 0 on successful parsing. -1 for failure.
*/
int parse_user_message(jsoncons::ojson &d, std::string_view message)
{
try
{
d = jsoncons::bson::decode_bson<jsoncons::ojson>(message);
}
catch (const std::exception &e)
{
LOG_DBG << "User bson message parsing failed.";
return -1;
}
if (!d[FLD_TYPE].is_string())
{
LOG_DBG << "User bson message 'type' missing or invalid.";
return -1;
}
return 0;
}
/**
* Extracts the message 'type' value from the bson document.
*/
int extract_type(std::string &extracted_type, const jsoncons::ojson &d)
{
extracted_type = d[FLD_TYPE].as<std::string>();
return 0;
}
/**
* Extracts a contract read request message sent by user.
*
* @param extracted_content The content to be passed to the contract, extracted from the message.
* @param d The bson document holding the read request message.
* Accepted signed input container format:
* {
* "type": "contract_read_request",
* "content": <content to be passed to the contract>
* }
* @return 0 on successful extraction. -1 for failure.
*/
int extract_read_request(std::string &extracted_content, const jsoncons::ojson &d)
{
if (!d[msg::usrmsg::FLD_CONTENT].is_byte_string_view())
{
LOG_DBG << "Read request 'content' fields missing or invalid.";
return -1;
}
const jsoncons::byte_string_view &bsv = d[msg::usrmsg::FLD_CONTENT].as_byte_string_view();
extracted_content = std::string_view(reinterpret_cast<const char *>(bsv.data()), bsv.size());
return 0;
}
/**
* Extracts a signed input container message sent by user.
*
* @param extracted_input_container The input container extracted from the message.
* @param extracted_sig The binary signature extracted from the message.
* @param d The bson document holding the input container.
* Accepted signed input container format:
* {
* "type": "contract_input",
* "input_container": <bson input container message>,
* "sig": <signature of the content>
* }
* @return 0 on successful extraction. -1 for failure.
*/
int extract_signed_input_container(
std::string &extracted_input_container, std::string &extracted_sig, const jsoncons::ojson &d)
{
if (!d[msg::usrmsg::FLD_INPUT_CONTAINER].is_byte_string_view() || !d[msg::usrmsg::FLD_SIG].is_byte_string_view())
{
LOG_DBG << "User signed input required fields missing or invalid.";
return -1;
}
const jsoncons::byte_string_view &bsv1 = d[msg::usrmsg::FLD_INPUT_CONTAINER].as_byte_string_view();
extracted_input_container = std::string_view(reinterpret_cast<const char *>(bsv1.data()), bsv1.size());
const jsoncons::byte_string_view &bsv2 = d[msg::usrmsg::FLD_SIG].as_byte_string_view();
extracted_sig = std::string_view(reinterpret_cast<const char *>(bsv2.data()), bsv2.size());
return 0;
}
/**
* Extract the individual components of a given input container bson.
* @param input The extracted input.
* @param nonce The extracted nonce.
* @param max_lcl_seqno The extracted max ledger sequence no.
* @param contentjson The bson input container message.
* {
* "input": <contract input content>,
* "nonce": "<random string with optional sorted order>",
* "max_lcl_seqno": <integer>
* }
* @return 0 on succesful extraction. -1 on failure.
*/
int extract_input_container(std::string &input, std::string &nonce, uint64_t &max_lcl_seqno, std::string_view contentbson)
{
jsoncons::ojson d;
try
{
d = jsoncons::bson::decode_bson<jsoncons::ojson>(contentbson);
}
catch (const std::exception &e)
{
LOG_DBG << "User input container bson parsing failed.";
return -1;
}
if (!d[msg::usrmsg::FLD_INPUT].is_byte_string_view() || !d[msg::usrmsg::FLD_NONCE].is_string() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].is_uint64())
{
LOG_DBG << "User input container required fields missing or invalid.";
return -1;
}
const jsoncons::byte_string_view &bsv = d[msg::usrmsg::FLD_INPUT].as_byte_string_view();
input = std::string_view(reinterpret_cast<const char *>(bsv.data()), bsv.size());
nonce = d[msg::usrmsg::FLD_NONCE].as<std::string>();
max_lcl_seqno = d[msg::usrmsg::FLD_MAX_LCL_SEQ].as<uint64_t>();
return 0;
}
} // namespace msg::usrmsg::bson

View File

@@ -0,0 +1,37 @@
#ifndef _HP_MSG_BSON_USRMSG_BSON_
#define _HP_MSG_BSON_USRMSG_BSON_
#include "../../pchheader.hpp"
namespace msg::usrmsg::bson
{
void create_user_challenge(std::vector<uint8_t> &msg, std::string &challengehex);
void create_status_response(std::vector<uint8_t> &msg);
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status, std::string_view reason,
std::string_view input_sig);
void create_contract_read_response_container(std::vector<uint8_t> &msg, std::string_view content);
void create_contract_output_container(std::vector<uint8_t> &msg, std::string_view content);
int verify_user_handshake_response(std::string &extracted_pubkeyhex, std::string &extracted_protocol,
std::string_view response, std::string_view original_challenge);
int parse_user_message(jsoncons::ojson &d, std::string_view message);
int extract_type(std::string &extracted_type, const jsoncons::ojson &d);
int extract_read_request(std::string &extracted_content, const jsoncons::ojson &d);
int extract_signed_input_container(std::string &extracted_input_container, std::string &extracted_sig,
const jsoncons::ojson &d);
int extract_input_container(std::string &input, std::string &nonce,
uint64_t &max_lcl_seqno, std::string_view contentbson);
} // namespace msg::usrmsg::bson
#endif

View File

@@ -1,6 +1,6 @@
#include "common_helpers.hpp"
namespace fbschema
namespace msg::fbuf
{
//---Conversion helpers from flatbuffers data types to std data types---//
@@ -123,4 +123,4 @@ namespace fbschema
return builder.CreateVector(fbvec);
}
} // namespace fbschema
} // namespace msg::fbuf

View File

@@ -1,11 +1,11 @@
#ifndef _HP_FBSCHEMA_COMMON_HELPERS_
#define _HP_FBSCHEMA_COMMON_HELPERS_
#ifndef _HP_MSG_FBUF_COMMON_HELPERS_
#define _HP_MSG_FBUF_COMMON_HELPERS_
#include "../pchheader.hpp"
#include "../hpfs/h32.hpp"
#include "../../pchheader.hpp"
#include "../../hpfs/h32.hpp"
#include "common_schema_generated.h"
namespace fbschema
namespace msg::fbuf
{
/**
* This section contains common Flatbuffer message reading/writing helpers.
@@ -44,6 +44,6 @@ stringlist_to_flatbuf_bytearrayvector(flatbuffers::FlatBufferBuilder &builder, c
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<BytesKeyValuePair>>>
stringmap_to_flatbuf_bytepairvector(flatbuffers::FlatBufferBuilder &builder, const std::unordered_map<std::string, const std::string> &map);
} // namespace fbschema
} // namespace msg::fbuf
#endif

View File

@@ -1,5 +1,5 @@
//IDL file for common types.
namespace fbschema;
namespace msg.fbuf;
table BytesKeyValuePair { //A key, value pair of byte[].
key:[ubyte];

View File

@@ -1,18 +1,22 @@
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_COMMONSCHEMA_FBSCHEMA_
#define FLATBUFFERS_GENERATED_COMMONSCHEMA_FBSCHEMA_
#ifndef FLATBUFFERS_GENERATED_COMMONSCHEMA_MSG_FBUF_H_
#define FLATBUFFERS_GENERATED_COMMONSCHEMA_MSG_FBUF_H_
#include "flatbuffers/flatbuffers.h"
namespace fbschema {
namespace msg {
namespace fbuf {
struct BytesKeyValuePair;
struct BytesKeyValuePairBuilder;
struct ByteArray;
struct ByteArrayBuilder;
struct BytesKeyValuePair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef BytesKeyValuePairBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_KEY = 4,
VT_VALUE = 6
@@ -40,6 +44,7 @@ struct BytesKeyValuePair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
};
struct BytesKeyValuePairBuilder {
typedef BytesKeyValuePair Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_key(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> key) {
@@ -52,7 +57,6 @@ struct BytesKeyValuePairBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
BytesKeyValuePairBuilder &operator=(const BytesKeyValuePairBuilder &);
flatbuffers::Offset<BytesKeyValuePair> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<BytesKeyValuePair>(end);
@@ -76,13 +80,14 @@ inline flatbuffers::Offset<BytesKeyValuePair> CreateBytesKeyValuePairDirect(
const std::vector<uint8_t> *value = nullptr) {
auto key__ = key ? _fbb.CreateVector<uint8_t>(*key) : 0;
auto value__ = value ? _fbb.CreateVector<uint8_t>(*value) : 0;
return fbschema::CreateBytesKeyValuePair(
return msg::fbuf::CreateBytesKeyValuePair(
_fbb,
key__,
value__);
}
struct ByteArray FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef ByteArrayBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ARRAY = 4
};
@@ -101,6 +106,7 @@ struct ByteArray FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
};
struct ByteArrayBuilder {
typedef ByteArray Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_array(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> array) {
@@ -110,7 +116,6 @@ struct ByteArrayBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
ByteArrayBuilder &operator=(const ByteArrayBuilder &);
flatbuffers::Offset<ByteArray> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<ByteArray>(end);
@@ -130,11 +135,12 @@ inline flatbuffers::Offset<ByteArray> CreateByteArrayDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<uint8_t> *array = nullptr) {
auto array__ = array ? _fbb.CreateVector<uint8_t>(*array) : 0;
return fbschema::CreateByteArray(
return msg::fbuf::CreateByteArray(
_fbb,
array__);
}
} // namespace fbschema
} // namespace fbuf
} // namespace msg
#endif // FLATBUFFERS_GENERATED_COMMONSCHEMA_FBSCHEMA_
#endif // FLATBUFFERS_GENERATED_COMMONSCHEMA_MSG_FBUF_H_

View File

@@ -1,10 +1,10 @@
#include "../pchheader.hpp"
#include "../../pchheader.hpp"
#include "../../p2p/p2p.hpp"
#include "ledger_schema_generated.h"
#include "../p2p/p2p.hpp"
#include "common_helpers.hpp"
#include "ledger_helpers.hpp"
namespace fbschema::ledger
namespace msg::fbuf::ledger
{
/**
@@ -28,4 +28,4 @@ const std::string_view create_ledger_from_proposal(flatbuffers::FlatBufferBuilde
return flatbuff_bytes_to_sv(builder.GetBufferPointer(), builder.GetSize());
}
} // namespace fbschema::ledger
} // namespace msg::fbuf::ledger

View File

@@ -1,11 +1,11 @@
#ifndef _HP_FBSCHEMA_LEDGER_HELPERS_
#define _HP_FBSCHEMA_LEDGER_HELPERS_
#ifndef _HP_MSG_FBUF_LEDGER_HELPERS_
#define _HP_MSG_FBUF_LEDGER_HELPERS_
#include "../pchheader.hpp"
#include "../../pchheader.hpp"
#include "../../p2p/p2p.hpp"
#include "ledger_schema_generated.h"
#include "../p2p/p2p.hpp"
namespace fbschema::ledger
namespace msg::fbuf::ledger
{
const std::string_view create_ledger_from_proposal(flatbuffers::FlatBufferBuilder &builder, const p2p::proposal &p, const uint64_t seq_no);

View File

@@ -1,6 +1,6 @@
include "common_schema.fbs";
namespace fbschema.ledger;
namespace msg.fbuf.ledger;
table Ledger {
seq_no:uint64;

View File

@@ -1,21 +1,25 @@
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_LEDGERSCHEMA_FBSCHEMA_LEDGER_H_
#define FLATBUFFERS_GENERATED_LEDGERSCHEMA_FBSCHEMA_LEDGER_H_
#ifndef FLATBUFFERS_GENERATED_LEDGERSCHEMA_MSG_FBUF_LEDGER_H_
#define FLATBUFFERS_GENERATED_LEDGERSCHEMA_MSG_FBUF_LEDGER_H_
#include "flatbuffers/flatbuffers.h"
#include "common_schema_generated.h"
namespace fbschema {
namespace msg {
namespace fbuf {
namespace ledger {
struct Ledger;
struct LedgerBuilder;
struct RawInputList;
struct RawInputListBuilder;
struct Ledger FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef LedgerBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_SEQ_NO = 4,
VT_TIME = 6,
@@ -49,23 +53,23 @@ struct Ledger FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
flatbuffers::Vector<uint8_t> *mutable_state() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_STATE);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *users() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_USERS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *users() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_USERS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_users() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_USERS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_users() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_USERS);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_INPUTS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_INPUTS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_INPUTS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_INPUTS);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *outputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_OUTPUTS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *outputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_OUTPUTS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_outputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_OUTPUTS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_outputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_OUTPUTS);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
@@ -89,6 +93,7 @@ struct Ledger FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
};
struct LedgerBuilder {
typedef Ledger Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_seq_no(uint64_t seq_no) {
@@ -103,20 +108,19 @@ struct LedgerBuilder {
void add_state(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state) {
fbb_.AddOffset(Ledger::VT_STATE, state);
}
void add_users(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> users) {
void add_users(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> users) {
fbb_.AddOffset(Ledger::VT_USERS, users);
}
void add_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> inputs) {
void add_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> inputs) {
fbb_.AddOffset(Ledger::VT_INPUTS, inputs);
}
void add_outputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> outputs) {
void add_outputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> outputs) {
fbb_.AddOffset(Ledger::VT_OUTPUTS, outputs);
}
explicit LedgerBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
LedgerBuilder &operator=(const LedgerBuilder &);
flatbuffers::Offset<Ledger> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Ledger>(end);
@@ -130,9 +134,9 @@ inline flatbuffers::Offset<Ledger> CreateLedger(
uint64_t time = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> lcl = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> users = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> inputs = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> outputs = 0) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> users = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> inputs = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> outputs = 0) {
LedgerBuilder builder_(_fbb);
builder_.add_time(time);
builder_.add_seq_no(seq_no);
@@ -150,15 +154,15 @@ inline flatbuffers::Offset<Ledger> CreateLedgerDirect(
uint64_t time = 0,
const std::vector<uint8_t> *lcl = nullptr,
const std::vector<uint8_t> *state = nullptr,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *users = nullptr,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *inputs = nullptr,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *outputs = nullptr) {
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *users = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *inputs = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *outputs = nullptr) {
auto lcl__ = lcl ? _fbb.CreateVector<uint8_t>(*lcl) : 0;
auto state__ = state ? _fbb.CreateVector<uint8_t>(*state) : 0;
auto users__ = users ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*users) : 0;
auto inputs__ = inputs ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*inputs) : 0;
auto outputs__ = outputs ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*outputs) : 0;
return fbschema::ledger::CreateLedger(
auto users__ = users ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*users) : 0;
auto inputs__ = inputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*inputs) : 0;
auto outputs__ = outputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*outputs) : 0;
return msg::fbuf::ledger::CreateLedger(
_fbb,
seq_no,
time,
@@ -170,6 +174,7 @@ inline flatbuffers::Offset<Ledger> CreateLedgerDirect(
}
struct RawInputList FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef RawInputListBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_HASH = 4,
VT_INPUTS = 6
@@ -180,11 +185,11 @@ struct RawInputList FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
flatbuffers::Vector<uint8_t> *mutable_hash() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_HASH);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_INPUTS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_INPUTS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_INPUTS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_INPUTS);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
@@ -198,19 +203,19 @@ struct RawInputList FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
};
struct RawInputListBuilder {
typedef RawInputList Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_hash(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash) {
fbb_.AddOffset(RawInputList::VT_HASH, hash);
}
void add_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> inputs) {
void add_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> inputs) {
fbb_.AddOffset(RawInputList::VT_INPUTS, inputs);
}
explicit RawInputListBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
RawInputListBuilder &operator=(const RawInputListBuilder &);
flatbuffers::Offset<RawInputList> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<RawInputList>(end);
@@ -221,7 +226,7 @@ struct RawInputListBuilder {
inline flatbuffers::Offset<RawInputList> CreateRawInputList(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> inputs = 0) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> inputs = 0) {
RawInputListBuilder builder_(_fbb);
builder_.add_inputs(inputs);
builder_.add_hash(hash);
@@ -231,21 +236,21 @@ inline flatbuffers::Offset<RawInputList> CreateRawInputList(
inline flatbuffers::Offset<RawInputList> CreateRawInputListDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<uint8_t> *hash = nullptr,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *inputs = nullptr) {
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *inputs = nullptr) {
auto hash__ = hash ? _fbb.CreateVector<uint8_t>(*hash) : 0;
auto inputs__ = inputs ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*inputs) : 0;
return fbschema::ledger::CreateRawInputList(
auto inputs__ = inputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*inputs) : 0;
return msg::fbuf::ledger::CreateRawInputList(
_fbb,
hash__,
inputs__);
}
inline const fbschema::ledger::Ledger *GetLedger(const void *buf) {
return flatbuffers::GetRoot<fbschema::ledger::Ledger>(buf);
inline const msg::fbuf::ledger::Ledger *GetLedger(const void *buf) {
return flatbuffers::GetRoot<msg::fbuf::ledger::Ledger>(buf);
}
inline const fbschema::ledger::Ledger *GetSizePrefixedLedger(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<fbschema::ledger::Ledger>(buf);
inline const msg::fbuf::ledger::Ledger *GetSizePrefixedLedger(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<msg::fbuf::ledger::Ledger>(buf);
}
inline Ledger *GetMutableLedger(void *buf) {
@@ -254,27 +259,28 @@ inline Ledger *GetMutableLedger(void *buf) {
inline bool VerifyLedgerBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<fbschema::ledger::Ledger>(nullptr);
return verifier.VerifyBuffer<msg::fbuf::ledger::Ledger>(nullptr);
}
inline bool VerifySizePrefixedLedgerBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<fbschema::ledger::Ledger>(nullptr);
return verifier.VerifySizePrefixedBuffer<msg::fbuf::ledger::Ledger>(nullptr);
}
inline void FinishLedgerBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<fbschema::ledger::Ledger> root) {
flatbuffers::Offset<msg::fbuf::ledger::Ledger> root) {
fbb.Finish(root);
}
inline void FinishSizePrefixedLedgerBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<fbschema::ledger::Ledger> root) {
flatbuffers::Offset<msg::fbuf::ledger::Ledger> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace ledger
} // namespace fbschema
} // namespace fbuf
} // namespace msg
#endif // FLATBUFFERS_GENERATED_LEDGERSCHEMA_FBSCHEMA_LEDGER_H_
#endif // FLATBUFFERS_GENERATED_LEDGERSCHEMA_MSG_FBUF_LEDGER_H_

View File

@@ -3,7 +3,7 @@
needed api methods. Since Flatbuff only support one rrot at each IDL files, we had to seperate message schema to 2 files.
*/
include "p2pmsg_content.fbs";
namespace fbschema.p2pmsg;
namespace msg.fbuf.p2pmsg;
table Container { //root type for message
version:uint16;

View File

@@ -1,20 +1,23 @@
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_P2PMSGCONTAINER_FBSCHEMA_P2PMSG_H_
#define FLATBUFFERS_GENERATED_P2PMSGCONTAINER_FBSCHEMA_P2PMSG_H_
#ifndef FLATBUFFERS_GENERATED_P2PMSGCONTAINER_MSG_FBUF_P2PMSG_H_
#define FLATBUFFERS_GENERATED_P2PMSGCONTAINER_MSG_FBUF_P2PMSG_H_
#include "flatbuffers/flatbuffers.h"
#include "common_schema_generated.h"
#include "p2pmsg_content_generated.h"
namespace fbschema {
namespace msg {
namespace fbuf {
namespace p2pmsg {
struct Container;
struct ContainerBuilder;
struct Container FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef ContainerBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_VERSION = 4,
VT_TIMESTAMP = 6,
@@ -76,6 +79,7 @@ struct Container FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
};
struct ContainerBuilder {
typedef Container Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_version(uint16_t version) {
@@ -100,7 +104,6 @@ struct ContainerBuilder {
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
ContainerBuilder &operator=(const ContainerBuilder &);
flatbuffers::Offset<Container> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<Container>(end);
@@ -138,7 +141,7 @@ inline flatbuffers::Offset<Container> CreateContainerDirect(
auto lcl__ = lcl ? _fbb.CreateVector<uint8_t>(*lcl) : 0;
auto signature__ = signature ? _fbb.CreateVector<uint8_t>(*signature) : 0;
auto content__ = content ? _fbb.CreateVector<uint8_t>(*content) : 0;
return fbschema::p2pmsg::CreateContainer(
return msg::fbuf::p2pmsg::CreateContainer(
_fbb,
version,
timestamp,
@@ -148,12 +151,12 @@ inline flatbuffers::Offset<Container> CreateContainerDirect(
content__);
}
inline const fbschema::p2pmsg::Container *GetContainer(const void *buf) {
return flatbuffers::GetRoot<fbschema::p2pmsg::Container>(buf);
inline const msg::fbuf::p2pmsg::Container *GetContainer(const void *buf) {
return flatbuffers::GetRoot<msg::fbuf::p2pmsg::Container>(buf);
}
inline const fbschema::p2pmsg::Container *GetSizePrefixedContainer(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<fbschema::p2pmsg::Container>(buf);
inline const msg::fbuf::p2pmsg::Container *GetSizePrefixedContainer(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<msg::fbuf::p2pmsg::Container>(buf);
}
inline Container *GetMutableContainer(void *buf) {
@@ -162,27 +165,28 @@ inline Container *GetMutableContainer(void *buf) {
inline bool VerifyContainerBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<fbschema::p2pmsg::Container>(nullptr);
return verifier.VerifyBuffer<msg::fbuf::p2pmsg::Container>(nullptr);
}
inline bool VerifySizePrefixedContainerBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<fbschema::p2pmsg::Container>(nullptr);
return verifier.VerifySizePrefixedBuffer<msg::fbuf::p2pmsg::Container>(nullptr);
}
inline void FinishContainerBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<fbschema::p2pmsg::Container> root) {
flatbuffers::Offset<msg::fbuf::p2pmsg::Container> root) {
fbb.Finish(root);
}
inline void FinishSizePrefixedContainerBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<fbschema::p2pmsg::Container> root) {
flatbuffers::Offset<msg::fbuf::p2pmsg::Container> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace p2pmsg
} // namespace fbschema
} // namespace fbuf
} // namespace msg
#endif // FLATBUFFERS_GENERATED_P2PMSGCONTAINER_FBSCHEMA_P2PMSG_H_
#endif // FLATBUFFERS_GENERATED_P2PMSGCONTAINER_MSG_FBUF_P2PMSG_H_

View File

@@ -1,8 +1,8 @@
// IDL file for p2p message content schema.
// flatc -o src/fbschema/ --gen-mutable --cpp src/fbschema/p2pmsg_content.fbs
// flatc -o src/msg/fbuf/ --gen-mutable --cpp src/msg/fbuf/p2pmsg_content.fbs
include "common_schema.fbs";
namespace fbschema.p2pmsg;
namespace msg.fbuf.p2pmsg;
table Peer_Challenge_Message {
challenge:[ubyte];
@@ -13,14 +13,15 @@ table Peer_Challenge_Response_Message {
sig:[ubyte];
}
table UserSubmittedMessage {
content:[ubyte];
table UserInput {
input_container:[ubyte];
signature:[ubyte];
protocol:uint8;
}
table UserSubmittedMessageGroup {
table UserInputGroup {
pubkey:[ubyte];
messages:[UserSubmittedMessage];
messages:[UserInput];
}
union Message { Peer_Challenge_Response_Message, Peer_Challenge_Message, NonUnl_Proposal_Message, Proposal_Message, Npl_Message, State_Request_Message, State_Response_Message, History_Request_Message, History_Response_Message } //message content type
@@ -30,7 +31,7 @@ table Content {
}
table NonUnl_Proposal_Message {
usermessages:[UserSubmittedMessageGroup];
user_inputs:[UserInputGroup];
}
table Proposal_Message { //Proposal type message schema

View File

@@ -1,14 +1,15 @@
// automatically generated by the FlatBuffers compiler, do not modify
#ifndef FLATBUFFERS_GENERATED_P2PMSGCONTENT_FBSCHEMA_P2PMSG_H_
#define FLATBUFFERS_GENERATED_P2PMSGCONTENT_FBSCHEMA_P2PMSG_H_
#ifndef FLATBUFFERS_GENERATED_P2PMSGCONTENT_MSG_FBUF_P2PMSG_H_
#define FLATBUFFERS_GENERATED_P2PMSGCONTENT_MSG_FBUF_P2PMSG_H_
#include "flatbuffers/flatbuffers.h"
#include "common_schema_generated.h"
namespace fbschema {
namespace msg {
namespace fbuf {
namespace p2pmsg {
struct Peer_Challenge_Message;
@@ -17,11 +18,11 @@ struct Peer_Challenge_MessageBuilder;
struct Peer_Challenge_Response_Message;
struct Peer_Challenge_Response_MessageBuilder;
struct UserSubmittedMessage;
struct UserSubmittedMessageBuilder;
struct UserInput;
struct UserInputBuilder;
struct UserSubmittedMessageGroup;
struct UserSubmittedMessageGroupBuilder;
struct UserInputGroup;
struct UserInputGroupBuilder;
struct Content;
struct ContentBuilder;
@@ -123,39 +124,39 @@ template<typename T> struct MessageTraits {
static const Message enum_value = Message_NONE;
};
template<> struct MessageTraits<fbschema::p2pmsg::Peer_Challenge_Response_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::Peer_Challenge_Response_Message> {
static const Message enum_value = Message_Peer_Challenge_Response_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::Peer_Challenge_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::Peer_Challenge_Message> {
static const Message enum_value = Message_Peer_Challenge_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::NonUnl_Proposal_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::NonUnl_Proposal_Message> {
static const Message enum_value = Message_NonUnl_Proposal_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::Proposal_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::Proposal_Message> {
static const Message enum_value = Message_Proposal_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::Npl_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::Npl_Message> {
static const Message enum_value = Message_Npl_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::State_Request_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::State_Request_Message> {
static const Message enum_value = Message_State_Request_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::State_Response_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::State_Response_Message> {
static const Message enum_value = Message_State_Response_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::History_Request_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::History_Request_Message> {
static const Message enum_value = Message_History_Request_Message;
};
template<> struct MessageTraits<fbschema::p2pmsg::History_Response_Message> {
template<> struct MessageTraits<msg::fbuf::p2pmsg::History_Response_Message> {
static const Message enum_value = Message_History_Response_Message;
};
@@ -235,15 +236,15 @@ template<typename T> struct State_ResponseTraits {
static const State_Response enum_value = State_Response_NONE;
};
template<> struct State_ResponseTraits<fbschema::p2pmsg::File_HashMap_Response> {
template<> struct State_ResponseTraits<msg::fbuf::p2pmsg::File_HashMap_Response> {
static const State_Response enum_value = State_Response_File_HashMap_Response;
};
template<> struct State_ResponseTraits<fbschema::p2pmsg::Block_Response> {
template<> struct State_ResponseTraits<msg::fbuf::p2pmsg::Block_Response> {
static const State_Response enum_value = State_Response_Block_Response;
};
template<> struct State_ResponseTraits<fbschema::p2pmsg::Fs_Entry_Response> {
template<> struct State_ResponseTraits<msg::fbuf::p2pmsg::Fs_Entry_Response> {
static const State_Response enum_value = State_Response_Fs_Entry_Response;
};
@@ -299,7 +300,7 @@ inline flatbuffers::Offset<Peer_Challenge_Message> CreatePeer_Challenge_MessageD
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<uint8_t> *challenge = nullptr) {
auto challenge__ = challenge ? _fbb.CreateVector<uint8_t>(*challenge) : 0;
return fbschema::p2pmsg::CreatePeer_Challenge_Message(
return msg::fbuf::p2pmsg::CreatePeer_Challenge_Message(
_fbb,
challenge__);
}
@@ -369,23 +370,24 @@ inline flatbuffers::Offset<Peer_Challenge_Response_Message> CreatePeer_Challenge
const std::vector<uint8_t> *sig = nullptr) {
auto challenge__ = challenge ? _fbb.CreateVector<uint8_t>(*challenge) : 0;
auto sig__ = sig ? _fbb.CreateVector<uint8_t>(*sig) : 0;
return fbschema::p2pmsg::CreatePeer_Challenge_Response_Message(
return msg::fbuf::p2pmsg::CreatePeer_Challenge_Response_Message(
_fbb,
challenge__,
sig__);
}
struct UserSubmittedMessage FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef UserSubmittedMessageBuilder Builder;
struct UserInput FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef UserInputBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_CONTENT = 4,
VT_SIGNATURE = 6
VT_INPUT_CONTAINER = 4,
VT_SIGNATURE = 6,
VT_PROTOCOL = 8
};
const flatbuffers::Vector<uint8_t> *content() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_CONTENT);
const flatbuffers::Vector<uint8_t> *input_container() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_INPUT_CONTAINER);
}
flatbuffers::Vector<uint8_t> *mutable_content() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_CONTENT);
flatbuffers::Vector<uint8_t> *mutable_input_container() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_INPUT_CONTAINER);
}
const flatbuffers::Vector<uint8_t> *signature() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_SIGNATURE);
@@ -393,61 +395,75 @@ struct UserSubmittedMessage FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table
flatbuffers::Vector<uint8_t> *mutable_signature() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_SIGNATURE);
}
uint8_t protocol() const {
return GetField<uint8_t>(VT_PROTOCOL, 0);
}
bool mutate_protocol(uint8_t _protocol) {
return SetField<uint8_t>(VT_PROTOCOL, _protocol, 0);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_CONTENT) &&
verifier.VerifyVector(content()) &&
VerifyOffset(verifier, VT_INPUT_CONTAINER) &&
verifier.VerifyVector(input_container()) &&
VerifyOffset(verifier, VT_SIGNATURE) &&
verifier.VerifyVector(signature()) &&
VerifyField<uint8_t>(verifier, VT_PROTOCOL) &&
verifier.EndTable();
}
};
struct UserSubmittedMessageBuilder {
typedef UserSubmittedMessage Table;
struct UserInputBuilder {
typedef UserInput Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_content(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> content) {
fbb_.AddOffset(UserSubmittedMessage::VT_CONTENT, content);
void add_input_container(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> input_container) {
fbb_.AddOffset(UserInput::VT_INPUT_CONTAINER, input_container);
}
void add_signature(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> signature) {
fbb_.AddOffset(UserSubmittedMessage::VT_SIGNATURE, signature);
fbb_.AddOffset(UserInput::VT_SIGNATURE, signature);
}
explicit UserSubmittedMessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
void add_protocol(uint8_t protocol) {
fbb_.AddElement<uint8_t>(UserInput::VT_PROTOCOL, protocol, 0);
}
explicit UserInputBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
flatbuffers::Offset<UserSubmittedMessage> Finish() {
flatbuffers::Offset<UserInput> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<UserSubmittedMessage>(end);
auto o = flatbuffers::Offset<UserInput>(end);
return o;
}
};
inline flatbuffers::Offset<UserSubmittedMessage> CreateUserSubmittedMessage(
inline flatbuffers::Offset<UserInput> CreateUserInput(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> content = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> signature = 0) {
UserSubmittedMessageBuilder builder_(_fbb);
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> input_container = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> signature = 0,
uint8_t protocol = 0) {
UserInputBuilder builder_(_fbb);
builder_.add_signature(signature);
builder_.add_content(content);
builder_.add_input_container(input_container);
builder_.add_protocol(protocol);
return builder_.Finish();
}
inline flatbuffers::Offset<UserSubmittedMessage> CreateUserSubmittedMessageDirect(
inline flatbuffers::Offset<UserInput> CreateUserInputDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<uint8_t> *content = nullptr,
const std::vector<uint8_t> *signature = nullptr) {
auto content__ = content ? _fbb.CreateVector<uint8_t>(*content) : 0;
const std::vector<uint8_t> *input_container = nullptr,
const std::vector<uint8_t> *signature = nullptr,
uint8_t protocol = 0) {
auto input_container__ = input_container ? _fbb.CreateVector<uint8_t>(*input_container) : 0;
auto signature__ = signature ? _fbb.CreateVector<uint8_t>(*signature) : 0;
return fbschema::p2pmsg::CreateUserSubmittedMessage(
return msg::fbuf::p2pmsg::CreateUserInput(
_fbb,
content__,
signature__);
input_container__,
signature__,
protocol);
}
struct UserSubmittedMessageGroup FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef UserSubmittedMessageGroupBuilder Builder;
struct UserInputGroup FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef UserInputGroupBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_PUBKEY = 4,
VT_MESSAGES = 6
@@ -458,11 +474,11 @@ struct UserSubmittedMessageGroup FLATBUFFERS_FINAL_CLASS : private flatbuffers::
flatbuffers::Vector<uint8_t> *mutable_pubkey() {
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_PUBKEY);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>> *messages() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>> *>(VT_MESSAGES);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>> *messages() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>> *>(VT_MESSAGES);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>> *mutable_messages() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>> *>(VT_MESSAGES);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>> *mutable_messages() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>> *>(VT_MESSAGES);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
@@ -475,44 +491,44 @@ struct UserSubmittedMessageGroup FLATBUFFERS_FINAL_CLASS : private flatbuffers::
}
};
struct UserSubmittedMessageGroupBuilder {
typedef UserSubmittedMessageGroup Table;
struct UserInputGroupBuilder {
typedef UserInputGroup Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_pubkey(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> pubkey) {
fbb_.AddOffset(UserSubmittedMessageGroup::VT_PUBKEY, pubkey);
fbb_.AddOffset(UserInputGroup::VT_PUBKEY, pubkey);
}
void add_messages(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>>> messages) {
fbb_.AddOffset(UserSubmittedMessageGroup::VT_MESSAGES, messages);
void add_messages(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>>> messages) {
fbb_.AddOffset(UserInputGroup::VT_MESSAGES, messages);
}
explicit UserSubmittedMessageGroupBuilder(flatbuffers::FlatBufferBuilder &_fbb)
explicit UserInputGroupBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
start_ = fbb_.StartTable();
}
flatbuffers::Offset<UserSubmittedMessageGroup> Finish() {
flatbuffers::Offset<UserInputGroup> Finish() {
const auto end = fbb_.EndTable(start_);
auto o = flatbuffers::Offset<UserSubmittedMessageGroup>(end);
auto o = flatbuffers::Offset<UserInputGroup>(end);
return o;
}
};
inline flatbuffers::Offset<UserSubmittedMessageGroup> CreateUserSubmittedMessageGroup(
inline flatbuffers::Offset<UserInputGroup> CreateUserInputGroup(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> pubkey = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>>> messages = 0) {
UserSubmittedMessageGroupBuilder builder_(_fbb);
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>>> messages = 0) {
UserInputGroupBuilder builder_(_fbb);
builder_.add_messages(messages);
builder_.add_pubkey(pubkey);
return builder_.Finish();
}
inline flatbuffers::Offset<UserSubmittedMessageGroup> CreateUserSubmittedMessageGroupDirect(
inline flatbuffers::Offset<UserInputGroup> CreateUserInputGroupDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<uint8_t> *pubkey = nullptr,
const std::vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>> *messages = nullptr) {
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>> *messages = nullptr) {
auto pubkey__ = pubkey ? _fbb.CreateVector<uint8_t>(*pubkey) : 0;
auto messages__ = messages ? _fbb.CreateVector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessage>>(*messages) : 0;
return fbschema::p2pmsg::CreateUserSubmittedMessageGroup(
auto messages__ = messages ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInput>>(*messages) : 0;
return msg::fbuf::p2pmsg::CreateUserInputGroup(
_fbb,
pubkey__,
messages__);
@@ -524,39 +540,39 @@ struct Content FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
VT_MESSAGE_TYPE = 4,
VT_MESSAGE = 6
};
fbschema::p2pmsg::Message message_type() const {
return static_cast<fbschema::p2pmsg::Message>(GetField<uint8_t>(VT_MESSAGE_TYPE, 0));
msg::fbuf::p2pmsg::Message message_type() const {
return static_cast<msg::fbuf::p2pmsg::Message>(GetField<uint8_t>(VT_MESSAGE_TYPE, 0));
}
const void *message() const {
return GetPointer<const void *>(VT_MESSAGE);
}
template<typename T> const T *message_as() const;
const fbschema::p2pmsg::Peer_Challenge_Response_Message *message_as_Peer_Challenge_Response_Message() const {
return message_type() == fbschema::p2pmsg::Message_Peer_Challenge_Response_Message ? static_cast<const fbschema::p2pmsg::Peer_Challenge_Response_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::Peer_Challenge_Response_Message *message_as_Peer_Challenge_Response_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Peer_Challenge_Response_Message ? static_cast<const msg::fbuf::p2pmsg::Peer_Challenge_Response_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::Peer_Challenge_Message *message_as_Peer_Challenge_Message() const {
return message_type() == fbschema::p2pmsg::Message_Peer_Challenge_Message ? static_cast<const fbschema::p2pmsg::Peer_Challenge_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::Peer_Challenge_Message *message_as_Peer_Challenge_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Peer_Challenge_Message ? static_cast<const msg::fbuf::p2pmsg::Peer_Challenge_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::NonUnl_Proposal_Message *message_as_NonUnl_Proposal_Message() const {
return message_type() == fbschema::p2pmsg::Message_NonUnl_Proposal_Message ? static_cast<const fbschema::p2pmsg::NonUnl_Proposal_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::NonUnl_Proposal_Message *message_as_NonUnl_Proposal_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_NonUnl_Proposal_Message ? static_cast<const msg::fbuf::p2pmsg::NonUnl_Proposal_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::Proposal_Message *message_as_Proposal_Message() const {
return message_type() == fbschema::p2pmsg::Message_Proposal_Message ? static_cast<const fbschema::p2pmsg::Proposal_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::Proposal_Message *message_as_Proposal_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Proposal_Message ? static_cast<const msg::fbuf::p2pmsg::Proposal_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::Npl_Message *message_as_Npl_Message() const {
return message_type() == fbschema::p2pmsg::Message_Npl_Message ? static_cast<const fbschema::p2pmsg::Npl_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::Npl_Message *message_as_Npl_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_Npl_Message ? static_cast<const msg::fbuf::p2pmsg::Npl_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::State_Request_Message *message_as_State_Request_Message() const {
return message_type() == fbschema::p2pmsg::Message_State_Request_Message ? static_cast<const fbschema::p2pmsg::State_Request_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::State_Request_Message *message_as_State_Request_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_State_Request_Message ? static_cast<const msg::fbuf::p2pmsg::State_Request_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::State_Response_Message *message_as_State_Response_Message() const {
return message_type() == fbschema::p2pmsg::Message_State_Response_Message ? static_cast<const fbschema::p2pmsg::State_Response_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::State_Response_Message *message_as_State_Response_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_State_Response_Message ? static_cast<const msg::fbuf::p2pmsg::State_Response_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::History_Request_Message *message_as_History_Request_Message() const {
return message_type() == fbschema::p2pmsg::Message_History_Request_Message ? static_cast<const fbschema::p2pmsg::History_Request_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::History_Request_Message *message_as_History_Request_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_History_Request_Message ? static_cast<const msg::fbuf::p2pmsg::History_Request_Message *>(message()) : nullptr;
}
const fbschema::p2pmsg::History_Response_Message *message_as_History_Response_Message() const {
return message_type() == fbschema::p2pmsg::Message_History_Response_Message ? static_cast<const fbschema::p2pmsg::History_Response_Message *>(message()) : nullptr;
const msg::fbuf::p2pmsg::History_Response_Message *message_as_History_Response_Message() const {
return message_type() == msg::fbuf::p2pmsg::Message_History_Response_Message ? static_cast<const msg::fbuf::p2pmsg::History_Response_Message *>(message()) : nullptr;
}
void *mutable_message() {
return GetPointer<void *>(VT_MESSAGE);
@@ -570,39 +586,39 @@ struct Content FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
}
};
template<> inline const fbschema::p2pmsg::Peer_Challenge_Response_Message *Content::message_as<fbschema::p2pmsg::Peer_Challenge_Response_Message>() const {
template<> inline const msg::fbuf::p2pmsg::Peer_Challenge_Response_Message *Content::message_as<msg::fbuf::p2pmsg::Peer_Challenge_Response_Message>() const {
return message_as_Peer_Challenge_Response_Message();
}
template<> inline const fbschema::p2pmsg::Peer_Challenge_Message *Content::message_as<fbschema::p2pmsg::Peer_Challenge_Message>() const {
template<> inline const msg::fbuf::p2pmsg::Peer_Challenge_Message *Content::message_as<msg::fbuf::p2pmsg::Peer_Challenge_Message>() const {
return message_as_Peer_Challenge_Message();
}
template<> inline const fbschema::p2pmsg::NonUnl_Proposal_Message *Content::message_as<fbschema::p2pmsg::NonUnl_Proposal_Message>() const {
template<> inline const msg::fbuf::p2pmsg::NonUnl_Proposal_Message *Content::message_as<msg::fbuf::p2pmsg::NonUnl_Proposal_Message>() const {
return message_as_NonUnl_Proposal_Message();
}
template<> inline const fbschema::p2pmsg::Proposal_Message *Content::message_as<fbschema::p2pmsg::Proposal_Message>() const {
template<> inline const msg::fbuf::p2pmsg::Proposal_Message *Content::message_as<msg::fbuf::p2pmsg::Proposal_Message>() const {
return message_as_Proposal_Message();
}
template<> inline const fbschema::p2pmsg::Npl_Message *Content::message_as<fbschema::p2pmsg::Npl_Message>() const {
template<> inline const msg::fbuf::p2pmsg::Npl_Message *Content::message_as<msg::fbuf::p2pmsg::Npl_Message>() const {
return message_as_Npl_Message();
}
template<> inline const fbschema::p2pmsg::State_Request_Message *Content::message_as<fbschema::p2pmsg::State_Request_Message>() const {
template<> inline const msg::fbuf::p2pmsg::State_Request_Message *Content::message_as<msg::fbuf::p2pmsg::State_Request_Message>() const {
return message_as_State_Request_Message();
}
template<> inline const fbschema::p2pmsg::State_Response_Message *Content::message_as<fbschema::p2pmsg::State_Response_Message>() const {
template<> inline const msg::fbuf::p2pmsg::State_Response_Message *Content::message_as<msg::fbuf::p2pmsg::State_Response_Message>() const {
return message_as_State_Response_Message();
}
template<> inline const fbschema::p2pmsg::History_Request_Message *Content::message_as<fbschema::p2pmsg::History_Request_Message>() const {
template<> inline const msg::fbuf::p2pmsg::History_Request_Message *Content::message_as<msg::fbuf::p2pmsg::History_Request_Message>() const {
return message_as_History_Request_Message();
}
template<> inline const fbschema::p2pmsg::History_Response_Message *Content::message_as<fbschema::p2pmsg::History_Response_Message>() const {
template<> inline const msg::fbuf::p2pmsg::History_Response_Message *Content::message_as<msg::fbuf::p2pmsg::History_Response_Message>() const {
return message_as_History_Response_Message();
}
@@ -610,7 +626,7 @@ struct ContentBuilder {
typedef Content Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_message_type(fbschema::p2pmsg::Message message_type) {
void add_message_type(msg::fbuf::p2pmsg::Message message_type) {
fbb_.AddElement<uint8_t>(Content::VT_MESSAGE_TYPE, static_cast<uint8_t>(message_type), 0);
}
void add_message(flatbuffers::Offset<void> message) {
@@ -629,7 +645,7 @@ struct ContentBuilder {
inline flatbuffers::Offset<Content> CreateContent(
flatbuffers::FlatBufferBuilder &_fbb,
fbschema::p2pmsg::Message message_type = fbschema::p2pmsg::Message_NONE,
msg::fbuf::p2pmsg::Message message_type = msg::fbuf::p2pmsg::Message_NONE,
flatbuffers::Offset<void> message = 0) {
ContentBuilder builder_(_fbb);
builder_.add_message(message);
@@ -640,19 +656,19 @@ inline flatbuffers::Offset<Content> CreateContent(
struct NonUnl_Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
typedef NonUnl_Proposal_MessageBuilder Builder;
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_USERMESSAGES = 4
VT_USER_INPUTS = 4
};
const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>> *usermessages() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>> *>(VT_USERMESSAGES);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>> *user_inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>> *>(VT_USER_INPUTS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>> *mutable_usermessages() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>> *>(VT_USERMESSAGES);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>> *mutable_user_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>> *>(VT_USER_INPUTS);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
VerifyOffset(verifier, VT_USERMESSAGES) &&
verifier.VerifyVector(usermessages()) &&
verifier.VerifyVectorOfTables(usermessages()) &&
VerifyOffset(verifier, VT_USER_INPUTS) &&
verifier.VerifyVector(user_inputs()) &&
verifier.VerifyVectorOfTables(user_inputs()) &&
verifier.EndTable();
}
};
@@ -661,8 +677,8 @@ struct NonUnl_Proposal_MessageBuilder {
typedef NonUnl_Proposal_Message Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_usermessages(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>>> usermessages) {
fbb_.AddOffset(NonUnl_Proposal_Message::VT_USERMESSAGES, usermessages);
void add_user_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>>> user_inputs) {
fbb_.AddOffset(NonUnl_Proposal_Message::VT_USER_INPUTS, user_inputs);
}
explicit NonUnl_Proposal_MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
: fbb_(_fbb) {
@@ -677,19 +693,19 @@ struct NonUnl_Proposal_MessageBuilder {
inline flatbuffers::Offset<NonUnl_Proposal_Message> CreateNonUnl_Proposal_Message(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>>> usermessages = 0) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>>> user_inputs = 0) {
NonUnl_Proposal_MessageBuilder builder_(_fbb);
builder_.add_usermessages(usermessages);
builder_.add_user_inputs(user_inputs);
return builder_.Finish();
}
inline flatbuffers::Offset<NonUnl_Proposal_Message> CreateNonUnl_Proposal_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>> *usermessages = nullptr) {
auto usermessages__ = usermessages ? _fbb.CreateVector<flatbuffers::Offset<fbschema::p2pmsg::UserSubmittedMessageGroup>>(*usermessages) : 0;
return fbschema::p2pmsg::CreateNonUnl_Proposal_Message(
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>> *user_inputs = nullptr) {
auto user_inputs__ = user_inputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::p2pmsg::UserInputGroup>>(*user_inputs) : 0;
return msg::fbuf::p2pmsg::CreateNonUnl_Proposal_Message(
_fbb,
usermessages__);
user_inputs__);
}
struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
@@ -714,23 +730,23 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool mutate_time(uint64_t _time) {
return SetField<uint64_t>(VT_TIME, _time, 0);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *users() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_USERS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *users() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_USERS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_users() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_USERS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_users() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_USERS);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *hash_inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_HASH_INPUTS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *hash_inputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_HASH_INPUTS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_hash_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_HASH_INPUTS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_hash_inputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_HASH_INPUTS);
}
const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *hash_outputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_HASH_OUTPUTS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *hash_outputs() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_HASH_OUTPUTS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *mutable_hash_outputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>> *>(VT_HASH_OUTPUTS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *mutable_hash_outputs() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *>(VT_HASH_OUTPUTS);
}
const flatbuffers::Vector<uint8_t> *state() const {
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_STATE);
@@ -767,13 +783,13 @@ struct Proposal_MessageBuilder {
void add_time(uint64_t time) {
fbb_.AddElement<uint64_t>(Proposal_Message::VT_TIME, time, 0);
}
void add_users(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> users) {
void add_users(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> users) {
fbb_.AddOffset(Proposal_Message::VT_USERS, users);
}
void add_hash_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> hash_inputs) {
void add_hash_inputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> hash_inputs) {
fbb_.AddOffset(Proposal_Message::VT_HASH_INPUTS, hash_inputs);
}
void add_hash_outputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> hash_outputs) {
void add_hash_outputs(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> hash_outputs) {
fbb_.AddOffset(Proposal_Message::VT_HASH_OUTPUTS, hash_outputs);
}
void add_state(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state) {
@@ -794,9 +810,9 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_Message(
flatbuffers::FlatBufferBuilder &_fbb,
uint8_t stage = 0,
uint64_t time = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> users = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> hash_inputs = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::ByteArray>>> hash_outputs = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> users = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> hash_inputs = 0,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> hash_outputs = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> state = 0) {
Proposal_MessageBuilder builder_(_fbb);
builder_.add_time(time);
@@ -812,15 +828,15 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
uint8_t stage = 0,
uint64_t time = 0,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *users = nullptr,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *hash_inputs = nullptr,
const std::vector<flatbuffers::Offset<fbschema::ByteArray>> *hash_outputs = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *users = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *hash_inputs = nullptr,
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *hash_outputs = nullptr,
const std::vector<uint8_t> *state = nullptr) {
auto users__ = users ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*users) : 0;
auto hash_inputs__ = hash_inputs ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*hash_inputs) : 0;
auto hash_outputs__ = hash_outputs ? _fbb.CreateVector<flatbuffers::Offset<fbschema::ByteArray>>(*hash_outputs) : 0;
auto users__ = users ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*users) : 0;
auto hash_inputs__ = hash_inputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*hash_inputs) : 0;
auto hash_outputs__ = hash_outputs ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::ByteArray>>(*hash_outputs) : 0;
auto state__ = state ? _fbb.CreateVector<uint8_t>(*state) : 0;
return fbschema::p2pmsg::CreateProposal_Message(
return msg::fbuf::p2pmsg::CreateProposal_Message(
_fbb,
stage,
time,
@@ -879,7 +895,7 @@ inline flatbuffers::Offset<Npl_Message> CreateNpl_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<uint8_t> *data = nullptr) {
auto data__ = data ? _fbb.CreateVector<uint8_t>(*data) : 0;
return fbschema::p2pmsg::CreateNpl_Message(
return msg::fbuf::p2pmsg::CreateNpl_Message(
_fbb,
data__);
}
@@ -949,7 +965,7 @@ inline flatbuffers::Offset<History_Request_Message> CreateHistory_Request_Messag
const std::vector<uint8_t> *required_lcl = nullptr) {
auto minimum_lcl__ = minimum_lcl ? _fbb.CreateVector<uint8_t>(*minimum_lcl) : 0;
auto required_lcl__ = required_lcl ? _fbb.CreateVector<uint8_t>(*required_lcl) : 0;
return fbschema::p2pmsg::CreateHistory_Request_Message(
return msg::fbuf::p2pmsg::CreateHistory_Request_Message(
_fbb,
minimum_lcl__,
required_lcl__);
@@ -961,16 +977,16 @@ struct History_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::T
VT_HIST_LEDGERS = 4,
VT_ERROR = 6
};
const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>> *hist_ledgers() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>> *>(VT_HIST_LEDGERS);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>> *hist_ledgers() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>> *>(VT_HIST_LEDGERS);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>> *mutable_hist_ledgers() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>> *>(VT_HIST_LEDGERS);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>> *mutable_hist_ledgers() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>> *>(VT_HIST_LEDGERS);
}
fbschema::p2pmsg::Ledger_Response_Error error() const {
return static_cast<fbschema::p2pmsg::Ledger_Response_Error>(GetField<uint8_t>(VT_ERROR, 0));
msg::fbuf::p2pmsg::Ledger_Response_Error error() const {
return static_cast<msg::fbuf::p2pmsg::Ledger_Response_Error>(GetField<uint8_t>(VT_ERROR, 0));
}
bool mutate_error(fbschema::p2pmsg::Ledger_Response_Error _error) {
bool mutate_error(msg::fbuf::p2pmsg::Ledger_Response_Error _error) {
return SetField<uint8_t>(VT_ERROR, static_cast<uint8_t>(_error), 0);
}
bool Verify(flatbuffers::Verifier &verifier) const {
@@ -987,10 +1003,10 @@ struct History_Response_MessageBuilder {
typedef History_Response_Message Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_hist_ledgers(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>>> hist_ledgers) {
void add_hist_ledgers(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>>> hist_ledgers) {
fbb_.AddOffset(History_Response_Message::VT_HIST_LEDGERS, hist_ledgers);
}
void add_error(fbschema::p2pmsg::Ledger_Response_Error error) {
void add_error(msg::fbuf::p2pmsg::Ledger_Response_Error error) {
fbb_.AddElement<uint8_t>(History_Response_Message::VT_ERROR, static_cast<uint8_t>(error), 0);
}
explicit History_Response_MessageBuilder(flatbuffers::FlatBufferBuilder &_fbb)
@@ -1006,8 +1022,8 @@ struct History_Response_MessageBuilder {
inline flatbuffers::Offset<History_Response_Message> CreateHistory_Response_Message(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>>> hist_ledgers = 0,
fbschema::p2pmsg::Ledger_Response_Error error = fbschema::p2pmsg::Ledger_Response_Error_None) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>>> hist_ledgers = 0,
msg::fbuf::p2pmsg::Ledger_Response_Error error = msg::fbuf::p2pmsg::Ledger_Response_Error_None) {
History_Response_MessageBuilder builder_(_fbb);
builder_.add_hist_ledgers(hist_ledgers);
builder_.add_error(error);
@@ -1016,10 +1032,10 @@ inline flatbuffers::Offset<History_Response_Message> CreateHistory_Response_Mess
inline flatbuffers::Offset<History_Response_Message> CreateHistory_Response_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>> *hist_ledgers = nullptr,
fbschema::p2pmsg::Ledger_Response_Error error = fbschema::p2pmsg::Ledger_Response_Error_None) {
auto hist_ledgers__ = hist_ledgers ? _fbb.CreateVector<flatbuffers::Offset<fbschema::p2pmsg::HistoryLedgerPair>>(*hist_ledgers) : 0;
return fbschema::p2pmsg::CreateHistory_Response_Message(
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>> *hist_ledgers = nullptr,
msg::fbuf::p2pmsg::Ledger_Response_Error error = msg::fbuf::p2pmsg::Ledger_Response_Error_None) {
auto hist_ledgers__ = hist_ledgers ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedgerPair>>(*hist_ledgers) : 0;
return msg::fbuf::p2pmsg::CreateHistory_Response_Message(
_fbb,
hist_ledgers__,
error);
@@ -1037,11 +1053,11 @@ struct HistoryLedgerPair FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
bool mutate_seq_no(uint64_t _seq_no) {
return SetField<uint64_t>(VT_SEQ_NO, _seq_no, 0);
}
const fbschema::p2pmsg::HistoryLedger *ledger() const {
return GetPointer<const fbschema::p2pmsg::HistoryLedger *>(VT_LEDGER);
const msg::fbuf::p2pmsg::HistoryLedger *ledger() const {
return GetPointer<const msg::fbuf::p2pmsg::HistoryLedger *>(VT_LEDGER);
}
fbschema::p2pmsg::HistoryLedger *mutable_ledger() {
return GetPointer<fbschema::p2pmsg::HistoryLedger *>(VT_LEDGER);
msg::fbuf::p2pmsg::HistoryLedger *mutable_ledger() {
return GetPointer<msg::fbuf::p2pmsg::HistoryLedger *>(VT_LEDGER);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
@@ -1059,7 +1075,7 @@ struct HistoryLedgerPairBuilder {
void add_seq_no(uint64_t seq_no) {
fbb_.AddElement<uint64_t>(HistoryLedgerPair::VT_SEQ_NO, seq_no, 0);
}
void add_ledger(flatbuffers::Offset<fbschema::p2pmsg::HistoryLedger> ledger) {
void add_ledger(flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedger> ledger) {
fbb_.AddOffset(HistoryLedgerPair::VT_LEDGER, ledger);
}
explicit HistoryLedgerPairBuilder(flatbuffers::FlatBufferBuilder &_fbb)
@@ -1076,7 +1092,7 @@ struct HistoryLedgerPairBuilder {
inline flatbuffers::Offset<HistoryLedgerPair> CreateHistoryLedgerPair(
flatbuffers::FlatBufferBuilder &_fbb,
uint64_t seq_no = 0,
flatbuffers::Offset<fbschema::p2pmsg::HistoryLedger> ledger = 0) {
flatbuffers::Offset<msg::fbuf::p2pmsg::HistoryLedger> ledger = 0) {
HistoryLedgerPairBuilder builder_(_fbb);
builder_.add_seq_no(seq_no);
builder_.add_ledger(ledger);
@@ -1164,7 +1180,7 @@ inline flatbuffers::Offset<HistoryLedger> CreateHistoryLedgerDirect(
auto state__ = state ? _fbb.CreateVector<uint8_t>(*state) : 0;
auto lcl__ = lcl ? _fbb.CreateVector<uint8_t>(*lcl) : 0;
auto raw_ledger__ = raw_ledger ? _fbb.CreateVector<uint8_t>(*raw_ledger) : 0;
return fbschema::p2pmsg::CreateHistoryLedger(
return msg::fbuf::p2pmsg::CreateHistoryLedger(
_fbb,
state__,
lcl__,
@@ -1264,7 +1280,7 @@ inline flatbuffers::Offset<State_Request_Message> CreateState_Request_MessageDir
const std::vector<uint8_t> *expected_hash = nullptr) {
auto parent_path__ = parent_path ? _fbb.CreateString(parent_path) : 0;
auto expected_hash__ = expected_hash ? _fbb.CreateVector<uint8_t>(*expected_hash) : 0;
return fbschema::p2pmsg::CreateState_Request_Message(
return msg::fbuf::p2pmsg::CreateState_Request_Message(
_fbb,
parent_path__,
is_file,
@@ -1280,21 +1296,21 @@ struct State_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
VT_HASH = 8,
VT_PATH = 10
};
fbschema::p2pmsg::State_Response state_response_type() const {
return static_cast<fbschema::p2pmsg::State_Response>(GetField<uint8_t>(VT_STATE_RESPONSE_TYPE, 0));
msg::fbuf::p2pmsg::State_Response state_response_type() const {
return static_cast<msg::fbuf::p2pmsg::State_Response>(GetField<uint8_t>(VT_STATE_RESPONSE_TYPE, 0));
}
const void *state_response() const {
return GetPointer<const void *>(VT_STATE_RESPONSE);
}
template<typename T> const T *state_response_as() const;
const fbschema::p2pmsg::File_HashMap_Response *state_response_as_File_HashMap_Response() const {
return state_response_type() == fbschema::p2pmsg::State_Response_File_HashMap_Response ? static_cast<const fbschema::p2pmsg::File_HashMap_Response *>(state_response()) : nullptr;
const msg::fbuf::p2pmsg::File_HashMap_Response *state_response_as_File_HashMap_Response() const {
return state_response_type() == msg::fbuf::p2pmsg::State_Response_File_HashMap_Response ? static_cast<const msg::fbuf::p2pmsg::File_HashMap_Response *>(state_response()) : nullptr;
}
const fbschema::p2pmsg::Block_Response *state_response_as_Block_Response() const {
return state_response_type() == fbschema::p2pmsg::State_Response_Block_Response ? static_cast<const fbschema::p2pmsg::Block_Response *>(state_response()) : nullptr;
const msg::fbuf::p2pmsg::Block_Response *state_response_as_Block_Response() const {
return state_response_type() == msg::fbuf::p2pmsg::State_Response_Block_Response ? static_cast<const msg::fbuf::p2pmsg::Block_Response *>(state_response()) : nullptr;
}
const fbschema::p2pmsg::Fs_Entry_Response *state_response_as_Fs_Entry_Response() const {
return state_response_type() == fbschema::p2pmsg::State_Response_Fs_Entry_Response ? static_cast<const fbschema::p2pmsg::Fs_Entry_Response *>(state_response()) : nullptr;
const msg::fbuf::p2pmsg::Fs_Entry_Response *state_response_as_Fs_Entry_Response() const {
return state_response_type() == msg::fbuf::p2pmsg::State_Response_Fs_Entry_Response ? static_cast<const msg::fbuf::p2pmsg::Fs_Entry_Response *>(state_response()) : nullptr;
}
void *mutable_state_response() {
return GetPointer<void *>(VT_STATE_RESPONSE);
@@ -1324,15 +1340,15 @@ struct State_Response_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
}
};
template<> inline const fbschema::p2pmsg::File_HashMap_Response *State_Response_Message::state_response_as<fbschema::p2pmsg::File_HashMap_Response>() const {
template<> inline const msg::fbuf::p2pmsg::File_HashMap_Response *State_Response_Message::state_response_as<msg::fbuf::p2pmsg::File_HashMap_Response>() const {
return state_response_as_File_HashMap_Response();
}
template<> inline const fbschema::p2pmsg::Block_Response *State_Response_Message::state_response_as<fbschema::p2pmsg::Block_Response>() const {
template<> inline const msg::fbuf::p2pmsg::Block_Response *State_Response_Message::state_response_as<msg::fbuf::p2pmsg::Block_Response>() const {
return state_response_as_Block_Response();
}
template<> inline const fbschema::p2pmsg::Fs_Entry_Response *State_Response_Message::state_response_as<fbschema::p2pmsg::Fs_Entry_Response>() const {
template<> inline const msg::fbuf::p2pmsg::Fs_Entry_Response *State_Response_Message::state_response_as<msg::fbuf::p2pmsg::Fs_Entry_Response>() const {
return state_response_as_Fs_Entry_Response();
}
@@ -1340,7 +1356,7 @@ struct State_Response_MessageBuilder {
typedef State_Response_Message Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_state_response_type(fbschema::p2pmsg::State_Response state_response_type) {
void add_state_response_type(msg::fbuf::p2pmsg::State_Response state_response_type) {
fbb_.AddElement<uint8_t>(State_Response_Message::VT_STATE_RESPONSE_TYPE, static_cast<uint8_t>(state_response_type), 0);
}
void add_state_response(flatbuffers::Offset<void> state_response) {
@@ -1365,7 +1381,7 @@ struct State_Response_MessageBuilder {
inline flatbuffers::Offset<State_Response_Message> CreateState_Response_Message(
flatbuffers::FlatBufferBuilder &_fbb,
fbschema::p2pmsg::State_Response state_response_type = fbschema::p2pmsg::State_Response_NONE,
msg::fbuf::p2pmsg::State_Response state_response_type = msg::fbuf::p2pmsg::State_Response_NONE,
flatbuffers::Offset<void> state_response = 0,
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> hash = 0,
flatbuffers::Offset<flatbuffers::String> path = 0) {
@@ -1379,13 +1395,13 @@ inline flatbuffers::Offset<State_Response_Message> CreateState_Response_Message(
inline flatbuffers::Offset<State_Response_Message> CreateState_Response_MessageDirect(
flatbuffers::FlatBufferBuilder &_fbb,
fbschema::p2pmsg::State_Response state_response_type = fbschema::p2pmsg::State_Response_NONE,
msg::fbuf::p2pmsg::State_Response state_response_type = msg::fbuf::p2pmsg::State_Response_NONE,
flatbuffers::Offset<void> state_response = 0,
const std::vector<uint8_t> *hash = nullptr,
const char *path = nullptr) {
auto hash__ = hash ? _fbb.CreateVector<uint8_t>(*hash) : 0;
auto path__ = path ? _fbb.CreateString(path) : 0;
return fbschema::p2pmsg::CreateState_Response_Message(
return msg::fbuf::p2pmsg::CreateState_Response_Message(
_fbb,
state_response_type,
state_response,
@@ -1398,11 +1414,11 @@ struct Fs_Entry_Response FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ENTRIES = 4
};
const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>> *entries() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>> *>(VT_ENTRIES);
const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *entries() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *>(VT_ENTRIES);
}
flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>> *mutable_entries() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>> *>(VT_ENTRIES);
flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *mutable_entries() {
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *>(VT_ENTRIES);
}
bool Verify(flatbuffers::Verifier &verifier) const {
return VerifyTableStart(verifier) &&
@@ -1417,7 +1433,7 @@ struct Fs_Entry_ResponseBuilder {
typedef Fs_Entry_Response Table;
flatbuffers::FlatBufferBuilder &fbb_;
flatbuffers::uoffset_t start_;
void add_entries(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>>> entries) {
void add_entries(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>>> entries) {
fbb_.AddOffset(Fs_Entry_Response::VT_ENTRIES, entries);
}
explicit Fs_Entry_ResponseBuilder(flatbuffers::FlatBufferBuilder &_fbb)
@@ -1433,7 +1449,7 @@ struct Fs_Entry_ResponseBuilder {
inline flatbuffers::Offset<Fs_Entry_Response> CreateFs_Entry_Response(
flatbuffers::FlatBufferBuilder &_fbb,
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>>> entries = 0) {
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>>> entries = 0) {
Fs_Entry_ResponseBuilder builder_(_fbb);
builder_.add_entries(entries);
return builder_.Finish();
@@ -1441,9 +1457,9 @@ inline flatbuffers::Offset<Fs_Entry_Response> CreateFs_Entry_Response(
inline flatbuffers::Offset<Fs_Entry_Response> CreateFs_Entry_ResponseDirect(
flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>> *entries = nullptr) {
auto entries__ = entries ? _fbb.CreateVector<flatbuffers::Offset<fbschema::p2pmsg::State_FS_Hash_Entry>>(*entries) : 0;
return fbschema::p2pmsg::CreateFs_Entry_Response(
const std::vector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>> *entries = nullptr) {
auto entries__ = entries ? _fbb.CreateVector<flatbuffers::Offset<msg::fbuf::p2pmsg::State_FS_Hash_Entry>>(*entries) : 0;
return msg::fbuf::p2pmsg::CreateFs_Entry_Response(
_fbb,
entries__);
}
@@ -1511,7 +1527,7 @@ inline flatbuffers::Offset<File_HashMap_Response> CreateFile_HashMap_ResponseDir
uint64_t file_length = 0,
const std::vector<uint8_t> *hash_map = nullptr) {
auto hash_map__ = hash_map ? _fbb.CreateVector<uint8_t>(*hash_map) : 0;
return fbschema::p2pmsg::CreateFile_HashMap_Response(
return msg::fbuf::p2pmsg::CreateFile_HashMap_Response(
_fbb,
file_length,
hash_map__);
@@ -1580,7 +1596,7 @@ inline flatbuffers::Offset<Block_Response> CreateBlock_ResponseDirect(
uint32_t block_id = 0,
const std::vector<uint8_t> *data = nullptr) {
auto data__ = data ? _fbb.CreateVector<uint8_t>(*data) : 0;
return fbschema::p2pmsg::CreateBlock_Response(
return msg::fbuf::p2pmsg::CreateBlock_Response(
_fbb,
block_id,
data__);
@@ -1665,7 +1681,7 @@ inline flatbuffers::Offset<State_FS_Hash_Entry> CreateState_FS_Hash_EntryDirect(
const std::vector<uint8_t> *hash = nullptr) {
auto name__ = name ? _fbb.CreateString(name) : 0;
auto hash__ = hash ? _fbb.CreateVector<uint8_t>(*hash) : 0;
return fbschema::p2pmsg::CreateState_FS_Hash_Entry(
return msg::fbuf::p2pmsg::CreateState_FS_Hash_Entry(
_fbb,
name__,
is_file,
@@ -1678,39 +1694,39 @@ inline bool VerifyMessage(flatbuffers::Verifier &verifier, const void *obj, Mess
return true;
}
case Message_Peer_Challenge_Response_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::Peer_Challenge_Response_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Peer_Challenge_Response_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_Peer_Challenge_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::Peer_Challenge_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Peer_Challenge_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_NonUnl_Proposal_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::NonUnl_Proposal_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::NonUnl_Proposal_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_Proposal_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::Proposal_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Proposal_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_Npl_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::Npl_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Npl_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_State_Request_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::State_Request_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::State_Request_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_State_Response_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::State_Response_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::State_Response_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_History_Request_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::History_Request_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::History_Request_Message *>(obj);
return verifier.VerifyTable(ptr);
}
case Message_History_Response_Message: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::History_Response_Message *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::History_Response_Message *>(obj);
return verifier.VerifyTable(ptr);
}
default: return true;
@@ -1735,15 +1751,15 @@ inline bool VerifyState_Response(flatbuffers::Verifier &verifier, const void *ob
return true;
}
case State_Response_File_HashMap_Response: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::File_HashMap_Response *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::File_HashMap_Response *>(obj);
return verifier.VerifyTable(ptr);
}
case State_Response_Block_Response: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::Block_Response *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Block_Response *>(obj);
return verifier.VerifyTable(ptr);
}
case State_Response_Fs_Entry_Response: {
auto ptr = reinterpret_cast<const fbschema::p2pmsg::Fs_Entry_Response *>(obj);
auto ptr = reinterpret_cast<const msg::fbuf::p2pmsg::Fs_Entry_Response *>(obj);
return verifier.VerifyTable(ptr);
}
default: return true;
@@ -1762,12 +1778,12 @@ inline bool VerifyState_ResponseVector(flatbuffers::Verifier &verifier, const fl
return true;
}
inline const fbschema::p2pmsg::Content *GetContent(const void *buf) {
return flatbuffers::GetRoot<fbschema::p2pmsg::Content>(buf);
inline const msg::fbuf::p2pmsg::Content *GetContent(const void *buf) {
return flatbuffers::GetRoot<msg::fbuf::p2pmsg::Content>(buf);
}
inline const fbschema::p2pmsg::Content *GetSizePrefixedContent(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<fbschema::p2pmsg::Content>(buf);
inline const msg::fbuf::p2pmsg::Content *GetSizePrefixedContent(const void *buf) {
return flatbuffers::GetSizePrefixedRoot<msg::fbuf::p2pmsg::Content>(buf);
}
inline Content *GetMutableContent(void *buf) {
@@ -1776,27 +1792,28 @@ inline Content *GetMutableContent(void *buf) {
inline bool VerifyContentBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifyBuffer<fbschema::p2pmsg::Content>(nullptr);
return verifier.VerifyBuffer<msg::fbuf::p2pmsg::Content>(nullptr);
}
inline bool VerifySizePrefixedContentBuffer(
flatbuffers::Verifier &verifier) {
return verifier.VerifySizePrefixedBuffer<fbschema::p2pmsg::Content>(nullptr);
return verifier.VerifySizePrefixedBuffer<msg::fbuf::p2pmsg::Content>(nullptr);
}
inline void FinishContentBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<fbschema::p2pmsg::Content> root) {
flatbuffers::Offset<msg::fbuf::p2pmsg::Content> root) {
fbb.Finish(root);
}
inline void FinishSizePrefixedContentBuffer(
flatbuffers::FlatBufferBuilder &fbb,
flatbuffers::Offset<fbschema::p2pmsg::Content> root) {
flatbuffers::Offset<msg::fbuf::p2pmsg::Content> root) {
fbb.FinishSizePrefixed(root);
}
} // namespace p2pmsg
} // namespace fbschema
} // namespace fbuf
} // namespace msg
#endif // FLATBUFFERS_GENERATED_P2PMSGCONTENT_FBSCHEMA_P2PMSG_H_
#endif // FLATBUFFERS_GENERATED_P2PMSGCONTENT_MSG_FBUF_P2PMSG_H_

View File

@@ -1,17 +1,17 @@
#include "../pchheader.hpp"
#include "../conf.hpp"
#include "../crypto.hpp"
#include "../util.hpp"
#include "../hplog.hpp"
#include "../p2p/p2p.hpp"
#include "../hpfs/h32.hpp"
#include "../hpfs/hpfs.hpp"
#include "../../pchheader.hpp"
#include "../../conf.hpp"
#include "../../crypto.hpp"
#include "../../util.hpp"
#include "../../hplog.hpp"
#include "../../p2p/p2p.hpp"
#include "../../hpfs/h32.hpp"
#include "../../hpfs/hpfs.hpp"
#include "p2pmsg_container_generated.h"
#include "p2pmsg_content_generated.h"
#include "common_helpers.hpp"
#include "p2pmsg_helpers.hpp"
namespace fbschema::p2pmsg
namespace msg::fbuf::p2pmsg
{
// Length of a peer connection challange.
@@ -186,8 +186,8 @@ namespace fbschema::p2pmsg
{
p2p::nonunl_proposal nup;
if (msg.usermessages())
nup.user_messages = flatbuf_usermsgsmap_to_usermsgsmap(msg.usermessages());
if (msg.user_inputs())
nup.user_inputs = flatbuf_user_input_group_to_user_input_map(msg.user_inputs());
return nup;
}
@@ -331,7 +331,7 @@ namespace fbschema::p2pmsg
const flatbuffers::Offset<NonUnl_Proposal_Message> nupmsg =
CreateNonUnl_Proposal_Message(
builder,
usermsgsmap_to_flatbuf_usermsgsmap(builder, nup.user_messages));
user_input_map_to_flatbuf_user_input_group(builder, nup.user_inputs));
const flatbuffers::Offset<Content> message = CreateContent(builder, Message_NonUnl_Proposal_Message, nupmsg.Union());
builder.Finish(message); // Finished building message content to get serialised content.
@@ -613,23 +613,24 @@ namespace fbschema::p2pmsg
//---Conversion helpers from flatbuffers data types to std data types---//
const std::unordered_map<std::string, const std::list<usr::user_submitted_message>>
flatbuf_usermsgsmap_to_usermsgsmap(const flatbuffers::Vector<flatbuffers::Offset<UserSubmittedMessageGroup>> *fbvec)
const std::unordered_map<std::string, const std::list<usr::user_input>>
flatbuf_user_input_group_to_user_input_map(const flatbuffers::Vector<flatbuffers::Offset<UserInputGroup>> *fbvec)
{
std::unordered_map<std::string, const std::list<usr::user_submitted_message>> map;
std::unordered_map<std::string, const std::list<usr::user_input>> map;
map.reserve(fbvec->size());
for (const UserSubmittedMessageGroup *group : *fbvec)
for (const UserInputGroup *group : *fbvec)
{
std::list<usr::user_submitted_message> msglist;
std::list<usr::user_input> user_inputs_list;
for (const auto msg : *group->messages())
{
msglist.push_back(usr::user_submitted_message(
flatbuff_bytes_to_sv(msg->content()),
flatbuff_bytes_to_sv(msg->signature())));
user_inputs_list.push_back(usr::user_input(
flatbuff_bytes_to_sv(msg->input_container()),
flatbuff_bytes_to_sv(msg->signature()),
static_cast<util::PROTOCOL>(msg->protocol())));
}
map.emplace(flatbuff_bytes_to_sv(group->pubkey()), std::move(msglist));
map.emplace(flatbuff_bytes_to_sv(group->pubkey()), std::move(user_inputs_list));
}
return map;
}
@@ -637,23 +638,24 @@ namespace fbschema::p2pmsg
//---Conversion helpers from std data types to flatbuffers data types---//
//---These are used in constructing Flatbuffer messages using builders---//
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<UserSubmittedMessageGroup>>>
usermsgsmap_to_flatbuf_usermsgsmap(flatbuffers::FlatBufferBuilder &builder, const std::unordered_map<std::string, const std::list<usr::user_submitted_message>> &map)
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<UserInputGroup>>>
user_input_map_to_flatbuf_user_input_group(flatbuffers::FlatBufferBuilder &builder, const std::unordered_map<std::string, const std::list<usr::user_input>> &map)
{
std::vector<flatbuffers::Offset<UserSubmittedMessageGroup>> fbvec;
std::vector<flatbuffers::Offset<UserInputGroup>> fbvec;
fbvec.reserve(map.size());
for (const auto &[pubkey, msglist] : map)
{
std::vector<flatbuffers::Offset<UserSubmittedMessage>> fbmsgsvec;
for (const usr::user_submitted_message &msg : msglist)
std::vector<flatbuffers::Offset<UserInput>> fbmsgsvec;
for (const usr::user_input &msg : msglist)
{
fbmsgsvec.push_back(CreateUserSubmittedMessage(
fbmsgsvec.push_back(CreateUserInput(
builder,
sv_to_flatbuff_bytes(builder, msg.content),
sv_to_flatbuff_bytes(builder, msg.sig)));
sv_to_flatbuff_bytes(builder, msg.input_container),
sv_to_flatbuff_bytes(builder, msg.sig),
static_cast<uint8_t>(msg.protocol)));
}
fbvec.push_back(CreateUserSubmittedMessageGroup(
fbvec.push_back(CreateUserInputGroup(
builder,
sv_to_flatbuff_bytes(builder, pubkey),
builder.CreateVector(fbmsgsvec)));
@@ -668,7 +670,7 @@ namespace fbschema::p2pmsg
for (const HistoryLedgerPair *pair : *fbvec)
{
std::list<usr::user_submitted_message> msglist;
std::list<usr::user_input> msglist;
p2p::history_ledger ledger;
@@ -735,4 +737,4 @@ namespace fbschema::p2pmsg
return builder.CreateVector(fbvec);
}
} // namespace fbschema::p2pmsg
} // namespace msg::fbuf::p2pmsg

View File

@@ -1,14 +1,14 @@
#ifndef _HP_FBSCHEMA_P2PMSG_HELPERS_
#define _HP_FBSCHEMA_P2PMSG_HELPERS_
#ifndef _HP_MSG_FBUF_P2PMSG_HELPERS_
#define _HP_MSG_FBUF_P2PMSG_HELPERS_
#include "../pchheader.hpp"
#include "../../pchheader.hpp"
#include "../../p2p/p2p.hpp"
#include "../../hpfs/h32.hpp"
#include "../../hpfs/hpfs.hpp"
#include "p2pmsg_container_generated.h"
#include "p2pmsg_content_generated.h"
#include "../p2p/p2p.hpp"
#include "../hpfs/h32.hpp"
#include "../hpfs/hpfs.hpp"
namespace fbschema::p2pmsg
namespace msg::fbuf::p2pmsg
{
/**
* This section contains Flatbuffer p2p message reading/writing helpers.
@@ -70,13 +70,13 @@ namespace fbschema::p2pmsg
//---Conversion helpers from flatbuffers data types to std data types---//
const std::unordered_map<std::string, const std::list<usr::user_submitted_message>>
flatbuf_usermsgsmap_to_usermsgsmap(const flatbuffers::Vector<flatbuffers::Offset<UserSubmittedMessageGroup>> *fbvec);
const std::unordered_map<std::string, const std::list<usr::user_input>>
flatbuf_user_input_group_to_user_input_map(const flatbuffers::Vector<flatbuffers::Offset<UserInputGroup>> *fbvec);
//---Conversion helpers from std data types to flatbuffers data types---//
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<UserSubmittedMessageGroup>>>
usermsgsmap_to_flatbuf_usermsgsmap(flatbuffers::FlatBufferBuilder &builder, const std::unordered_map<std::string, const std::list<usr::user_submitted_message>> &map);
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<UserInputGroup>>>
user_input_map_to_flatbuf_user_input_group(flatbuffers::FlatBufferBuilder &builder, const std::unordered_map<std::string, const std::list<usr::user_input>> &map);
const std::map<uint64_t, const p2p::history_ledger>
flatbuf_historyledgermap_to_historyledgermap(const flatbuffers::Vector<flatbuffers::Offset<HistoryLedgerPair>> *fbvec);
@@ -95,6 +95,6 @@ namespace fbschema::p2pmsg
flatbuffers::FlatBufferBuilder &builder,
std::vector<hpfs::child_hash_node> &hash_nodes);
} // namespace fbschema::p2pmsg
} // namespace msg::fbuf::p2pmsg
#endif

View File

@@ -1,36 +1,25 @@
#include "../pchheader.hpp"
#include "../util.hpp"
#include "../crypto.hpp"
#include "../cons/cons.hpp"
#include "../hplog.hpp"
#include "usrmsg_helpers.hpp"
#include "../../pchheader.hpp"
#include "../../util.hpp"
#include "../../crypto.hpp"
#include "../../cons/cons.hpp"
#include "../../hplog.hpp"
#include "../usrmsg_common.hpp"
#include "usrmsg_json.hpp"
namespace jsonschema::usrmsg
namespace msg::usrmsg::json
{
// Separators
// JSON separators
constexpr const char *SEP_COMMA = "\",\"";
constexpr const char *SEP_COLON = "\":\"";
constexpr const char *SEP_COMMA_NOQUOTE = ",\"";
constexpr const char *SEP_COLON_NOQUOTE = "\":";
// Message field names
constexpr const char *FLD_TYPE = "type";
constexpr const char *FLD_CHALLENGE = "challenge";
constexpr const char *FLD_SIG = "sig";
constexpr const char *FLD_PUBKEY = "pubkey";
constexpr const char *FLD_INPUT = "input";
constexpr const char *FLD_INPUT_CONTAINER = "input_container";
constexpr const char *FLD_INPUT_SIG = "input_sig";
constexpr const char *FLD_MAX_LCL_SEQ = "max_lcl_seqno";
constexpr const char *FLD_CONTENT = "content";
constexpr const char *FLD_NONCE = "nonce";
constexpr const char *FLD_LCL = "lcl";
constexpr const char *FLD_LCL_SEQ = "lcl_seqno";
constexpr const char *FLD_STATUS = "status";
constexpr const char *FLD_REASON = "reason";
// Length of user random challenge bytes.
const size_t CHALLENGE_LEN = 16;
// std::vector overload to concatonate string.
std::vector<uint8_t> &operator+=(std::vector<uint8_t> &vec, std::string_view sv)
{
vec.insert(vec.end(), sv.begin(), sv.end());
return vec;
}
/**
* Constructs user challenge message json and the challenge string required for
@@ -45,16 +34,16 @@ namespace jsonschema::usrmsg
* }
* @param challengehex String reference to copy the generated hex challenge string into.
*/
void create_user_challenge(std::string &msg, std::string &challengehex)
void create_user_challenge(std::vector<uint8_t> &msg, std::string &challengehex)
{
// Use libsodium to generate the random challenge bytes.
unsigned char challenge_bytes[CHALLENGE_LEN];
randombytes_buf(challenge_bytes, CHALLENGE_LEN);
unsigned char challenge_bytes[msg::usrmsg::CHALLENGE_LEN];
randombytes_buf(challenge_bytes, msg::usrmsg::CHALLENGE_LEN);
// We pass the hex challenge string separately to the caller even though
// we also include it in the challenge msg as well.
util::bin2hex(challengehex, challenge_bytes, CHALLENGE_LEN);
util::bin2hex(challengehex, challenge_bytes, msg::usrmsg::CHALLENGE_LEN);
// Construct the challenge msg json.
// We do not use RapidJson here in favour of performance because this is a simple json message.
@@ -63,15 +52,15 @@ namespace jsonschema::usrmsg
// Only Hot Pocket version number is variable length. Therefore message size is roughly 90 bytes
// so allocating 128bytes for heap padding.
msg.reserve(128);
msg.append("{\"")
.append(FLD_TYPE)
.append(SEP_COLON)
.append(MSGTYPE_HANDSHAKE_CHALLENGE)
.append(SEP_COMMA)
.append(FLD_CHALLENGE)
.append(SEP_COLON)
.append(challengehex)
.append("\"}");
msg += "{\"";
msg += msg::usrmsg::FLD_TYPE;
msg += SEP_COLON;
msg += msg::usrmsg::MSGTYPE_HANDSHAKE_CHALLENGE;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_CHALLENGE;
msg += SEP_COLON;
msg += challengehex;
msg += "\"}";
}
/**
@@ -84,22 +73,22 @@ namespace jsonschema::usrmsg
* "lcl_seqno": <integer>
* }
*/
void create_status_response(std::string &msg)
void create_status_response(std::vector<uint8_t> &msg)
{
msg.reserve(128);
msg.append("{\"")
.append(FLD_TYPE)
.append(SEP_COLON)
.append(MSGTYPE_STAT_RESPONSE)
.append(SEP_COMMA)
.append(FLD_LCL)
.append(SEP_COLON)
.append(cons::ctx.lcl)
.append(SEP_COMMA)
.append(FLD_LCL_SEQ)
.append(SEP_COLON_NOQUOTE)
.append(std::to_string(cons::ctx.led_seq_no))
.append("}");
msg += "{\"";
msg += msg::usrmsg::FLD_TYPE;
msg += SEP_COLON;
msg += msg::usrmsg::MSGTYPE_STAT_RESPONSE;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_LCL;
msg += SEP_COLON;
msg += cons::ctx.lcl;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_LCL_SEQ;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(cons::ctx.led_seq_no);
msg += "}";
}
/**
@@ -116,29 +105,29 @@ namespace jsonschema::usrmsg
* @param reason Rejected reason. Empty if accepted.
* @param input_sig Binary signature of the original input message which generated this result.
*/
void create_contract_input_status(std::string &msg, std::string_view status, std::string_view reason, std::string_view input_sig)
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status, std::string_view reason, std::string_view input_sig)
{
std::string sighex;
util::bin2hex(sighex, reinterpret_cast<const unsigned char *>(input_sig.data()), input_sig.length());
msg.reserve(128);
msg.append("{\"")
.append(FLD_TYPE)
.append(SEP_COLON)
.append(MSGTYPE_CONTRACT_INPUT_STATUS)
.append(SEP_COMMA)
.append(FLD_STATUS)
.append(SEP_COLON)
.append(status)
.append(SEP_COMMA)
.append(FLD_REASON)
.append(SEP_COLON)
.append(reason)
.append(SEP_COMMA)
.append(FLD_INPUT_SIG)
.append(SEP_COLON)
.append(sighex)
.append("\"}");
msg += "{\"";
msg += msg::usrmsg::FLD_TYPE;
msg += SEP_COLON;
msg += msg::usrmsg::MSGTYPE_CONTRACT_INPUT_STATUS;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_STATUS;
msg += SEP_COLON;
msg += status;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_REASON;
msg += SEP_COLON;
msg += reason;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_INPUT_SIG;
msg += SEP_COLON;
msg += sighex;
msg += "\"}";
}
/**
@@ -151,7 +140,7 @@ namespace jsonschema::usrmsg
* }
* @param content The contract binary output content to be put in the message.
*/
void create_contract_read_response_container(std::string &msg, std::string_view content)
void create_contract_read_response_container(std::vector<uint8_t> &msg, std::string_view content)
{
std::string contenthex;
util::bin2hex(
@@ -160,15 +149,15 @@ namespace jsonschema::usrmsg
content.length());
msg.reserve(256);
msg.append("{\"")
.append(FLD_TYPE)
.append(SEP_COLON)
.append(MSGTYPE_CONTRACT_READ_RESPONSE)
.append(SEP_COMMA)
.append(FLD_CONTENT)
.append(SEP_COLON)
.append(contenthex)
.append("\"}");
msg += "{\"";
msg += msg::usrmsg::FLD_TYPE;
msg += SEP_COLON;
msg += msg::usrmsg::MSGTYPE_CONTRACT_READ_RESPONSE;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_CONTENT;
msg += SEP_COLON;
msg += contenthex;
msg += "\"}";
}
/**
@@ -183,7 +172,7 @@ namespace jsonschema::usrmsg
* }
* @param content The contract binary output content to be put in the message.
*/
void create_contract_output_container(std::string &msg, std::string_view content)
void create_contract_output_container(std::vector<uint8_t> &msg, std::string_view content)
{
std::string contenthex;
util::bin2hex(
@@ -192,80 +181,98 @@ namespace jsonschema::usrmsg
content.length());
msg.reserve(256);
msg.append("{\"")
.append(FLD_TYPE)
.append(SEP_COLON)
.append(MSGTYPE_CONTRACT_OUTPUT)
.append(SEP_COMMA)
.append(FLD_LCL)
.append(SEP_COLON)
.append(cons::ctx.lcl)
.append(SEP_COMMA)
.append(FLD_LCL_SEQ)
.append(SEP_COLON_NOQUOTE)
.append(std::to_string(cons::ctx.led_seq_no))
.append(SEP_COMMA_NOQUOTE)
.append(FLD_CONTENT)
.append(SEP_COLON)
.append(contenthex)
.append("\"}");
msg += "{\"";
msg += msg::usrmsg::FLD_TYPE;
msg += SEP_COLON;
msg += msg::usrmsg::MSGTYPE_CONTRACT_OUTPUT;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_LCL;
msg += SEP_COLON;
msg += cons::ctx.lcl;
msg += SEP_COMMA;
msg += msg::usrmsg::FLD_LCL_SEQ;
msg += SEP_COLON_NOQUOTE;
msg += std::to_string(cons::ctx.led_seq_no);
msg += SEP_COMMA_NOQUOTE;
msg += msg::usrmsg::FLD_CONTENT;
msg += SEP_COLON;
msg += contenthex;
msg += "\"}";
}
/**
* Verifies the user challenge response with the original challenge issued to the user
* Verifies the user handshake response with the original challenge issued to the user
* and the user public key contained in the response.
*
* @param extracted_pubkeyhex The hex public key extracted from the response.
* @param extracted_pubkeyhex The hex public key extracted from the response.
* @param extracted_protocol The protocol code extracted from the response.
* @param response The response bytes to verify. This will be parsed as json.
* Accepted response format:
* {
* "type": "challenge_resp",
* "type": "handshake_response",
* "challenge": "<original hex challenge the user received>",
* "sig": "<hex signature of the challenge>",
* "pubkey": "<hex public key of the user>"
* "pubkey": "<hex public key of the user>",
* "protocol": "<json | bson>"
* }
* @param original_challenge The original hex 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(std::string &extracted_pubkeyhex, std::string_view response, std::string_view original_challenge)
int verify_user_handshake_response(std::string &extracted_pubkeyhex, std::string &extracted_protocol,
std::string_view response, std::string_view original_challenge)
{
rapidjson::Document d;
if (parse_user_message(d, response) != 0)
return -1;
// Validate msg type.
if (d[FLD_TYPE] != MSGTYPE_HANDSHAKE_RESPONSE)
if (d[msg::usrmsg::FLD_TYPE] != msg::usrmsg::MSGTYPE_HANDSHAKE_RESPONSE)
{
LOG_DBG << "User challenge response type invalid. 'challenge_response' expected.";
LOG_DBG << "User handshake response type invalid. 'handshake_response' expected.";
return -1;
}
// Compare the response challenge string with the original issued challenge.
if (!d.HasMember(FLD_CHALLENGE) || d[FLD_CHALLENGE] != original_challenge.data())
// Compare the response handshake string with the original issued challenge.
if (!d.HasMember(msg::usrmsg::FLD_CHALLENGE) || d[msg::usrmsg::FLD_CHALLENGE] != original_challenge.data())
{
LOG_DBG << "User challenge response challenge invalid.";
LOG_DBG << "User handshake response 'challenge' invalid.";
return -1;
}
// Check for the 'sig' field existence.
if (!d.HasMember(FLD_SIG) || !d[FLD_SIG].IsString())
if (!d.HasMember(msg::usrmsg::FLD_SIG) || !d[msg::usrmsg::FLD_SIG].IsString())
{
LOG_DBG << "User challenge response signature invalid.";
LOG_DBG << "User handshake response 'challenge signature' invalid.";
return -1;
}
// Check for the 'pubkey' field existence.
if (!d.HasMember(FLD_PUBKEY) || !d[FLD_PUBKEY].IsString())
if (!d.HasMember(msg::usrmsg::FLD_PUBKEY) || !d[msg::usrmsg::FLD_PUBKEY].IsString())
{
LOG_DBG << "User challenge response public key invalid.";
LOG_DBG << "User handshake response 'public key' invalid.";
return -1;
}
// Check for protocol field existence and valid value.
if (!d.HasMember(msg::usrmsg::FLD_PROTOCOL) || !d[msg::usrmsg::FLD_PROTOCOL].IsString())
{
LOG_DBG << "User handshake response 'protocol' invalid.";
return -1;
}
std::string_view protocolsv = util::getsv(d[msg::usrmsg::FLD_PROTOCOL]);
if (protocolsv != "json" && protocolsv != "bson")
{
LOG_DBG << "User handshake response 'protocol' type invalid.";
return -1;
}
// Verify the challenge signature. We do this last due to signature verification cost.
std::string_view pubkeysv = util::getsv(d[FLD_PUBKEY]);
std::string_view pubkeysv = util::getsv(d[msg::usrmsg::FLD_PUBKEY]);
if (crypto::verify_hex(
original_challenge,
util::getsv(d[FLD_SIG]),
util::getsv(d[msg::usrmsg::FLD_SIG]),
pubkeysv) != 0)
{
LOG_DBG << "User challenge response signature verification failed.";
@@ -273,10 +280,53 @@ namespace jsonschema::usrmsg
}
extracted_pubkeyhex = pubkeysv;
extracted_protocol = protocolsv;
return 0;
}
/**
* Parses a json message sent by a user.
* @param d RapidJson document to which the parsed json should be loaded.
* @param message The message to parse.
* Accepted message format:
* {
* 'type': '<message type>'
* ...
* }
* @return 0 on successful parsing. -1 for failure.
*/
int parse_user_message(rapidjson::Document &d, std::string_view message)
{
// We load response raw bytes into json document.
// Because we project the response message directly from the binary socket buffer in a zero-copy manner, the response
// string is not null terminated. 'kParseStopWhenDoneFlag' avoids rapidjson error in this case.
d.Parse<rapidjson::kParseStopWhenDoneFlag>(message.data());
if (d.HasParseError())
{
LOG_DBG << "User json message parsing failed.";
return -1;
}
// Check existence of msg type field.
if (!d.HasMember(msg::usrmsg::FLD_TYPE) || !d[msg::usrmsg::FLD_TYPE].IsString())
{
LOG_DBG << "User json message 'type' missing or invalid.";
return -1;
}
return 0;
}
/**
* Extracts the message 'type' value from the json document.
*/
int extract_type(std::string &extracted_type, const rapidjson::Document &d)
{
extracted_type = d[msg::usrmsg::FLD_TYPE].GetString();
return 0;
}
/**
* Extracts a contract read request message sent by user.
*
@@ -291,20 +341,20 @@ namespace jsonschema::usrmsg
*/
int extract_read_request(std::string &extracted_content, const rapidjson::Document &d)
{
if (!d.HasMember(FLD_CONTENT))
if (!d.HasMember(msg::usrmsg::FLD_CONTENT))
{
LOG_DBG << "Read request required fields missing.";
return -1;
}
if (!d[FLD_CONTENT].IsString())
if (!d[msg::usrmsg::FLD_CONTENT].IsString())
{
LOG_DBG << "Read request invalid field values.";
return -1;
}
std::string_view contenthex(d[FLD_CONTENT].GetString(), d[FLD_CONTENT].GetStringLength());
std::string_view contenthex(d[msg::usrmsg::FLD_CONTENT].GetString(), d[msg::usrmsg::FLD_CONTENT].GetStringLength());
std::string content;
content.resize(contenthex.length() / 2);
if (util::hex2bin(
@@ -329,7 +379,7 @@ namespace jsonschema::usrmsg
* Accepted signed input container format:
* {
* "type": "contract_input",
* "input_container": "<stringified json input container message>",
* "input_container": "<hex encoded stringified json input container message>",
* "sig": "<hex encoded signature of the content>"
* }
* @return 0 on successful extraction. -1 for failure.
@@ -337,13 +387,13 @@ namespace jsonschema::usrmsg
int extract_signed_input_container(
std::string &extracted_input_container, std::string &extracted_sig, const rapidjson::Document &d)
{
if (!d.HasMember(FLD_INPUT_CONTAINER) || !d.HasMember(FLD_SIG))
if (!d.HasMember(msg::usrmsg::FLD_INPUT_CONTAINER) || !d.HasMember(msg::usrmsg::FLD_SIG))
{
LOG_DBG << "User signed input required fields missing.";
return -1;
}
if (!d[FLD_INPUT_CONTAINER].IsString() || !d[FLD_SIG].IsString())
if (!d[msg::usrmsg::FLD_INPUT_CONTAINER].IsString() || !d[msg::usrmsg::FLD_SIG].IsString())
{
LOG_DBG << "User signed input invalid field values.";
return -1;
@@ -352,12 +402,15 @@ namespace jsonschema::usrmsg
// We do not verify the signature of the content here since we need to let each node
// (including self) to verify that individually after we broadcast the NUP proposal.
const std::string input_container(d[FLD_INPUT_CONTAINER].GetString(), d[FLD_INPUT_CONTAINER].GetStringLength());
const std::string_view input_container_hex(d[msg::usrmsg::FLD_INPUT_CONTAINER].GetString(), d[msg::usrmsg::FLD_INPUT_CONTAINER].GetStringLength());
std::string input_container;
input_container.resize(input_container_hex.size() / 2);
util::hex2bin(reinterpret_cast<unsigned char *>(input_container.data()), input_container.length(), input_container_hex);
const std::string_view sighex(d[FLD_SIG].GetString(), d[FLD_SIG].GetStringLength());
const std::string_view sig_hex(d[msg::usrmsg::FLD_SIG].GetString(), d[msg::usrmsg::FLD_SIG].GetStringLength());
std::string sig;
sig.resize(crypto_sign_ed25519_BYTES);
util::hex2bin(reinterpret_cast<unsigned char *>(sig.data()), sig.length(), sighex);
util::hex2bin(reinterpret_cast<unsigned char *>(sig.data()), sig.length(), sig_hex);
extracted_input_container = std::move(input_container);
extracted_sig = std::move(sig);
@@ -387,19 +440,19 @@ namespace jsonschema::usrmsg
return -1;
}
if (!d.HasMember(FLD_NONCE) || !d.HasMember(FLD_INPUT) || !d.HasMember(FLD_MAX_LCL_SEQ))
if (!d.HasMember(msg::usrmsg::FLD_INPUT) || !d.HasMember(msg::usrmsg::FLD_NONCE) || !d.HasMember(msg::usrmsg::FLD_MAX_LCL_SEQ))
{
LOG_DBG << "User input container required fields missing.";
return -1;
}
if (!d[FLD_NONCE].IsString() || !d[FLD_INPUT].IsString() || !d[FLD_MAX_LCL_SEQ].IsUint64())
if (!d[msg::usrmsg::FLD_INPUT].IsString() || !d[msg::usrmsg::FLD_NONCE].IsString() || !d[msg::usrmsg::FLD_MAX_LCL_SEQ].IsUint64())
{
LOG_DBG << "User input container invalid field values.";
return -1;
}
const rapidjson::Value &inputval = d[FLD_INPUT];
const rapidjson::Value &inputval = d[msg::usrmsg::FLD_INPUT];
std::string_view inputhex(inputval.GetString(), inputval.GetStringLength());
// Convert hex input to binary.
@@ -413,43 +466,10 @@ namespace jsonschema::usrmsg
return -1;
}
nonce = d[FLD_NONCE].GetString();
max_lcl_seqno = d[FLD_MAX_LCL_SEQ].GetUint64();
nonce = d[msg::usrmsg::FLD_NONCE].GetString();
max_lcl_seqno = d[msg::usrmsg::FLD_MAX_LCL_SEQ].GetUint64();
return 0;
}
/**
* Parses a json message sent by a user.
* @param d RapidJson document to which the parsed json should be loaded.
* @param message The message to parse.
* Accepted message format:
* {
* 'type': '<message type>'
* ...
* }
* @return 0 on successful parsing. -1 for failure.
*/
int parse_user_message(rapidjson::Document &d, std::string_view message)
{
// We load response raw bytes into json document.
// Because we project the response message directly from the binary socket buffer in a zero-copy manner, the response
// string is not null terminated. 'kParseStopWhenDoneFlag' avoids rapidjson error in this case.
d.Parse<rapidjson::kParseStopWhenDoneFlag>(message.data());
if (d.HasParseError())
{
LOG_DBG << "User json message parsing failed.";
return -1;
}
// Check existence of msg type field.
if (!d.HasMember(FLD_TYPE) || !d[FLD_TYPE].IsString())
{
LOG_DBG << "User json message 'type' missing or invalid.";
return -1;
}
return 0;
}
} // namespace jsonschema::usrmsg
} // namespace msg::usrmsg::json

View File

@@ -0,0 +1,37 @@
#ifndef _HP_MSG_JSON_USRMSG_JSON_
#define _HP_MSG_JSON_USRMSG_JSON_
#include "../../pchheader.hpp"
namespace msg::usrmsg::json
{
void create_user_challenge(std::vector<uint8_t> &msg, std::string &challengehex);
void create_status_response(std::vector<uint8_t> &msg);
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status, std::string_view reason,
std::string_view input_sig);
void create_contract_read_response_container(std::vector<uint8_t> &msg, std::string_view content);
void create_contract_output_container(std::vector<uint8_t> &msg, std::string_view content);
int verify_user_handshake_response(std::string &extracted_pubkeyhex, std::string &extracted_protocol,
std::string_view response, std::string_view original_challenge);
int parse_user_message(rapidjson::Document &d, std::string_view message);
int extract_type(std::string &extracted_type, const rapidjson::Document &d);
int extract_read_request(std::string &extracted_content, const rapidjson::Document &d);
int extract_signed_input_container(std::string &extracted_input_container, std::string &extracted_sig,
const rapidjson::Document &d);
int extract_input_container(std::string &input, std::string &nonce,
uint64_t &max_lcl_seqno, std::string_view contentjson);
} // namespace msg::usrmsg::json
#endif

52
src/msg/usrmsg_common.hpp Normal file
View File

@@ -0,0 +1,52 @@
#ifndef _HP_MSG_USRMSG_COMMON_
#define _HP_MSG_USRMSG_COMMON_
#include "../pchheader.hpp"
namespace msg::usrmsg
{
// Length of user random challenge bytes.
constexpr size_t CHALLENGE_LEN = 16;
// Message field names
constexpr const char *FLD_TYPE = "type";
constexpr const char *FLD_CHALLENGE = "challenge";
constexpr const char *FLD_SIG = "sig";
constexpr const char *FLD_PUBKEY = "pubkey";
constexpr const char *FLD_PROTOCOL = "protocol";
constexpr const char *FLD_INPUT = "input";
constexpr const char *FLD_INPUT_CONTAINER = "input_container";
constexpr const char *FLD_INPUT_SIG = "input_sig";
constexpr const char *FLD_MAX_LCL_SEQ = "max_lcl_seqno";
constexpr const char *FLD_CONTENT = "content";
constexpr const char *FLD_NONCE = "nonce";
constexpr const char *FLD_LCL = "lcl";
constexpr const char *FLD_LCL_SEQ = "lcl_seqno";
constexpr const char *FLD_STATUS = "status";
constexpr const char *FLD_REASON = "reason";
// Message types
constexpr const char *MSGTYPE_HANDSHAKE_CHALLENGE = "handshake_challenge";
constexpr const char *MSGTYPE_HANDSHAKE_RESPONSE = "handshake_response";
constexpr const char *MSGTYPE_CONTRACT_READ_REQUEST = "contract_read_request";
constexpr const char *MSGTYPE_CONTRACT_READ_RESPONSE = "contract_read_response";
constexpr const char *MSGTYPE_CONTRACT_INPUT = "contract_input";
constexpr const char *MSGTYPE_CONTRACT_INPUT_STATUS = "contract_input_status";
constexpr const char *MSGTYPE_CONTRACT_OUTPUT = "contract_output";
constexpr const char *MSGTYPE_STAT = "stat";
constexpr const char *MSGTYPE_STAT_RESPONSE = "stat_response";
constexpr const char *MSGTYPE_UNKNOWN = "unknown";
// Values
constexpr const char *STATUS_ACCEPTED = "accepted";
constexpr const char *STATUS_REJECTED = "rejected";
constexpr const char *REASON_BAD_MSG_FORMAT = "bad_msg_format";
constexpr const char *REASON_INVALID_MSG_TYPE = "invalid_msg_type";
constexpr const char *REASON_DUPLICATE_MSG = "dup_msg";
constexpr const char *REASON_BAD_SIG = "bad_sig";
constexpr const char *REASON_APPBILL_BALANCE_EXCEEDED = "appbill_balance_exceeded";
constexpr const char *REASON_MAX_LEDGER_EXPIRED = "max_ledger_expired";
} // namespace msg::usrmsg
#endif

90
src/msg/usrmsg_parser.cpp Normal file
View File

@@ -0,0 +1,90 @@
#include "../pchheader.hpp"
#include "../util.hpp"
#include "json/usrmsg_json.hpp"
#include "bson/usrmsg_bson.hpp"
#include "usrmsg_parser.hpp"
namespace jusrmsg = msg::usrmsg::json;
namespace busrmsg = msg::usrmsg::bson;
namespace msg::usrmsg
{
usrmsg_parser::usrmsg_parser(const util::PROTOCOL protocol) : protocol(protocol)
{
}
void usrmsg_parser::create_status_response(std::vector<uint8_t> &msg) const
{
if (protocol == util::PROTOCOL::JSON)
jusrmsg::create_status_response(msg);
else
busrmsg::create_status_response(msg);
}
void usrmsg_parser::create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status,
std::string_view reason, std::string_view input_sig) const
{
if (protocol == util::PROTOCOL::JSON)
jusrmsg::create_contract_input_status(msg, status, reason, input_sig);
else
busrmsg::create_contract_input_status(msg, status, reason, input_sig);
}
void usrmsg_parser::create_contract_read_response_container(std::vector<uint8_t> &msg, std::string_view content) const
{
if (protocol == util::PROTOCOL::JSON)
jusrmsg::create_contract_read_response_container(msg, content);
else
busrmsg::create_contract_read_response_container(msg, content);
}
void usrmsg_parser::create_contract_output_container(std::vector<uint8_t> &msg, std::string_view content) const
{
if (protocol == util::PROTOCOL::JSON)
jusrmsg::create_contract_output_container(msg, content);
else
busrmsg::create_contract_output_container(msg, content);
}
int usrmsg_parser::parse(std::string_view message)
{
if (protocol == util::PROTOCOL::JSON)
return jusrmsg::parse_user_message(jsonDoc, message);
else
return busrmsg::parse_user_message(bsonDoc, message);
}
int usrmsg_parser::extract_type(std::string &extracted_type) const
{
if (protocol == util::PROTOCOL::JSON)
return jusrmsg::extract_type(extracted_type, jsonDoc);
else
return busrmsg::extract_type(extracted_type, bsonDoc);
}
int usrmsg_parser::extract_read_request(std::string &extracted_content) const
{
if (protocol == util::PROTOCOL::JSON)
return jusrmsg::extract_read_request(extracted_content, jsonDoc);
else
return busrmsg::extract_read_request(extracted_content, bsonDoc);
}
int usrmsg_parser::extract_signed_input_container(std::string &extracted_input_container, std::string &extracted_sig) const
{
if (protocol == util::PROTOCOL::JSON)
return jusrmsg::extract_signed_input_container(extracted_input_container, extracted_sig, jsonDoc);
else
return busrmsg::extract_signed_input_container(extracted_input_container, extracted_sig, bsonDoc);
}
int usrmsg_parser::extract_input_container(std::string &input, std::string &nonce,
uint64_t &max_lcl_seqno, std::string_view encoded_content) const
{
if (protocol == util::PROTOCOL::JSON)
return jusrmsg::extract_input_container(input, nonce, max_lcl_seqno, encoded_content);
else
return busrmsg::extract_input_container(input, nonce, max_lcl_seqno, encoded_content);
}
} // namespace msg::usrmsg

44
src/msg/usrmsg_parser.hpp Normal file
View File

@@ -0,0 +1,44 @@
#ifndef _HP_MSG_USRMSG_PARSER_
#define _HP_MSG_USRMSG_PARSER_
#include "../util.hpp"
#include "../pchheader.hpp"
namespace msg::usrmsg
{
// Forward declaration
class usrmsg_parser;
class usrmsg_parser
{
const util::PROTOCOL protocol;
rapidjson::Document jsonDoc;
jsoncons::ojson bsonDoc;
public:
usrmsg_parser(const util::PROTOCOL protocol);
void create_status_response(std::vector<uint8_t> &msg) const;
void create_contract_input_status(std::vector<uint8_t> &msg, std::string_view status,
std::string_view reason, std::string_view input_sig) const;
void create_contract_read_response_container(std::vector<uint8_t> &msg, std::string_view content) const;
void create_contract_output_container(std::vector<uint8_t> &msg, std::string_view content) const;
int parse(std::string_view message);
int extract_type(std::string &extracted_type) const;
int extract_read_request(std::string &extracted_content) const;
int extract_signed_input_container(std::string &extracted_input_container, std::string &extracted_sig) const;
int extract_input_container(std::string &input, std::string &nonce,
uint64_t &max_lcl_seqno, std::string_view encoded_content) const;
};
} // namespace msg::usrmsg
#endif

View File

@@ -28,7 +28,7 @@ namespace p2p
struct nonunl_proposal
{
std::unordered_map<std::string, const std::list<usr::user_submitted_message>> user_messages;
std::unordered_map<std::string, const std::list<usr::user_input>> user_inputs;
};
struct history_request

View File

@@ -3,10 +3,10 @@
#include "../crypto.hpp"
#include "../util.hpp"
#include "../hplog.hpp"
#include "../fbschema/p2pmsg_container_generated.h"
#include "../fbschema/p2pmsg_content_generated.h"
#include "../fbschema/p2pmsg_helpers.hpp"
#include "../fbschema/common_helpers.hpp"
#include "../msg/fbuf/p2pmsg_container_generated.h"
#include "../msg/fbuf/p2pmsg_content_generated.h"
#include "../msg/fbuf/p2pmsg_helpers.hpp"
#include "../msg/fbuf/common_helpers.hpp"
#include "../comm/comm_session.hpp"
#include "../comm/comm_client.hpp"
#include "p2p.hpp"
@@ -15,7 +15,7 @@
#include "../state/state_sync.hpp"
#include "../cons/cons.hpp"
namespace p2pmsg = fbschema::p2pmsg;
namespace p2pmsg = msg::fbuf::p2pmsg;
namespace p2p
{

View File

@@ -30,6 +30,8 @@
#include <fstream>
#include <iomanip>
#include <iostream>
#include <jsoncons/json.hpp>
#include <jsoncons_ext/bson/bson.hpp>
#include <libgen.h>
#include <list>
#include <math.h>

View File

@@ -1,9 +1,9 @@
#include "pchheader.hpp"
#include "conf.hpp"
#include "hplog.hpp"
#include "fbschema/common_helpers.hpp"
#include "fbschema/p2pmsg_container_generated.h"
#include "fbschema/p2pmsg_content_generated.h"
#include "msg/fbuf/common_helpers.hpp"
#include "msg/fbuf/p2pmsg_container_generated.h"
#include "msg/fbuf/p2pmsg_content_generated.h"
#include "sc.hpp"
#include "hpfs/hpfs.hpp"
@@ -555,7 +555,7 @@ namespace sc
uint8_t reserve = 0;
//Get message container
const fbschema::p2pmsg::Container *container = fbschema::p2pmsg::GetContainer(input.data());
const msg::fbuf::p2pmsg::Container *container = msg::fbuf::p2pmsg::GetContainer(input.data());
const flatbuffers::Vector<uint8_t> *container_content = container->content();
uint16_t msg_length = container_content->size();
@@ -576,7 +576,7 @@ namespace sc
memsegs[pre_header_index].iov_base = &pre_header;
memsegs[pre_header_index].iov_len = 4;
std::string_view msg_pubkey = fbschema::flatbuff_bytes_to_sv(container->pubkey());
std::string_view msg_pubkey = msg::fbuf::flatbuff_bytes_to_sv(container->pubkey());
memsegs[pubkey_index].iov_base = reinterpret_cast<void *>(const_cast<char *>(msg_pubkey.data()));
memsegs[pubkey_index].iov_len = msg_pubkey.size();

View File

@@ -3,15 +3,15 @@
#include "../hpfs/h32.hpp"
#include "../util.hpp"
#include "../p2p/p2p.hpp"
#include "../fbschema/p2pmsg_content_generated.h"
#include "../fbschema/p2pmsg_helpers.hpp"
#include "../fbschema/common_helpers.hpp"
#include "../msg/fbuf/p2pmsg_content_generated.h"
#include "../msg/fbuf/p2pmsg_helpers.hpp"
#include "../msg/fbuf/common_helpers.hpp"
#include "../cons/cons.hpp"
#include "../hplog.hpp"
#include "state_serve.hpp"
#include "state_common.hpp"
namespace p2pmsg = fbschema::p2pmsg;
namespace p2pmsg = msg::fbuf::p2pmsg;
/**
* Helper functions for serving state requests from other peers.
@@ -70,7 +70,7 @@ namespace state_serve
if (is_shutting_down)
break;
const fbschema::p2pmsg::Content *content = fbschema::p2pmsg::GetContent(request.data());
const msg::fbuf::p2pmsg::Content *content = msg::fbuf::p2pmsg::GetContent(request.data());
const p2p::state_request sr = p2pmsg::create_state_request_from_msg(*content->message_as_State_Request_Message());
flatbuffers::FlatBufferBuilder fbuf(1024);
@@ -132,7 +132,7 @@ namespace state_serve
resp.hash = sr.expected_hash;
resp.data = std::string_view(reinterpret_cast<const char *>(block.data()), block.size());
fbschema::p2pmsg::create_msg_from_block_response(fbuf, resp, cons::ctx.lcl);
msg::fbuf::p2pmsg::create_msg_from_block_response(fbuf, resp, cons::ctx.lcl);
}
else
{
@@ -147,7 +147,7 @@ namespace state_serve
return -1;
}
fbschema::p2pmsg::create_msg_from_filehashmap_response(
msg::fbuf::p2pmsg::create_msg_from_filehashmap_response(
fbuf, sr.parent_path, block_hashes,
file_length, sr.expected_hash, cons::ctx.lcl);
}
@@ -162,7 +162,7 @@ namespace state_serve
return -1;
}
fbschema::p2pmsg::create_msg_from_fsentry_response(
msg::fbuf::p2pmsg::create_msg_from_fsentry_response(
fbuf, sr.parent_path, child_hash_nodes, sr.expected_hash, cons::ctx.lcl);
}
}

View File

@@ -4,7 +4,7 @@
#include "../hpfs/h32.hpp"
#include "../hpfs/hpfs.hpp"
#include "../p2p/p2p.hpp"
#include "../fbschema/p2pmsg_content_generated.h"
#include "../msg/fbuf/p2pmsg_content_generated.h"
namespace state_serve
{

View File

@@ -1,6 +1,6 @@
#include "../fbschema/p2pmsg_helpers.hpp"
#include "../fbschema/p2pmsg_content_generated.h"
#include "../fbschema/common_helpers.hpp"
#include "../msg/fbuf/p2pmsg_helpers.hpp"
#include "../msg/fbuf/p2pmsg_content_generated.h"
#include "../msg/fbuf/common_helpers.hpp"
#include "../p2p/p2p.hpp"
#include "../pchheader.hpp"
#include "../cons/cons.hpp"
@@ -159,12 +159,12 @@ namespace state_sync
if (should_stop_request_loop(current_target))
return;
const fbschema::p2pmsg::Content *content = fbschema::p2pmsg::GetContent(response.data());
const fbschema::p2pmsg::State_Response_Message *resp_msg = content->message_as_State_Response_Message();
const msg::fbuf::p2pmsg::Content *content = msg::fbuf::p2pmsg::GetContent(response.data());
const msg::fbuf::p2pmsg::State_Response_Message *resp_msg = content->message_as_State_Response_Message();
// Check whether we are actually waiting for this response. If not, ignore it.
std::string_view hash = fbschema::flatbuff_bytes_to_sv(resp_msg->hash());
std::string_view vpath = fbschema::flatbuff_str_to_sv(resp_msg->path());
std::string_view hash = msg::fbuf::flatbuff_bytes_to_sv(resp_msg->hash());
std::string_view vpath = msg::fbuf::flatbuff_str_to_sv(resp_msg->path());
const std::string key = std::string(vpath).append(hash);
const auto pending_resp_itr = ctx.submitted_requests.find(key);
@@ -178,13 +178,13 @@ namespace state_sync
ctx.submitted_requests.erase(pending_resp_itr);
// Process the message based on response type.
const fbschema::p2pmsg::State_Response msg_type = resp_msg->state_response_type();
const msg::fbuf::p2pmsg::State_Response msg_type = resp_msg->state_response_type();
if (msg_type == fbschema::p2pmsg::State_Response_Fs_Entry_Response)
if (msg_type == msg::fbuf::p2pmsg::State_Response_Fs_Entry_Response)
handle_fs_entry_response(vpath, resp_msg->state_response_as_Fs_Entry_Response());
else if (msg_type == fbschema::p2pmsg::State_Response_File_HashMap_Response)
else if (msg_type == msg::fbuf::p2pmsg::State_Response_File_HashMap_Response)
handle_file_hashmap_response(vpath, resp_msg->state_response_as_File_HashMap_Response());
else if (msg_type == fbschema::p2pmsg::State_Response_Block_Response)
else if (msg_type == msg::fbuf::p2pmsg::State_Response_Block_Response)
handle_file_block_response(vpath, resp_msg->state_response_as_Block_Response());
// After handling each response, check whether we have reached target state.
@@ -262,7 +262,7 @@ namespace state_sync
sr.expected_hash = expected_hash;
flatbuffers::FlatBufferBuilder fbuf(1024);
fbschema::p2pmsg::create_msg_from_state_request(fbuf, sr, cons::ctx.lcl);
msg::fbuf::p2pmsg::create_msg_from_state_request(fbuf, sr, cons::ctx.lcl);
p2p::send_message_to_random_peer(fbuf); //todo: send to a node that hold the majority state to improve reliability of retrieving state.
}
@@ -286,14 +286,14 @@ namespace state_sync
/**
* Process dir children response.
*/
int handle_fs_entry_response(std::string_view parent_vpath, const fbschema::p2pmsg::Fs_Entry_Response *fs_entry_resp)
int handle_fs_entry_response(std::string_view parent_vpath, const msg::fbuf::p2pmsg::Fs_Entry_Response *fs_entry_resp)
{
// Get the parent path of the fs entries we have received.
LOG_DBG << "State sync: Processing fs entries response for " << parent_vpath;
// Get fs entries we have received.
std::unordered_map<std::string, p2p::state_fs_hash_entry> peer_fs_entry_map;
fbschema::p2pmsg::flatbuf_statefshashentry_to_statefshashentry(peer_fs_entry_map, fs_entry_resp->entries());
msg::fbuf::p2pmsg::flatbuf_statefshashentry_to_statefshashentry(peer_fs_entry_map, fs_entry_resp->entries());
// Create physical directory on our side if not exist.
std::string parent_physical_path = std::string(ctx.hpfs_mount_dir).append(parent_vpath);
@@ -362,7 +362,7 @@ namespace state_sync
/**
* Process file block hash map response.
*/
int handle_file_hashmap_response(std::string_view file_vpath, const fbschema::p2pmsg::File_HashMap_Response *file_resp)
int handle_file_hashmap_response(std::string_view file_vpath, const msg::fbuf::p2pmsg::File_HashMap_Response *file_resp)
{
// Get the file path of the block hashes we have received.
LOG_DBG << "State sync: Processing file block hashes response for " << file_vpath;
@@ -401,11 +401,11 @@ namespace state_sync
/**
* Process file block response.
*/
int handle_file_block_response(std::string_view file_vpath, const fbschema::p2pmsg::Block_Response *block_msg)
int handle_file_block_response(std::string_view file_vpath, const msg::fbuf::p2pmsg::Block_Response *block_msg)
{
// Get the file path of the block data we have received.
const uint32_t block_id = block_msg->block_id();
std::string_view buf = fbschema::flatbuff_bytes_to_sv(block_msg->data());
std::string_view buf = msg::fbuf::flatbuff_bytes_to_sv(block_msg->data());
LOG_DBG << "State sync: Writing block_id " << block_id
<< " (len:" << buf.length()

View File

@@ -3,7 +3,7 @@
#include "../pchheader.hpp"
#include "../p2p/p2p.hpp"
#include "../fbschema/p2pmsg_content_generated.h"
#include "../msg/fbuf/p2pmsg_content_generated.h"
#include "../hpfs/h32.hpp"
namespace state_sync
@@ -72,11 +72,11 @@ namespace state_sync
void submit_request(const backlog_item &request);
int handle_fs_entry_response(std::string_view parent_vpath, const fbschema::p2pmsg::Fs_Entry_Response *fs_entry_resp);
int handle_fs_entry_response(std::string_view parent_vpath, const msg::fbuf::p2pmsg::Fs_Entry_Response *fs_entry_resp);
int handle_file_hashmap_response(std::string_view file_vpath, const fbschema::p2pmsg::File_HashMap_Response *file_resp);
int handle_file_hashmap_response(std::string_view file_vpath, const msg::fbuf::p2pmsg::File_HashMap_Response *file_resp);
int handle_file_block_response(std::string_view file_vpath, const fbschema::p2pmsg::Block_Response *block_msg);
int handle_file_block_response(std::string_view file_vpath, const msg::fbuf::p2pmsg::Block_Response *block_msg);
} // namespace state_sync

View File

@@ -3,12 +3,10 @@
#include "../util.hpp"
#include "../sc.hpp"
#include "../conf.hpp"
#include "../jsonschema/usrmsg_helpers.hpp"
#include "../msg/usrmsg_parser.hpp"
#include "usr.hpp"
#include "read_req.hpp"
namespace jusrmsg = jsonschema::usrmsg;
/**
* Helper functions for serving read requests from users.
*/
@@ -97,10 +95,12 @@ namespace read_req
std::string outputtosend;
outputtosend.swap(bufpair.output);
std::string msg;
jusrmsg::create_contract_read_response_container(msg, outputtosend);
const usr::connected_user &user = user_itr->second;
msg::usrmsg::usrmsg_parser parser(user.protocol);
std::vector<uint8_t> msg;
parser.create_contract_read_response_container(msg, outputtosend);
user.session.send(msg);
dispatch_count++;
}

View File

@@ -2,6 +2,7 @@
#define _HP_USR_USER_INPUT_
#include "../pchheader.hpp"
#include "../util.hpp"
namespace usr
{
@@ -9,18 +10,19 @@ namespace usr
/**
* Represents a signed contract input message a network user has submitted.
*/
struct user_submitted_message
struct user_input
{
const std::string content;
const std::string input_container;
const std::string sig;
const util::PROTOCOL protocol; // The encoding protocol used for the input container.
user_submitted_message(const std::string content, const std::string sig)
: content(std::move(content)), sig(std::move(sig))
user_input(const std::string input_container, const std::string sig, const util::PROTOCOL protocol)
: input_container(std::move(input_container)), sig(std::move(sig)), protocol(protocol)
{
}
user_submitted_message(std::string_view content, std::string_view sig)
: content(content), sig(sig)
user_input(std::string_view input_container, std::string_view sig, const util::PROTOCOL protocol)
: input_container(input_container), sig(sig), protocol(protocol)
{
}
};

View File

@@ -1,11 +1,11 @@
#include "../pchheader.hpp"
#include "../hplog.hpp"
#include "../jsonschema/usrmsg_helpers.hpp"
#include "../msg/json/usrmsg_json.hpp"
#include "../bill/corebill.h"
#include "usr.hpp"
#include "user_session_handler.hpp"
namespace jusrmsg = jsonschema::usrmsg;
namespace jusrmsg = msg::usrmsg::json;
namespace usr
{
@@ -25,9 +25,9 @@ int user_session_handler::on_connect(comm::comm_session &session) const
// As soon as a user connects, we issue them a challenge message. We remember the
// challenge we issued and later verify the user's response with it.
std::string msgstr;
jusrmsg::create_user_challenge(msgstr, session.issued_challenge);
session.send(msgstr);
std::vector<uint8_t> msg;
jusrmsg::create_user_challenge(msg, session.issued_challenge);
session.send(msg);
// Set the challenge-issued value to true.
session.challenge_status = comm::CHALLENGE_ISSUED;

View File

@@ -1,5 +1,7 @@
#include "../pchheader.hpp"
#include "../jsonschema/usrmsg_helpers.hpp"
#include "../msg/json/usrmsg_json.hpp"
#include "../msg/usrmsg_parser.hpp"
#include "../msg/usrmsg_common.hpp"
#include "../comm/comm_server.hpp"
#include "../comm/comm_session.hpp"
#include "../util.hpp"
@@ -10,8 +12,6 @@
#include "user_session_handler.hpp"
#include "user_input.hpp"
namespace jusrmsg = jsonschema::usrmsg;
namespace usr
{
@@ -78,8 +78,10 @@ namespace usr
}
std::string userpubkeyhex;
std::string protocol_code;
std::string_view original_challenge = session.issued_challenge;
if (jusrmsg::verify_user_challenge_response(userpubkeyhex, message, original_challenge) == 0)
if (msg::usrmsg::json::verify_user_handshake_response(userpubkeyhex, protocol_code, message, original_challenge) == 0)
{
// Challenge signature verification successful.
@@ -98,8 +100,10 @@ namespace usr
// All good. Unique public key.
// Promote the connection from pending-challenges to authenticated users.
const util::PROTOCOL user_protocol = (protocol_code == "json" ? util::PROTOCOL::JSON : util::PROTOCOL::BSON);
session.challenge_status = comm::CHALLENGE_VERIFIED; // Set as challenge verified
add_user(session, userpubkey); // Add the user to the global authed user list
add_user(session, userpubkey, user_protocol); // Add the user to the global authed user list
session.issued_challenge.clear(); // Remove the stored challenge
LOG_DBG << "User connection " << session.uniqueid << " authenticated. Public key "
@@ -127,17 +131,17 @@ namespace usr
*/
int handle_user_message(connected_user &user, std::string_view message)
{
rapidjson::Document d;
const char *msg_type = jusrmsg::MSGTYPE_UNKNOWN;
msg::usrmsg::usrmsg_parser parser(user.protocol);
if (jusrmsg::parse_user_message(d, message) == 0)
if (parser.parse(message) == 0)
{
const char *msg_type = d[jusrmsg::FLD_TYPE].GetString();
std::string msg_type;
parser.extract_type(msg_type);
if (d[jusrmsg::FLD_TYPE] == jusrmsg::MSGTYPE_CONTRACT_READ_REQUEST)
if (msg_type == msg::usrmsg::MSGTYPE_CONTRACT_READ_REQUEST)
{
std::string content;
if (jusrmsg::extract_read_request(content, d) == 0)
if (parser.extract_read_request(content) == 0)
{
std::lock_guard<std::mutex> lock(ctx.users_mutex);
@@ -147,50 +151,51 @@ namespace usr
}
else
{
send_input_status(user.session, jusrmsg::STATUS_REJECTED, jusrmsg::REASON_BAD_MSG_FORMAT, "");
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, msg::usrmsg::REASON_BAD_MSG_FORMAT, "");
return -1;
}
}
else if (d[jusrmsg::FLD_TYPE] == jusrmsg::MSGTYPE_CONTRACT_INPUT)
else if (msg_type == msg::usrmsg::MSGTYPE_CONTRACT_INPUT)
{
// Message is a contract input message.
std::string input_container_json;
std::string input_container;
std::string sig;
if (jusrmsg::extract_signed_input_container(input_container_json, sig, d) == 0)
if (parser.extract_signed_input_container(input_container, sig) == 0)
{
std::lock_guard<std::mutex> lock(ctx.users_mutex);
//Add to the submitted input list.
user.submitted_inputs.push_back(user_submitted_message(
std::move(input_container_json),
std::move(sig)));
user.submitted_inputs.push_back(user_input(
std::move(input_container),
std::move(sig),
user.protocol));
return 0;
}
else
{
send_input_status(user.session, jusrmsg::STATUS_REJECTED, jusrmsg::REASON_BAD_SIG, sig);
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, msg::usrmsg::REASON_BAD_SIG, sig);
return -1;
}
}
else if (d[jusrmsg::FLD_TYPE] == jusrmsg::MSGTYPE_STAT)
else if (msg_type == msg::usrmsg::MSGTYPE_STAT)
{
std::string msg;
jusrmsg::create_status_response(msg);
std::vector<uint8_t> msg;
parser.create_status_response(msg);
user.session.send(msg);
return 0;
}
else
{
LOG_DBG << "Invalid user message type: " << msg_type;
send_input_status(user.session, jusrmsg::STATUS_REJECTED, jusrmsg::REASON_INVALID_MSG_TYPE, "");
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, msg::usrmsg::REASON_INVALID_MSG_TYPE, "");
return -1;
}
}
else
{
// Bad message.
send_input_status(user.session, jusrmsg::STATUS_REJECTED, jusrmsg::REASON_BAD_MSG_FORMAT, "");
send_input_status(parser, user.session, msg::usrmsg::STATUS_REJECTED, msg::usrmsg::REASON_BAD_MSG_FORMAT, "");
return -1;
}
}
@@ -198,10 +203,11 @@ namespace usr
/**
* Send the specified contract input status result via the provided session.
*/
void send_input_status(const comm::comm_session &session, std::string_view status, std::string_view reason, std::string_view input_sig)
void send_input_status(const msg::usrmsg::usrmsg_parser &parser, const comm::comm_session &session,
std::string_view status, std::string_view reason, std::string_view input_sig)
{
std::string msg;
jusrmsg::create_contract_input_status(msg, status, reason, input_sig);
std::vector<uint8_t> msg;
parser.create_contract_input_status(msg, status, reason, input_sig);
session.send(msg);
}
@@ -211,9 +217,10 @@ namespace usr
*
* @param session User socket session.
* @param pubkey User's binary public key.
* @param protocol Messaging protocol used by user.
* @return 0 on successful additions. -1 on failure.
*/
int add_user(const comm::comm_session &session, const std::string &pubkey)
int add_user(const comm::comm_session &session, const std::string &pubkey, const util::PROTOCOL protocol)
{
const std::string &sessionid = session.uniqueid;
if (ctx.users.count(sessionid) == 1)
@@ -224,7 +231,7 @@ namespace usr
{
std::lock_guard<std::mutex> lock(ctx.users_mutex);
ctx.users.emplace(sessionid, usr::connected_user(session, pubkey));
ctx.users.emplace(sessionid, usr::connected_user(session, pubkey, protocol));
}
// Populate sessionid map so we can lookup by user pubkey.

View File

@@ -5,6 +5,7 @@
#include "../util.hpp"
#include "../comm/comm_server.hpp"
#include "../comm/comm_session.hpp"
#include "../msg/usrmsg_parser.hpp"
#include "user_session_handler.hpp"
#include "user_input.hpp"
@@ -13,7 +14,6 @@
*/
namespace usr
{
/**
* Holds information about an authenticated (challenge-verified) user
* connected to the HotPocket node.
@@ -24,7 +24,7 @@ namespace usr
const std::string pubkey;
// Holds the unprocessed user inputs collected from websocket.
std::list<user_submitted_message> submitted_inputs;
std::list<user_input> submitted_inputs;
// Holds the unprocessed read requests collected from websocket.
std::list<std::string> read_requests;
@@ -33,12 +33,15 @@ namespace usr
// We don't need to own the session object since the lifetime of user and session are coupled.
const comm::comm_session &session;
// The messaging protocol used by this user.
const util::PROTOCOL protocol;
/**
* @param session The web socket session the user is connected to.
* @param pubkey The public key of the user in binary format.
*/
connected_user(const comm::comm_session &session, std::string_view pubkey)
: session(session), pubkey(pubkey)
connected_user(const comm::comm_session &session, std::string_view pubkey, util::PROTOCOL protocol)
: session(session), pubkey(pubkey), protocol(protocol)
{
}
};
@@ -72,9 +75,10 @@ namespace usr
int handle_user_message(connected_user &user, std::string_view message);
void send_input_status(const comm::comm_session &session, std::string_view status, std::string_view reason, std::string_view input_sig);
void send_input_status(const msg::usrmsg::usrmsg_parser &parser, const comm::comm_session &session,
std::string_view status, std::string_view reason, std::string_view input_sig);
int add_user(const comm::comm_session &session, const std::string &pubkey);
int add_user(const comm::comm_session &session, const std::string &pubkey, const util::PROTOCOL protocol);
int remove_user(const std::string &sessionid);

View File

@@ -65,6 +65,15 @@ namespace util
bool exists(const std::string &key);
};
/**
* The messaging protocol used in a web socket channel.
*/
enum PROTOCOL
{
JSON = 0,
BSON = 1
};
int bin2hex(std::string &encoded_string, const unsigned char *bin, const size_t bin_len);
int hex2bin(unsigned char *decoded, const size_t decoded_len, std::string_view hex_str);

View File

@@ -8,6 +8,8 @@ hpcore=$5
echo $nodeid. $vmip
strip $hpcore/build/hpcore
if [ $mode = "new" ]; then
sshpass -f vmpass.txt scp $hpcore/build/hpcore \