mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Dynamic roundtime detection. (#244)
When consensus is unreliable detect roundtime based on roundtime reported by peers.
This commit is contained in:
@@ -6,6 +6,7 @@ namespace msg.fbuf.p2pmsg;
|
||||
|
||||
table Peer_Challenge_Message {
|
||||
contract_id:string;
|
||||
roundtime:uint16;
|
||||
challenge:string;
|
||||
}
|
||||
|
||||
@@ -52,6 +53,7 @@ table NonUnl_Proposal_Message {
|
||||
table Proposal_Message { //Proposal type message schema
|
||||
stage:uint8;
|
||||
time:uint64;
|
||||
roundtime:uint16;
|
||||
nonce: [ubyte];
|
||||
users:[ByteArray];
|
||||
input_hashes:[ByteArray];
|
||||
|
||||
@@ -81,7 +81,7 @@ struct Peer_List_Response_MessageBuilder;
|
||||
struct Peer_Properties;
|
||||
struct Peer_PropertiesBuilder;
|
||||
|
||||
enum Message : uint8_t {
|
||||
enum Message {
|
||||
Message_NONE = 0,
|
||||
Message_Peer_Challenge_Response_Message = 1,
|
||||
Message_Peer_Challenge_Message = 2,
|
||||
@@ -206,7 +206,7 @@ template<> struct MessageTraits<msg::fbuf::p2pmsg::Available_Capacity_Announceme
|
||||
bool VerifyMessage(flatbuffers::Verifier &verifier, const void *obj, Message type);
|
||||
bool VerifyMessageVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
enum Ledger_Response_Error : uint8_t {
|
||||
enum Ledger_Response_Error {
|
||||
Ledger_Response_Error_None = 0,
|
||||
Ledger_Response_Error_Invalid_Min_Ledger = 1,
|
||||
Ledger_Response_Error_Req_Ledger_Not_Found = 2,
|
||||
@@ -239,7 +239,7 @@ inline const char *EnumNameLedger_Response_Error(Ledger_Response_Error e) {
|
||||
return EnumNamesLedger_Response_Error()[index];
|
||||
}
|
||||
|
||||
enum Hpfs_Response : uint8_t {
|
||||
enum Hpfs_Response {
|
||||
Hpfs_Response_NONE = 0,
|
||||
Hpfs_Response_File_HashMap_Response = 1,
|
||||
Hpfs_Response_Block_Response = 2,
|
||||
@@ -298,7 +298,8 @@ struct Peer_Challenge_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
|
||||
typedef Peer_Challenge_MessageBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_CONTRACT_ID = 4,
|
||||
VT_CHALLENGE = 6
|
||||
VT_ROUNDTIME = 6,
|
||||
VT_CHALLENGE = 8
|
||||
};
|
||||
const flatbuffers::String *contract_id() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_CONTRACT_ID);
|
||||
@@ -306,6 +307,12 @@ struct Peer_Challenge_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
|
||||
flatbuffers::String *mutable_contract_id() {
|
||||
return GetPointer<flatbuffers::String *>(VT_CONTRACT_ID);
|
||||
}
|
||||
uint16_t roundtime() const {
|
||||
return GetField<uint16_t>(VT_ROUNDTIME, 0);
|
||||
}
|
||||
bool mutate_roundtime(uint16_t _roundtime) {
|
||||
return SetField<uint16_t>(VT_ROUNDTIME, _roundtime, 0);
|
||||
}
|
||||
const flatbuffers::String *challenge() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_CHALLENGE);
|
||||
}
|
||||
@@ -316,6 +323,7 @@ struct Peer_Challenge_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Tab
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset(verifier, VT_CONTRACT_ID) &&
|
||||
verifier.VerifyString(contract_id()) &&
|
||||
VerifyField<uint16_t>(verifier, VT_ROUNDTIME) &&
|
||||
VerifyOffset(verifier, VT_CHALLENGE) &&
|
||||
verifier.VerifyString(challenge()) &&
|
||||
verifier.EndTable();
|
||||
@@ -329,6 +337,9 @@ struct Peer_Challenge_MessageBuilder {
|
||||
void add_contract_id(flatbuffers::Offset<flatbuffers::String> contract_id) {
|
||||
fbb_.AddOffset(Peer_Challenge_Message::VT_CONTRACT_ID, contract_id);
|
||||
}
|
||||
void add_roundtime(uint16_t roundtime) {
|
||||
fbb_.AddElement<uint16_t>(Peer_Challenge_Message::VT_ROUNDTIME, roundtime, 0);
|
||||
}
|
||||
void add_challenge(flatbuffers::Offset<flatbuffers::String> challenge) {
|
||||
fbb_.AddOffset(Peer_Challenge_Message::VT_CHALLENGE, challenge);
|
||||
}
|
||||
@@ -336,6 +347,7 @@ struct Peer_Challenge_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Peer_Challenge_MessageBuilder &operator=(const Peer_Challenge_MessageBuilder &);
|
||||
flatbuffers::Offset<Peer_Challenge_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Peer_Challenge_Message>(end);
|
||||
@@ -346,22 +358,26 @@ struct Peer_Challenge_MessageBuilder {
|
||||
inline flatbuffers::Offset<Peer_Challenge_Message> CreatePeer_Challenge_Message(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::String> contract_id = 0,
|
||||
uint16_t roundtime = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> challenge = 0) {
|
||||
Peer_Challenge_MessageBuilder builder_(_fbb);
|
||||
builder_.add_challenge(challenge);
|
||||
builder_.add_contract_id(contract_id);
|
||||
builder_.add_roundtime(roundtime);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Peer_Challenge_Message> CreatePeer_Challenge_MessageDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *contract_id = nullptr,
|
||||
uint16_t roundtime = 0,
|
||||
const char *challenge = nullptr) {
|
||||
auto contract_id__ = contract_id ? _fbb.CreateString(contract_id) : 0;
|
||||
auto challenge__ = challenge ? _fbb.CreateString(challenge) : 0;
|
||||
return msg::fbuf::p2pmsg::CreatePeer_Challenge_Message(
|
||||
_fbb,
|
||||
contract_id__,
|
||||
roundtime,
|
||||
challenge__);
|
||||
}
|
||||
|
||||
@@ -407,6 +423,7 @@ struct Peer_Challenge_Response_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Peer_Challenge_Response_MessageBuilder &operator=(const Peer_Challenge_Response_MessageBuilder &);
|
||||
flatbuffers::Offset<Peer_Challenge_Response_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Peer_Challenge_Response_Message>(end);
|
||||
@@ -489,6 +506,7 @@ struct UserInputBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
UserInputBuilder &operator=(const UserInputBuilder &);
|
||||
flatbuffers::Offset<UserInput> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<UserInput>(end);
|
||||
@@ -565,6 +583,7 @@ struct UserInputGroupBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
UserInputGroupBuilder &operator=(const UserInputGroupBuilder &);
|
||||
flatbuffers::Offset<UserInputGroup> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<UserInputGroup>(end);
|
||||
@@ -724,6 +743,7 @@ struct ContentBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
ContentBuilder &operator=(const ContentBuilder &);
|
||||
flatbuffers::Offset<Content> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Content>(end);
|
||||
@@ -772,6 +792,7 @@ struct NonUnl_Proposal_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
NonUnl_Proposal_MessageBuilder &operator=(const NonUnl_Proposal_MessageBuilder &);
|
||||
flatbuffers::Offset<NonUnl_Proposal_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<NonUnl_Proposal_Message>(end);
|
||||
@@ -801,13 +822,14 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_STAGE = 4,
|
||||
VT_TIME = 6,
|
||||
VT_NONCE = 8,
|
||||
VT_USERS = 10,
|
||||
VT_INPUT_HASHES = 12,
|
||||
VT_OUTPUT_HASH = 14,
|
||||
VT_OUTPUT_SIG = 16,
|
||||
VT_STATE_HASH = 18,
|
||||
VT_PATCH_HASH = 20
|
||||
VT_ROUNDTIME = 8,
|
||||
VT_NONCE = 10,
|
||||
VT_USERS = 12,
|
||||
VT_INPUT_HASHES = 14,
|
||||
VT_OUTPUT_HASH = 16,
|
||||
VT_OUTPUT_SIG = 18,
|
||||
VT_STATE_HASH = 20,
|
||||
VT_PATCH_HASH = 22
|
||||
};
|
||||
uint8_t stage() const {
|
||||
return GetField<uint8_t>(VT_STAGE, 0);
|
||||
@@ -821,6 +843,12 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
bool mutate_time(uint64_t _time) {
|
||||
return SetField<uint64_t>(VT_TIME, _time, 0);
|
||||
}
|
||||
uint16_t roundtime() const {
|
||||
return GetField<uint16_t>(VT_ROUNDTIME, 0);
|
||||
}
|
||||
bool mutate_roundtime(uint16_t _roundtime) {
|
||||
return SetField<uint16_t>(VT_ROUNDTIME, _roundtime, 0);
|
||||
}
|
||||
const flatbuffers::Vector<uint8_t> *nonce() const {
|
||||
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_NONCE);
|
||||
}
|
||||
@@ -867,6 +895,7 @@ struct Proposal_Message FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<uint8_t>(verifier, VT_STAGE) &&
|
||||
VerifyField<uint64_t>(verifier, VT_TIME) &&
|
||||
VerifyField<uint16_t>(verifier, VT_ROUNDTIME) &&
|
||||
VerifyOffset(verifier, VT_NONCE) &&
|
||||
verifier.VerifyVector(nonce()) &&
|
||||
VerifyOffset(verifier, VT_USERS) &&
|
||||
@@ -897,6 +926,9 @@ struct Proposal_MessageBuilder {
|
||||
void add_time(uint64_t time) {
|
||||
fbb_.AddElement<uint64_t>(Proposal_Message::VT_TIME, time, 0);
|
||||
}
|
||||
void add_roundtime(uint16_t roundtime) {
|
||||
fbb_.AddElement<uint16_t>(Proposal_Message::VT_ROUNDTIME, roundtime, 0);
|
||||
}
|
||||
void add_nonce(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> nonce) {
|
||||
fbb_.AddOffset(Proposal_Message::VT_NONCE, nonce);
|
||||
}
|
||||
@@ -922,6 +954,7 @@ struct Proposal_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Proposal_MessageBuilder &operator=(const Proposal_MessageBuilder &);
|
||||
flatbuffers::Offset<Proposal_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Proposal_Message>(end);
|
||||
@@ -933,6 +966,7 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_Message(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
uint8_t stage = 0,
|
||||
uint64_t time = 0,
|
||||
uint16_t roundtime = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> nonce = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> users = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<msg::fbuf::ByteArray>>> input_hashes = 0,
|
||||
@@ -949,6 +983,7 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_Message(
|
||||
builder_.add_input_hashes(input_hashes);
|
||||
builder_.add_users(users);
|
||||
builder_.add_nonce(nonce);
|
||||
builder_.add_roundtime(roundtime);
|
||||
builder_.add_stage(stage);
|
||||
return builder_.Finish();
|
||||
}
|
||||
@@ -957,6 +992,7 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_MessageDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
uint8_t stage = 0,
|
||||
uint64_t time = 0,
|
||||
uint16_t roundtime = 0,
|
||||
const std::vector<uint8_t> *nonce = nullptr,
|
||||
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *users = nullptr,
|
||||
const std::vector<flatbuffers::Offset<msg::fbuf::ByteArray>> *input_hashes = nullptr,
|
||||
@@ -975,6 +1011,7 @@ inline flatbuffers::Offset<Proposal_Message> CreateProposal_MessageDirect(
|
||||
_fbb,
|
||||
stage,
|
||||
time,
|
||||
roundtime,
|
||||
nonce__,
|
||||
users__,
|
||||
input_hashes__,
|
||||
@@ -1014,6 +1051,7 @@ struct Npl_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Npl_MessageBuilder &operator=(const Npl_MessageBuilder &);
|
||||
flatbuffers::Offset<Npl_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Npl_Message>(end);
|
||||
@@ -1068,6 +1106,7 @@ struct History_Request_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
History_Request_MessageBuilder &operator=(const History_Request_MessageBuilder &);
|
||||
flatbuffers::Offset<History_Request_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<History_Request_Message>(end);
|
||||
@@ -1146,6 +1185,7 @@ struct History_Response_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
History_Response_MessageBuilder &operator=(const History_Response_MessageBuilder &);
|
||||
flatbuffers::Offset<History_Response_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<History_Response_Message>(end);
|
||||
@@ -1220,6 +1260,7 @@ struct HistoryLedgerBlockPairBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
HistoryLedgerBlockPairBuilder &operator=(const HistoryLedgerBlockPairBuilder &);
|
||||
flatbuffers::Offset<HistoryLedgerBlockPair> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<HistoryLedgerBlockPair>(end);
|
||||
@@ -1279,6 +1320,7 @@ struct HistoryLedgerBlockBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
HistoryLedgerBlockBuilder &operator=(const HistoryLedgerBlockBuilder &);
|
||||
flatbuffers::Offset<HistoryLedgerBlock> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<HistoryLedgerBlock>(end);
|
||||
@@ -1383,6 +1425,7 @@ struct Hpfs_Request_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Hpfs_Request_MessageBuilder &operator=(const Hpfs_Request_MessageBuilder &);
|
||||
flatbuffers::Offset<Hpfs_Request_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Hpfs_Request_Message>(end);
|
||||
@@ -1519,6 +1562,7 @@ struct Hpfs_Response_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Hpfs_Response_MessageBuilder &operator=(const Hpfs_Response_MessageBuilder &);
|
||||
flatbuffers::Offset<Hpfs_Response_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Hpfs_Response_Message>(end);
|
||||
@@ -1591,6 +1635,7 @@ struct Fs_Entry_ResponseBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Fs_Entry_ResponseBuilder &operator=(const Fs_Entry_ResponseBuilder &);
|
||||
flatbuffers::Offset<Fs_Entry_Response> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Fs_Entry_Response>(end);
|
||||
@@ -1656,6 +1701,7 @@ struct File_HashMap_ResponseBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
File_HashMap_ResponseBuilder &operator=(const File_HashMap_ResponseBuilder &);
|
||||
flatbuffers::Offset<File_HashMap_Response> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<File_HashMap_Response>(end);
|
||||
@@ -1725,6 +1771,7 @@ struct Block_ResponseBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Block_ResponseBuilder &operator=(const Block_ResponseBuilder &);
|
||||
flatbuffers::Offset<Block_Response> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Block_Response>(end);
|
||||
@@ -1806,6 +1853,7 @@ struct Hpfs_FS_Hash_EntryBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Hpfs_FS_Hash_EntryBuilder &operator=(const Hpfs_FS_Hash_EntryBuilder &);
|
||||
flatbuffers::Offset<Hpfs_FS_Hash_Entry> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Hpfs_FS_Hash_Entry>(end);
|
||||
@@ -1868,6 +1916,7 @@ struct Peer_Requirement_Announcement_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Peer_Requirement_Announcement_MessageBuilder &operator=(const Peer_Requirement_Announcement_MessageBuilder &);
|
||||
flatbuffers::Offset<Peer_Requirement_Announcement_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Peer_Requirement_Announcement_Message>(end);
|
||||
@@ -1923,6 +1972,7 @@ struct Available_Capacity_Announcement_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Available_Capacity_Announcement_MessageBuilder &operator=(const Available_Capacity_Announcement_MessageBuilder &);
|
||||
flatbuffers::Offset<Available_Capacity_Announcement_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Available_Capacity_Announcement_Message>(end);
|
||||
@@ -1956,6 +2006,7 @@ struct Peer_List_Request_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Peer_List_Request_MessageBuilder &operator=(const Peer_List_Request_MessageBuilder &);
|
||||
flatbuffers::Offset<Peer_List_Request_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Peer_List_Request_Message>(end);
|
||||
@@ -2000,6 +2051,7 @@ struct Peer_List_Response_MessageBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Peer_List_Response_MessageBuilder &operator=(const Peer_List_Response_MessageBuilder &);
|
||||
flatbuffers::Offset<Peer_List_Response_Message> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Peer_List_Response_Message>(end);
|
||||
@@ -2087,6 +2139,7 @@ struct Peer_PropertiesBuilder {
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
Peer_PropertiesBuilder &operator=(const Peer_PropertiesBuilder &);
|
||||
flatbuffers::Offset<Peer_Properties> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Peer_Properties>(end);
|
||||
|
||||
@@ -20,30 +20,30 @@ namespace msg::fbuf::p2pmsg
|
||||
constexpr size_t MAX_SIZE_FOR_TIME_CHECK = 1 * 1024 * 1024; // 1 MB
|
||||
|
||||
/**
|
||||
* This section contains Flatbuffer message reading/writing helpers.
|
||||
* These helpers are mainly used by peer_session_handler.
|
||||
*
|
||||
* All Flatbuffer peer messages are 'Container' messages. 'Container' message is a bucket
|
||||
* which some common headers (version, singature etc..) and the message 'Content' (Proposal, NPL etc..).
|
||||
*
|
||||
* Therefore, when constructing peer messages, we have to first construct 'Content' message and then
|
||||
* place the 'Content' inside a 'Conatiner. 'Content' and 'Container' messages are constructed using
|
||||
* Flatbuffer builders.
|
||||
*
|
||||
* Reading is also 2 steps because of this. We have first interprit the 'Container' message from the
|
||||
* received data and then interprit the 'Content' portion of it separately to read the actual content.
|
||||
*/
|
||||
* This section contains Flatbuffer message reading/writing helpers.
|
||||
* These helpers are mainly used by peer_session_handler.
|
||||
*
|
||||
* All Flatbuffer peer messages are 'Container' messages. 'Container' message is a bucket
|
||||
* which some common headers (version, singature etc..) and the message 'Content' (Proposal, NPL etc..).
|
||||
*
|
||||
* Therefore, when constructing peer messages, we have to first construct 'Content' message and then
|
||||
* place the 'Content' inside a 'Conatiner. 'Content' and 'Container' messages are constructed using
|
||||
* Flatbuffer builders.
|
||||
*
|
||||
* Reading is also 2 steps because of this. We have first interprit the 'Container' message from the
|
||||
* received data and then interprit the 'Content' portion of it separately to read the actual content.
|
||||
*/
|
||||
|
||||
//---Message validation helpers---/
|
||||
|
||||
/**
|
||||
* Verifies Conatiner message structure and outputs faltbuffer Container pointer to access the given buffer.
|
||||
*
|
||||
* @param container_ref A pointer reference to assign the pointer to the Container object.
|
||||
* @param container_buf The buffer containing the data that should be validated and interpreted
|
||||
* via the container pointer.
|
||||
* @return 0 on successful verification. -1 for failure.
|
||||
*/
|
||||
* Verifies Conatiner message structure and outputs faltbuffer Container pointer to access the given buffer.
|
||||
*
|
||||
* @param container_ref A pointer reference to assign the pointer to the Container object.
|
||||
* @param container_buf The buffer containing the data that should be validated and interpreted
|
||||
* via the container pointer.
|
||||
* @return 0 on successful verification. -1 for failure.
|
||||
*/
|
||||
int validate_and_extract_container(const Container **container_ref, std::string_view container_buf)
|
||||
{
|
||||
//Accessing message buffer
|
||||
@@ -123,14 +123,14 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the Content message structure and outputs faltbuffer Content pointer to access the given buffer.
|
||||
*
|
||||
* @param content_ref A pointer reference to assign the pointer to the Content object.
|
||||
* @param content_ptr Pointer to the buffer containing the data that should validated and interpreted
|
||||
* via the container pointer.
|
||||
* @param content_size Data buffer size.
|
||||
* @return 0 on successful verification. -1 for failure.
|
||||
*/
|
||||
* Verifies the Content message structure and outputs faltbuffer Content pointer to access the given buffer.
|
||||
*
|
||||
* @param content_ref A pointer reference to assign the pointer to the Content object.
|
||||
* @param content_ptr Pointer to the buffer containing the data that should validated and interpreted
|
||||
* via the container pointer.
|
||||
* @param content_size Data buffer size.
|
||||
* @return 0 on successful verification. -1 for failure.
|
||||
*/
|
||||
int validate_and_extract_content(const Content **content_ref, const uint8_t *content_ptr, const flatbuffers::uoffset_t content_size)
|
||||
{
|
||||
//Defining Flatbuffer verifier for message content verification.
|
||||
@@ -151,22 +151,23 @@ namespace msg::fbuf::p2pmsg
|
||||
//---Message reading helpers---/
|
||||
|
||||
/**
|
||||
* Returns challenge from the peer challenge message.
|
||||
* @param The Flatbuffer peer challenge message received from the peer.
|
||||
* @return Peer challenge struct.
|
||||
*/
|
||||
* Returns challenge from the peer challenge message.
|
||||
* @param The Flatbuffer peer challenge message received from the peer.
|
||||
* @return Peer challenge struct.
|
||||
*/
|
||||
const p2p::peer_challenge get_peer_challenge_from_msg(const Peer_Challenge_Message &msg)
|
||||
{
|
||||
return {
|
||||
std::string(flatbuff_str_to_sv(msg.contract_id())),
|
||||
msg.roundtime(),
|
||||
std::string(flatbuff_str_to_sv(msg.challenge()))};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a peer challenge response struct from the given peer challenge response message.
|
||||
* @param The Flatbuffer peer challenge response message received from the peer.
|
||||
* @return A peer challenge response struct representing the message.
|
||||
*/
|
||||
* Creates a peer challenge response struct from the given peer challenge response message.
|
||||
* @param The Flatbuffer peer challenge response message received from the peer.
|
||||
* @return A peer challenge response struct representing the message.
|
||||
*/
|
||||
const p2p::peer_challenge_response create_peer_challenge_response_from_msg(const Peer_Challenge_Response_Message &msg, const flatbuffers::Vector<uint8_t> *pubkey)
|
||||
{
|
||||
p2p::peer_challenge_response pchalresp;
|
||||
@@ -179,10 +180,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a non-unl proposal stuct from the given non-unl proposal message.
|
||||
* @param The Flatbuffer non-unl poporal received from the peer.
|
||||
* @return A non-unl proposal struct representing the message.
|
||||
*/
|
||||
* Creates a non-unl proposal stuct from the given non-unl proposal message.
|
||||
* @param The Flatbuffer non-unl poporal received from the peer.
|
||||
* @return A non-unl proposal struct representing the message.
|
||||
*/
|
||||
const p2p::nonunl_proposal create_nonunl_proposal_from_msg(const NonUnl_Proposal_Message &msg, const uint64_t timestamp)
|
||||
{
|
||||
p2p::nonunl_proposal nup;
|
||||
@@ -194,10 +195,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a history response stuct from the given histrory response message.
|
||||
* @param msg Flatbuffer History response message received from the peer.
|
||||
* @return A History response struct representing the message.
|
||||
*/
|
||||
* Creates a history response stuct from the given histrory response message.
|
||||
* @param msg Flatbuffer History response message received from the peer.
|
||||
* @return A History response struct representing the message.
|
||||
*/
|
||||
const p2p::history_response create_history_response_from_msg(const History_Response_Message &msg)
|
||||
{
|
||||
p2p::history_response hr;
|
||||
@@ -215,10 +216,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a proposal stuct from the given proposal message.
|
||||
* @param The Flatbuffer poposal received from the peer.
|
||||
* @return A proposal struct representing the message.
|
||||
*/
|
||||
* Creates a proposal stuct from the given proposal message.
|
||||
* @param The Flatbuffer poposal received from the peer.
|
||||
* @return A proposal struct representing the message.
|
||||
*/
|
||||
const p2p::proposal create_proposal_from_msg(const Proposal_Message &msg, const flatbuffers::Vector<uint8_t> *pubkey, const uint64_t timestamp, const flatbuffers::Vector<uint8_t> *lcl)
|
||||
{
|
||||
p2p::proposal p;
|
||||
@@ -227,6 +228,7 @@ namespace msg::fbuf::p2pmsg
|
||||
p.sent_timestamp = timestamp;
|
||||
p.recv_timestamp = util::get_epoch_milliseconds();
|
||||
p.time = msg.time();
|
||||
p.roundtime = msg.roundtime();
|
||||
p.nonce = flatbuff_bytes_to_sv(msg.nonce());
|
||||
p.stage = msg.stage();
|
||||
p.lcl = flatbuff_bytes_to_sv(lcl);
|
||||
@@ -249,10 +251,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a history request struct from the given history request message.
|
||||
* @param msg Flatbuffer History request message received from the peer.
|
||||
* @return A History request struct representing the message.
|
||||
*/
|
||||
* Creates a history request struct from the given history request message.
|
||||
* @param msg Flatbuffer History request message received from the peer.
|
||||
* @return A History request struct representing the message.
|
||||
*/
|
||||
const p2p::history_request create_history_request_from_msg(const History_Request_Message &msg, const flatbuffers::Vector<uint8_t> *lcl)
|
||||
{
|
||||
p2p::history_request hr;
|
||||
@@ -284,10 +286,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a peer property list from the given peer list response message.
|
||||
* @param msg Flatbuffer Peer List response message received from the peer.
|
||||
* @return A Peer list representing the message.
|
||||
*/
|
||||
* Creates a peer property list from the given peer list response message.
|
||||
* @param msg Flatbuffer Peer List response message received from the peer.
|
||||
* @return A Peer list representing the message.
|
||||
*/
|
||||
const std::vector<conf::peer_properties> create_peer_list_response_from_msg(const Peer_List_Response_Message &msg)
|
||||
{
|
||||
return flatbuf_peer_propertieslist_to_peer_propertiesvector(msg.peer_list());
|
||||
@@ -296,10 +298,10 @@ namespace msg::fbuf::p2pmsg
|
||||
//---Message creation helpers---//
|
||||
|
||||
/**
|
||||
* Create peer challenge message from the given challenge.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param challenge Challenge message needed to convert to flatbuffer message.
|
||||
*/
|
||||
* Create peer challenge message from the given challenge.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param challenge Challenge message needed to convert to flatbuffer message.
|
||||
*/
|
||||
void create_msg_from_peer_challenge(flatbuffers::FlatBufferBuilder &container_builder, std::string &challenge)
|
||||
{
|
||||
flatbuffers::FlatBufferBuilder builder(1024);
|
||||
@@ -313,6 +315,7 @@ namespace msg::fbuf::p2pmsg
|
||||
CreatePeer_Challenge_Message(
|
||||
builder,
|
||||
sv_to_flatbuff_str(builder, conf::cfg.contract.id),
|
||||
conf::cfg.contract.roundtime,
|
||||
sv_to_flatbuff_str(builder, challenge));
|
||||
|
||||
const flatbuffers::Offset<Content> message = CreateContent(builder, Message_Peer_Challenge_Message, peer_challenge_msg.Union());
|
||||
@@ -323,10 +326,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create peer challenge response message from the given challenge.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param challenge Message which need to be signed and placed in the container message.
|
||||
*/
|
||||
* Create peer challenge response message from the given challenge.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param challenge Message which need to be signed and placed in the container message.
|
||||
*/
|
||||
void create_peer_challenge_response_from_challenge(flatbuffers::FlatBufferBuilder &container_builder, const std::string &challenge)
|
||||
{
|
||||
flatbuffers::FlatBufferBuilder builder(1024);
|
||||
@@ -363,10 +366,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create proposal peer message from the given proposal struct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param p The proposal struct to be placed in the container message.
|
||||
*/
|
||||
* Create proposal peer message from the given proposal struct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param p The proposal struct to be placed in the container message.
|
||||
*/
|
||||
void create_msg_from_proposal(flatbuffers::FlatBufferBuilder &container_builder, const p2p::proposal &p)
|
||||
{
|
||||
// todo:get a average propsal message size and allocate content builder based on that.
|
||||
@@ -377,6 +380,7 @@ namespace msg::fbuf::p2pmsg
|
||||
builder,
|
||||
p.stage,
|
||||
p.time,
|
||||
p.roundtime,
|
||||
sv_to_flatbuff_bytes(builder, p.nonce),
|
||||
stringlist_to_flatbuf_bytearrayvector(builder, p.users),
|
||||
stringlist_to_flatbuf_bytearrayvector(builder, p.input_hashes),
|
||||
@@ -394,11 +398,11 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Ctreat npl message from the given npl output srtuct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param msg The message to be sent as NPL message.
|
||||
* @param lcl Lcl value to be passed in the container message.
|
||||
*/
|
||||
* Ctreat npl message from the given npl output srtuct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param msg The message to be sent as NPL message.
|
||||
* @param lcl Lcl value to be passed in the container message.
|
||||
*/
|
||||
void create_msg_from_npl_output(flatbuffers::FlatBufferBuilder &container_builder, const std::string_view &msg, std::string_view lcl)
|
||||
{
|
||||
flatbuffers::FlatBufferBuilder builder(1024);
|
||||
@@ -417,10 +421,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create history request message from the given history request struct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param hr The History request struct to be placed in the container message.
|
||||
*/
|
||||
* Create history request message from the given history request struct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param hr The History request struct to be placed in the container message.
|
||||
*/
|
||||
void create_msg_from_history_request(flatbuffers::FlatBufferBuilder &container_builder, const p2p::history_request &hr)
|
||||
{
|
||||
flatbuffers::FlatBufferBuilder builder(1024);
|
||||
@@ -439,10 +443,10 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create history response message from the given history response struct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param hr The History response struct to be placed in the container message.
|
||||
*/
|
||||
* Create history response message from the given history response struct.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param hr The History response struct to be placed in the container message.
|
||||
*/
|
||||
void create_msg_from_history_response(flatbuffers::FlatBufferBuilder &container_builder, const p2p::history_response &hr)
|
||||
{
|
||||
flatbuffers::FlatBufferBuilder builder(1024);
|
||||
@@ -489,14 +493,14 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create content response message from the given content response.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param path The path of the directory.
|
||||
* @param mount_id The mount id of the relavent hpfs mount.
|
||||
* @param hash_nodes File or directory entries with hashes in the given parent path.
|
||||
* @param expected_hash The exptected hash of the requested path.
|
||||
* @param lcl Lcl to be include in the container msg.
|
||||
*/
|
||||
* Create content response message from the given content response.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param path The path of the directory.
|
||||
* @param mount_id The mount id of the relavent hpfs mount.
|
||||
* @param hash_nodes File or directory entries with hashes in the given parent path.
|
||||
* @param expected_hash The exptected hash of the requested path.
|
||||
* @param lcl Lcl to be include in the container msg.
|
||||
*/
|
||||
void create_msg_from_fsentry_response(
|
||||
flatbuffers::FlatBufferBuilder &container_builder, const std::string_view path, const uint32_t mount_id,
|
||||
std::vector<hpfs::child_hash_node> &hash_nodes, util::h32 expected_hash, std::string_view lcl)
|
||||
@@ -523,13 +527,13 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create content response message from the given content response.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param path The path of the directory.
|
||||
* @param mount_id The mount id of the relavent hpfs mount.
|
||||
* @param hashmap Hashmap of the file
|
||||
* @param lcl Lcl to be include in the container msg.
|
||||
*/
|
||||
* Create content response message from the given content response.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param path The path of the directory.
|
||||
* @param mount_id The mount id of the relavent hpfs mount.
|
||||
* @param hashmap Hashmap of the file
|
||||
* @param lcl Lcl to be include in the container msg.
|
||||
*/
|
||||
void create_msg_from_filehashmap_response(
|
||||
flatbuffers::FlatBufferBuilder &container_builder, std::string_view path, const uint32_t mount_id,
|
||||
std::vector<util::h32> &hashmap, std::size_t file_length, util::h32 expected_hash, std::string_view lcl)
|
||||
@@ -561,12 +565,12 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create content response message from the given content response.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param block_resp Block response struct to place in the message.
|
||||
* @param mount_id The mount id of the relavent hpfs mount.
|
||||
* @param lcl Lcl to be include in the container message.
|
||||
*/
|
||||
* Create content response message from the given content response.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param block_resp Block response struct to place in the message.
|
||||
* @param mount_id The mount id of the relavent hpfs mount.
|
||||
* @param lcl Lcl to be include in the container message.
|
||||
*/
|
||||
void create_msg_from_block_response(flatbuffers::FlatBufferBuilder &container_builder, p2p::block_response &block_resp, const uint32_t mount_id, std::string_view lcl)
|
||||
{
|
||||
// todo:get a average propsal message size and allocate content builder based on that.
|
||||
@@ -683,12 +687,12 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Flatbuffer container message from the given Content message.
|
||||
* @param container_builder The Flatbuffer builder to which the final container message should be written to.
|
||||
* @param content_builder The Flatbuffer builder containing the content message that should be placed
|
||||
* inside the container message.
|
||||
* @param sign Whether to sign the message content.
|
||||
*/
|
||||
* Creates a Flatbuffer container message from the given Content message.
|
||||
* @param container_builder The Flatbuffer builder to which the final container message should be written to.
|
||||
* @param content_builder The Flatbuffer builder containing the content message that should be placed
|
||||
* inside the container message.
|
||||
* @param sign Whether to sign the message content.
|
||||
*/
|
||||
void create_containermsg_from_content(
|
||||
flatbuffers::FlatBufferBuilder &container_builder, const flatbuffers::FlatBufferBuilder &content_builder, std::string_view lcl, const bool sign)
|
||||
{
|
||||
@@ -854,11 +858,11 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create peer list message from the given vector of peer properties structs.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param peers The Vector of peer properties to be placed in the container message.
|
||||
* @param skipping_peer Peer that does not need to be sent.
|
||||
*/
|
||||
* Create peer list message from the given vector of peer properties structs.
|
||||
* @param container_builder Flatbuffer builder for the container message.
|
||||
* @param peers The Vector of peer properties to be placed in the container message.
|
||||
* @param skipping_peer Peer that does not need to be sent.
|
||||
*/
|
||||
const flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Peer_Properties>>>
|
||||
peer_propertiesvector_to_flatbuf_peer_propertieslist(flatbuffers::FlatBufferBuilder &builder, const std::vector<conf::peer_properties> &peers, const std::optional<conf::ip_port_prop> &skipping_ip_port)
|
||||
{
|
||||
@@ -879,9 +883,9 @@ namespace msg::fbuf::p2pmsg
|
||||
}
|
||||
|
||||
/**
|
||||
* Create vector of peer properties structs from the given peer list message.
|
||||
* @param fbvec The peer list message to be convert to a list of peer properties structs.
|
||||
*/
|
||||
* Create vector of peer properties structs from the given peer list message.
|
||||
* @param fbvec The peer list message to be convert to a list of peer properties structs.
|
||||
*/
|
||||
const std::vector<conf::peer_properties>
|
||||
flatbuf_peer_propertieslist_to_peer_propertiesvector(const flatbuffers::Vector<flatbuffers::Offset<Peer_Properties>> *fbvec)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user