Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
protocol.hpp
Go to the documentation of this file.
1#pragma once
4#include <chrono>
5
6namespace sysio {
7 using namespace chain;
8 using namespace fc;
9
10 static_assert(sizeof(std::chrono::system_clock::duration::rep) >= 8, "system_clock is expected to be at least 64 bits");
11 typedef std::chrono::system_clock::duration::rep tstamp;
12
19
20 // Longest domain name is 253 characters according to wikipedia.
21 // Addresses include ":port" where max port is 65535, which adds 6 chars.
22 // We also add our own extentions of "[:trx|:blk] - xxxxxxx", which adds 14 chars, total= 273.
23 // Allow for future extentions as well, hence 384.
24 constexpr size_t max_p2p_address_length = 253 + 6;
25 constexpr size_t max_handshake_str_length = 384;
26
44
45
60
61 constexpr auto reason_str( go_away_reason rsn ) {
62 switch (rsn ) {
63 case no_reason : return "no reason";
64 case self : return "self connect";
65 case duplicate : return "duplicate";
66 case wrong_chain : return "wrong chain";
67 case wrong_version : return "wrong version";
68 case forked : return "chain is forked";
69 case unlinkable : return "unlinkable block received";
70 case bad_transaction : return "bad transaction";
71 case validation : return "invalid block";
72 case authentication : return "authentication failure";
73 case fatal_other : return "some other failure";
74 case benign_other : return "some other non-fatal condition, possibly unknown block";
75 default : return "some crazy reason";
76 }
77 }
78
84
85 struct time_message {
89 mutable tstamp dst{0};
90 };
91
98
99 constexpr auto modes_str( id_list_modes m ) {
100 switch( m ) {
101 case none : return "none";
102 case catch_up : return "catch up";
103 case last_irr_catch_up : return "last irreversible";
104 case normal : return "normal";
105 default: return "undefined mode";
106 }
107 }
108
109 template<typename T>
110 struct select_ids {
115 bool empty () const { return (mode == none || ids.empty()); }
116 };
117
120
126
132
137
138 using net_message = std::variant<handshake_message,
145 signed_block, // which = 7
146 packed_transaction>; // which = 8
147
148} // namespace sysio
149
150FC_REFLECT( sysio::select_ids<fc::sha256>, (mode)(pending)(ids) )
152 (last_irreversible_block_num)(last_irreversible_block_id)
153 (head_num)(head_id))
155 (network_version)(chain_id)(node_id)(key)
156 (time)(token)(sig)(p2p_address)
157 (last_irreversible_block_num)(last_irreversible_block_id)
158 (head_num)(head_id)
159 (os)(agent)(generation) )
160FC_REFLECT( sysio::go_away_message, (reason)(node_id) )
161FC_REFLECT( sysio::time_message, (org)(rec)(xmt)(dst) )
162FC_REFLECT( sysio::notice_message, (known_trx)(known_blocks) )
163FC_REFLECT( sysio::request_message, (req_trx)(req_blocks) )
164FC_REFLECT( sysio::sync_request_message, (start_block)(end_block) )
165
166
const mie::Vuint & r
Definition bn.cpp:28
os_t os
namespace sysio::chain
Definition authority.cpp:3
constexpr size_t max_handshake_str_length
Definition protocol.hpp:25
id_list_modes
Definition protocol.hpp:92
@ normal
Definition protocol.hpp:96
@ last_irr_catch_up
Definition protocol.hpp:95
@ catch_up
Definition protocol.hpp:94
std::chrono::system_clock::duration::rep tstamp
Definition protocol.hpp:11
constexpr auto modes_str(id_list_modes m)
Definition protocol.hpp:99
go_away_reason
Definition protocol.hpp:46
@ duplicate
the connection is redundant
Definition protocol.hpp:49
@ self
the connection is to itself
Definition protocol.hpp:48
@ no_reason
no reason to go away
Definition protocol.hpp:47
@ wrong_chain
the peer's chain id doesn't match
Definition protocol.hpp:50
@ wrong_version
the peer's network version doesn't match
Definition protocol.hpp:51
@ unlinkable
the peer sent a block we couldn't use
Definition protocol.hpp:53
@ bad_transaction
the peer sent a transaction that failed verification
Definition protocol.hpp:54
@ fatal_other
a catch-all for errors we don't have discriminated
Definition protocol.hpp:57
@ forked
the peer's irreversible blocks are different
Definition protocol.hpp:52
@ authentication
peer failed authenicatio
Definition protocol.hpp:58
@ validation
the peer sent a block that failed validation
Definition protocol.hpp:55
@ benign_other
reasons such as a timeout. not fatal but warrant resetting
Definition protocol.hpp:56
std::variant< handshake_message, chain_size_message, go_away_message, time_message, notice_message, request_message, sync_request_message, signed_block, packed_transaction > net_message
Definition protocol.hpp:138
constexpr auto reason_str(go_away_reason rsn)
Definition protocol.hpp:61
constexpr size_t max_p2p_address_length
Definition protocol.hpp:24
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
signed short int16_t
Definition stdint.h:122
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
block_id_type last_irreversible_block_id
Definition protocol.hpp:15
uint32_t last_irreversible_block_num
Definition protocol.hpp:14
go_away_message(go_away_reason r=no_reason)
Definition protocol.hpp:80
go_away_reason reason
Definition protocol.hpp:81
fc::sha256 node_id
for duplicate notification
Definition protocol.hpp:82
chain_id_type chain_id
used to identify chain
Definition protocol.hpp:29
uint16_t network_version
incremental value above a computed base
Definition protocol.hpp:28
block_id_type head_id
Definition protocol.hpp:39
uint32_t last_irreversible_block_num
Definition protocol.hpp:36
fc::sha256 node_id
used to identify peers and prevent self-connect
Definition protocol.hpp:30
fc::sha256 token
digest of time to prove we own the private key of the key above
Definition protocol.hpp:33
chain::public_key_type key
authentication key; may be a producer or peer key, or empty
Definition protocol.hpp:31
chain::signature_type sig
signature for the digest
Definition protocol.hpp:34
block_id_type last_irreversible_block_id
Definition protocol.hpp:37
ordered_blk_ids known_blocks
Definition protocol.hpp:124
ordered_txn_ids known_trx
Definition protocol.hpp:123
ordered_blk_ids req_blocks
Definition protocol.hpp:130
ordered_txn_ids req_trx
Definition protocol.hpp:129
bool empty() const
Definition protocol.hpp:115
id_list_modes mode
Definition protocol.hpp:112
vector< T > ids
Definition protocol.hpp:114
tstamp xmt
transmit timestamp
Definition protocol.hpp:88
tstamp dst
destination timestamp
Definition protocol.hpp:89
tstamp rec
receive timestamp
Definition protocol.hpp:87
tstamp org
origin timestamp
Definition protocol.hpp:86