forked from stellar/stellar-xdr
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Stellar-overlay.x
412 lines (343 loc) · 8.43 KB
/
Stellar-overlay.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// Copyright 2015 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
%#include "xdr/Stellar-ledger.h"
namespace stellar
{
enum ErrorCode
{
ERR_MISC = 0, // Unspecific error
ERR_DATA = 1, // Malformed data
ERR_CONF = 2, // Misconfiguration error
ERR_AUTH = 3, // Authentication failure
ERR_LOAD = 4 // System overloaded
};
struct Error
{
ErrorCode code;
string msg<100>;
};
struct SendMore
{
uint32 numMessages;
};
struct SendMoreExtended
{
uint32 numMessages;
uint32 numBytes;
};
struct AuthCert
{
Curve25519Public pubkey;
uint64 expiration;
Signature sig;
};
struct Hello
{
uint32 ledgerVersion;
uint32 overlayVersion;
uint32 overlayMinVersion;
Hash networkID;
string versionStr<100>;
int listeningPort;
NodeID peerID;
AuthCert cert;
uint256 nonce;
};
// During the roll-out phrase, nodes can disable flow control in bytes.
// Therefore, we need a way to communicate with other nodes
// that we want/don't want flow control in bytes.
// We use the `flags` field in the Auth message with a special value
// set to communicate this. Note that AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED != 0
// AND AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED != 100 (as previously
// that value was used for other purposes).
const AUTH_MSG_FLAG_FLOW_CONTROL_BYTES_REQUESTED = 200;
struct Auth
{
int flags;
};
enum IPAddrType
{
IPv4 = 0,
IPv6 = 1
};
struct PeerAddress
{
union switch (IPAddrType type)
{
case IPv4:
opaque ipv4[4];
case IPv6:
opaque ipv6[16];
}
ip;
uint32 port;
uint32 numFailures;
};
// Next ID: 21
enum MessageType
{
ERROR_MSG = 0,
AUTH = 2,
DONT_HAVE = 3,
GET_PEERS = 4, // gets a list of peers this guy knows about
PEERS = 5,
GET_TX_SET = 6, // gets a particular txset by hash
TX_SET = 7,
GENERALIZED_TX_SET = 17,
TRANSACTION = 8, // pass on a tx you have heard about
// SCP
GET_SCP_QUORUMSET = 9,
SCP_QUORUMSET = 10,
SCP_MESSAGE = 11,
GET_SCP_STATE = 12,
// new messages
HELLO = 13,
SURVEY_REQUEST = 14,
SURVEY_RESPONSE = 15,
SEND_MORE = 16,
SEND_MORE_EXTENDED = 20,
FLOOD_ADVERT = 18,
FLOOD_DEMAND = 19,
TIME_SLICED_SURVEY_REQUEST = 21,
TIME_SLICED_SURVEY_RESPONSE = 22,
TIME_SLICED_SURVEY_START_COLLECTING = 23,
TIME_SLICED_SURVEY_STOP_COLLECTING = 24
};
struct DontHave
{
MessageType type;
uint256 reqHash;
};
enum SurveyMessageCommandType
{
SURVEY_TOPOLOGY = 0,
TIME_SLICED_SURVEY_TOPOLOGY = 1
};
enum SurveyMessageResponseType
{
SURVEY_TOPOLOGY_RESPONSE_V0 = 0,
SURVEY_TOPOLOGY_RESPONSE_V1 = 1,
SURVEY_TOPOLOGY_RESPONSE_V2 = 2
};
struct TimeSlicedSurveyStartCollectingMessage
{
NodeID surveyorID;
uint32 nonce;
uint32 ledgerNum;
};
struct SignedTimeSlicedSurveyStartCollectingMessage
{
Signature signature;
TimeSlicedSurveyStartCollectingMessage startCollecting;
};
struct TimeSlicedSurveyStopCollectingMessage
{
NodeID surveyorID;
uint32 nonce;
uint32 ledgerNum;
};
struct SignedTimeSlicedSurveyStopCollectingMessage
{
Signature signature;
TimeSlicedSurveyStopCollectingMessage stopCollecting;
};
struct SurveyRequestMessage
{
NodeID surveyorPeerID;
NodeID surveyedPeerID;
uint32 ledgerNum;
Curve25519Public encryptionKey;
SurveyMessageCommandType commandType;
};
struct TimeSlicedSurveyRequestMessage
{
SurveyRequestMessage request;
uint32 nonce;
uint32 inboundPeersIndex;
uint32 outboundPeersIndex;
};
struct SignedSurveyRequestMessage
{
Signature requestSignature;
SurveyRequestMessage request;
};
struct SignedTimeSlicedSurveyRequestMessage
{
Signature requestSignature;
TimeSlicedSurveyRequestMessage request;
};
typedef opaque EncryptedBody<64000>;
struct SurveyResponseMessage
{
NodeID surveyorPeerID;
NodeID surveyedPeerID;
uint32 ledgerNum;
SurveyMessageCommandType commandType;
EncryptedBody encryptedBody;
};
struct TimeSlicedSurveyResponseMessage
{
SurveyResponseMessage response;
uint32 nonce;
};
struct SignedSurveyResponseMessage
{
Signature responseSignature;
SurveyResponseMessage response;
};
struct SignedTimeSlicedSurveyResponseMessage
{
Signature responseSignature;
TimeSlicedSurveyResponseMessage response;
};
struct PeerStats
{
NodeID id;
string versionStr<100>;
uint64 messagesRead;
uint64 messagesWritten;
uint64 bytesRead;
uint64 bytesWritten;
uint64 secondsConnected;
uint64 uniqueFloodBytesRecv;
uint64 duplicateFloodBytesRecv;
uint64 uniqueFetchBytesRecv;
uint64 duplicateFetchBytesRecv;
uint64 uniqueFloodMessageRecv;
uint64 duplicateFloodMessageRecv;
uint64 uniqueFetchMessageRecv;
uint64 duplicateFetchMessageRecv;
};
typedef PeerStats PeerStatList<25>;
struct TimeSlicedNodeData
{
uint32 addedAuthenticatedPeers;
uint32 droppedAuthenticatedPeers;
uint32 totalInboundPeerCount;
uint32 totalOutboundPeerCount;
// SCP stats
uint32 p75SCPFirstToSelfLatencyMs;
uint32 p75SCPSelfToOtherLatencyMs;
// How many times the node lost sync in the time slice
uint32 lostSyncCount;
// Config data
bool isValidator;
uint32 maxInboundPeerCount;
uint32 maxOutboundPeerCount;
};
struct TimeSlicedPeerData
{
PeerStats peerStats;
uint32 averageLatencyMs;
};
typedef TimeSlicedPeerData TimeSlicedPeerDataList<25>;
struct TopologyResponseBodyV0
{
PeerStatList inboundPeers;
PeerStatList outboundPeers;
uint32 totalInboundPeerCount;
uint32 totalOutboundPeerCount;
};
struct TopologyResponseBodyV1
{
PeerStatList inboundPeers;
PeerStatList outboundPeers;
uint32 totalInboundPeerCount;
uint32 totalOutboundPeerCount;
uint32 maxInboundPeerCount;
uint32 maxOutboundPeerCount;
};
struct TopologyResponseBodyV2
{
TimeSlicedPeerDataList inboundPeers;
TimeSlicedPeerDataList outboundPeers;
TimeSlicedNodeData nodeData;
};
union SurveyResponseBody switch (SurveyMessageResponseType type)
{
case SURVEY_TOPOLOGY_RESPONSE_V0:
TopologyResponseBodyV0 topologyResponseBodyV0;
case SURVEY_TOPOLOGY_RESPONSE_V1:
TopologyResponseBodyV1 topologyResponseBodyV1;
case SURVEY_TOPOLOGY_RESPONSE_V2:
TopologyResponseBodyV2 topologyResponseBodyV2;
};
const TX_ADVERT_VECTOR_MAX_SIZE = 1000;
typedef Hash TxAdvertVector<TX_ADVERT_VECTOR_MAX_SIZE>;
struct FloodAdvert
{
TxAdvertVector txHashes;
};
const TX_DEMAND_VECTOR_MAX_SIZE = 1000;
typedef Hash TxDemandVector<TX_DEMAND_VECTOR_MAX_SIZE>;
struct FloodDemand
{
TxDemandVector txHashes;
};
union StellarMessage switch (MessageType type)
{
case ERROR_MSG:
Error error;
case HELLO:
Hello hello;
case AUTH:
Auth auth;
case DONT_HAVE:
DontHave dontHave;
case GET_PEERS:
void;
case PEERS:
PeerAddress peers<100>;
case GET_TX_SET:
uint256 txSetHash;
case TX_SET:
TransactionSet txSet;
case GENERALIZED_TX_SET:
GeneralizedTransactionSet generalizedTxSet;
case TRANSACTION:
TransactionEnvelope transaction;
case SURVEY_REQUEST:
SignedSurveyRequestMessage signedSurveyRequestMessage;
case SURVEY_RESPONSE:
SignedSurveyResponseMessage signedSurveyResponseMessage;
case TIME_SLICED_SURVEY_REQUEST:
SignedTimeSlicedSurveyRequestMessage signedTimeSlicedSurveyRequestMessage;
case TIME_SLICED_SURVEY_RESPONSE:
SignedTimeSlicedSurveyResponseMessage signedTimeSlicedSurveyResponseMessage;
case TIME_SLICED_SURVEY_START_COLLECTING:
SignedTimeSlicedSurveyStartCollectingMessage
signedTimeSlicedSurveyStartCollectingMessage;
case TIME_SLICED_SURVEY_STOP_COLLECTING:
SignedTimeSlicedSurveyStopCollectingMessage
signedTimeSlicedSurveyStopCollectingMessage;
// SCP
case GET_SCP_QUORUMSET:
uint256 qSetHash;
case SCP_QUORUMSET:
SCPQuorumSet qSet;
case SCP_MESSAGE:
SCPEnvelope envelope;
case GET_SCP_STATE:
uint32 getSCPLedgerSeq; // ledger seq requested ; if 0, requests the latest
case SEND_MORE:
SendMore sendMoreMessage;
case SEND_MORE_EXTENDED:
SendMoreExtended sendMoreExtendedMessage;
// Pull mode
case FLOOD_ADVERT:
FloodAdvert floodAdvert;
case FLOOD_DEMAND:
FloodDemand floodDemand;
};
union AuthenticatedMessage switch (uint32 v)
{
case 0:
struct
{
uint64 sequence;
StellarMessage message;
HmacSha256Mac mac;
} v0;
};
}