@libp2p/kad-dht 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/kad-dht.d.ts +2 -2
- package/dist/src/message/dht.d.ts +46 -287
- package/dist/src/message/dht.d.ts.map +1 -0
- package/dist/src/message/dht.js +75 -913
- package/dist/src/message/dht.js.map +1 -0
- package/dist/src/message/index.d.ts +8 -8
- package/dist/src/message/index.d.ts.map +1 -1
- package/dist/src/message/index.js +7 -7
- package/dist/src/message/index.js.map +1 -1
- package/dist/src/network.d.ts +2 -2
- package/dist/src/network.d.ts.map +1 -1
- package/dist/src/network.js +3 -3
- package/dist/src/network.js.map +1 -1
- package/dist/src/peer-list/index.d.ts +1 -1
- package/dist/src/peer-list/index.js +1 -1
- package/dist/src/peer-routing/index.d.ts +2 -2
- package/dist/src/peer-routing/index.d.ts.map +1 -1
- package/dist/src/peer-routing/index.js +3 -0
- package/dist/src/peer-routing/index.js.map +1 -1
- package/dist/src/query/events.d.ts +9 -8
- package/dist/src/query/events.d.ts.map +1 -1
- package/dist/src/query/events.js +3 -13
- package/dist/src/query/events.js.map +1 -1
- package/dist/src/query/manager.d.ts.map +1 -1
- package/dist/src/query/manager.js +2 -3
- package/dist/src/query/manager.js.map +1 -1
- package/dist/src/rpc/handlers/get-providers.d.ts +2 -2
- package/dist/src/rpc/handlers/get-value.js +1 -1
- package/dist/src/rpc/handlers/get-value.js.map +1 -1
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/index.js +2 -2
- package/dist/src/rpc/index.js.map +1 -1
- package/dist/src/utils.d.ts +3 -3
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +6 -2
- package/dist/src/utils.js.map +1 -1
- package/package.json +19 -22
- package/src/content-routing/index.ts +2 -2
- package/src/kad-dht.ts +2 -2
- package/src/message/dht.ts +112 -0
- package/src/message/index.ts +15 -17
- package/src/network.ts +5 -5
- package/src/peer-list/index.ts +1 -1
- package/src/peer-routing/index.ts +6 -2
- package/src/query/events.ts +12 -22
- package/src/query/manager.ts +2 -4
- package/src/rpc/handlers/get-providers.ts +2 -2
- package/src/rpc/handlers/get-value.ts +1 -1
- package/src/rpc/index.ts +3 -3
- package/src/utils.ts +11 -5
- package/src/message/dht.d.ts +0 -297
- package/src/message/dht.js +0 -921
package/dist/src/message/dht.js
CHANGED
|
@@ -1,921 +1,83 @@
|
|
|
1
|
-
/*eslint-disable*/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @exports IRecord
|
|
15
|
-
* @interface IRecord
|
|
16
|
-
* @property {Uint8Array|null} [key] Record key
|
|
17
|
-
* @property {Uint8Array|null} [value] Record value
|
|
18
|
-
* @property {Uint8Array|null} [author] Record author
|
|
19
|
-
* @property {Uint8Array|null} [signature] Record signature
|
|
20
|
-
* @property {string|null} [timeReceived] Record timeReceived
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Constructs a new Record.
|
|
25
|
-
* @exports Record
|
|
26
|
-
* @classdesc Represents a Record.
|
|
27
|
-
* @implements IRecord
|
|
28
|
-
* @constructor
|
|
29
|
-
* @param {IRecord=} [p] Properties to set
|
|
30
|
-
*/
|
|
31
|
-
function Record(p) {
|
|
32
|
-
if (p)
|
|
33
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
34
|
-
if (p[ks[i]] != null)
|
|
35
|
-
this[ks[i]] = p[ks[i]];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Record key.
|
|
40
|
-
* @member {Uint8Array|null|undefined} key
|
|
41
|
-
* @memberof Record
|
|
42
|
-
* @instance
|
|
43
|
-
*/
|
|
44
|
-
Record.prototype.key = null;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Record value.
|
|
48
|
-
* @member {Uint8Array|null|undefined} value
|
|
49
|
-
* @memberof Record
|
|
50
|
-
* @instance
|
|
51
|
-
*/
|
|
52
|
-
Record.prototype.value = null;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Record author.
|
|
56
|
-
* @member {Uint8Array|null|undefined} author
|
|
57
|
-
* @memberof Record
|
|
58
|
-
* @instance
|
|
59
|
-
*/
|
|
60
|
-
Record.prototype.author = null;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Record signature.
|
|
64
|
-
* @member {Uint8Array|null|undefined} signature
|
|
65
|
-
* @memberof Record
|
|
66
|
-
* @instance
|
|
67
|
-
*/
|
|
68
|
-
Record.prototype.signature = null;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Record timeReceived.
|
|
72
|
-
* @member {string|null|undefined} timeReceived
|
|
73
|
-
* @memberof Record
|
|
74
|
-
* @instance
|
|
75
|
-
*/
|
|
76
|
-
Record.prototype.timeReceived = null;
|
|
77
|
-
|
|
78
|
-
// OneOf field names bound to virtual getters and setters
|
|
79
|
-
let $oneOfFields;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Record _key.
|
|
83
|
-
* @member {"key"|undefined} _key
|
|
84
|
-
* @memberof Record
|
|
85
|
-
* @instance
|
|
86
|
-
*/
|
|
87
|
-
Object.defineProperty(Record.prototype, "_key", {
|
|
88
|
-
get: $util.oneOfGetter($oneOfFields = ["key"]),
|
|
89
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Record _value.
|
|
94
|
-
* @member {"value"|undefined} _value
|
|
95
|
-
* @memberof Record
|
|
96
|
-
* @instance
|
|
97
|
-
*/
|
|
98
|
-
Object.defineProperty(Record.prototype, "_value", {
|
|
99
|
-
get: $util.oneOfGetter($oneOfFields = ["value"]),
|
|
100
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Record _author.
|
|
105
|
-
* @member {"author"|undefined} _author
|
|
106
|
-
* @memberof Record
|
|
107
|
-
* @instance
|
|
108
|
-
*/
|
|
109
|
-
Object.defineProperty(Record.prototype, "_author", {
|
|
110
|
-
get: $util.oneOfGetter($oneOfFields = ["author"]),
|
|
111
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Record _signature.
|
|
116
|
-
* @member {"signature"|undefined} _signature
|
|
117
|
-
* @memberof Record
|
|
118
|
-
* @instance
|
|
119
|
-
*/
|
|
120
|
-
Object.defineProperty(Record.prototype, "_signature", {
|
|
121
|
-
get: $util.oneOfGetter($oneOfFields = ["signature"]),
|
|
122
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Record _timeReceived.
|
|
127
|
-
* @member {"timeReceived"|undefined} _timeReceived
|
|
128
|
-
* @memberof Record
|
|
129
|
-
* @instance
|
|
130
|
-
*/
|
|
131
|
-
Object.defineProperty(Record.prototype, "_timeReceived", {
|
|
132
|
-
get: $util.oneOfGetter($oneOfFields = ["timeReceived"]),
|
|
133
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
|
|
138
|
-
* @function encode
|
|
139
|
-
* @memberof Record
|
|
140
|
-
* @static
|
|
141
|
-
* @param {IRecord} m Record message or plain object to encode
|
|
142
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
143
|
-
* @returns {$protobuf.Writer} Writer
|
|
144
|
-
*/
|
|
145
|
-
Record.encode = function encode(m, w) {
|
|
146
|
-
if (!w)
|
|
147
|
-
w = $Writer.create();
|
|
148
|
-
if (m.key != null && Object.hasOwnProperty.call(m, "key"))
|
|
149
|
-
w.uint32(10).bytes(m.key);
|
|
150
|
-
if (m.value != null && Object.hasOwnProperty.call(m, "value"))
|
|
151
|
-
w.uint32(18).bytes(m.value);
|
|
152
|
-
if (m.author != null && Object.hasOwnProperty.call(m, "author"))
|
|
153
|
-
w.uint32(26).bytes(m.author);
|
|
154
|
-
if (m.signature != null && Object.hasOwnProperty.call(m, "signature"))
|
|
155
|
-
w.uint32(34).bytes(m.signature);
|
|
156
|
-
if (m.timeReceived != null && Object.hasOwnProperty.call(m, "timeReceived"))
|
|
157
|
-
w.uint32(42).string(m.timeReceived);
|
|
158
|
-
return w;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Decodes a Record message from the specified reader or buffer.
|
|
163
|
-
* @function decode
|
|
164
|
-
* @memberof Record
|
|
165
|
-
* @static
|
|
166
|
-
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
167
|
-
* @param {number} [l] Message length if known beforehand
|
|
168
|
-
* @returns {Record} Record
|
|
169
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
170
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
171
|
-
*/
|
|
172
|
-
Record.decode = function decode(r, l) {
|
|
173
|
-
if (!(r instanceof $Reader))
|
|
174
|
-
r = $Reader.create(r);
|
|
175
|
-
var c = l === undefined ? r.len : r.pos + l, m = new $root.Record();
|
|
176
|
-
while (r.pos < c) {
|
|
177
|
-
var t = r.uint32();
|
|
178
|
-
switch (t >>> 3) {
|
|
179
|
-
case 1:
|
|
180
|
-
m.key = r.bytes();
|
|
181
|
-
break;
|
|
182
|
-
case 2:
|
|
183
|
-
m.value = r.bytes();
|
|
184
|
-
break;
|
|
185
|
-
case 3:
|
|
186
|
-
m.author = r.bytes();
|
|
187
|
-
break;
|
|
188
|
-
case 4:
|
|
189
|
-
m.signature = r.bytes();
|
|
190
|
-
break;
|
|
191
|
-
case 5:
|
|
192
|
-
m.timeReceived = r.string();
|
|
193
|
-
break;
|
|
194
|
-
default:
|
|
195
|
-
r.skipType(t & 7);
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return m;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Creates a Record message from a plain object. Also converts values to their respective internal types.
|
|
204
|
-
* @function fromObject
|
|
205
|
-
* @memberof Record
|
|
206
|
-
* @static
|
|
207
|
-
* @param {Object.<string,*>} d Plain object
|
|
208
|
-
* @returns {Record} Record
|
|
209
|
-
*/
|
|
210
|
-
Record.fromObject = function fromObject(d) {
|
|
211
|
-
if (d instanceof $root.Record)
|
|
212
|
-
return d;
|
|
213
|
-
var m = new $root.Record();
|
|
214
|
-
if (d.key != null) {
|
|
215
|
-
if (typeof d.key === "string")
|
|
216
|
-
$util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0);
|
|
217
|
-
else if (d.key.length)
|
|
218
|
-
m.key = d.key;
|
|
219
|
-
}
|
|
220
|
-
if (d.value != null) {
|
|
221
|
-
if (typeof d.value === "string")
|
|
222
|
-
$util.base64.decode(d.value, m.value = $util.newBuffer($util.base64.length(d.value)), 0);
|
|
223
|
-
else if (d.value.length)
|
|
224
|
-
m.value = d.value;
|
|
225
|
-
}
|
|
226
|
-
if (d.author != null) {
|
|
227
|
-
if (typeof d.author === "string")
|
|
228
|
-
$util.base64.decode(d.author, m.author = $util.newBuffer($util.base64.length(d.author)), 0);
|
|
229
|
-
else if (d.author.length)
|
|
230
|
-
m.author = d.author;
|
|
231
|
-
}
|
|
232
|
-
if (d.signature != null) {
|
|
233
|
-
if (typeof d.signature === "string")
|
|
234
|
-
$util.base64.decode(d.signature, m.signature = $util.newBuffer($util.base64.length(d.signature)), 0);
|
|
235
|
-
else if (d.signature.length)
|
|
236
|
-
m.signature = d.signature;
|
|
237
|
-
}
|
|
238
|
-
if (d.timeReceived != null) {
|
|
239
|
-
m.timeReceived = String(d.timeReceived);
|
|
240
|
-
}
|
|
241
|
-
return m;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Creates a plain object from a Record message. Also converts values to other types if specified.
|
|
246
|
-
* @function toObject
|
|
247
|
-
* @memberof Record
|
|
248
|
-
* @static
|
|
249
|
-
* @param {Record} m Record
|
|
250
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
251
|
-
* @returns {Object.<string,*>} Plain object
|
|
252
|
-
*/
|
|
253
|
-
Record.toObject = function toObject(m, o) {
|
|
254
|
-
if (!o)
|
|
255
|
-
o = {};
|
|
256
|
-
var d = {};
|
|
257
|
-
if (m.key != null && m.hasOwnProperty("key")) {
|
|
258
|
-
d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key;
|
|
259
|
-
if (o.oneofs)
|
|
260
|
-
d._key = "key";
|
|
261
|
-
}
|
|
262
|
-
if (m.value != null && m.hasOwnProperty("value")) {
|
|
263
|
-
d.value = o.bytes === String ? $util.base64.encode(m.value, 0, m.value.length) : o.bytes === Array ? Array.prototype.slice.call(m.value) : m.value;
|
|
264
|
-
if (o.oneofs)
|
|
265
|
-
d._value = "value";
|
|
266
|
-
}
|
|
267
|
-
if (m.author != null && m.hasOwnProperty("author")) {
|
|
268
|
-
d.author = o.bytes === String ? $util.base64.encode(m.author, 0, m.author.length) : o.bytes === Array ? Array.prototype.slice.call(m.author) : m.author;
|
|
269
|
-
if (o.oneofs)
|
|
270
|
-
d._author = "author";
|
|
271
|
-
}
|
|
272
|
-
if (m.signature != null && m.hasOwnProperty("signature")) {
|
|
273
|
-
d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature;
|
|
274
|
-
if (o.oneofs)
|
|
275
|
-
d._signature = "signature";
|
|
276
|
-
}
|
|
277
|
-
if (m.timeReceived != null && m.hasOwnProperty("timeReceived")) {
|
|
278
|
-
d.timeReceived = m.timeReceived;
|
|
279
|
-
if (o.oneofs)
|
|
280
|
-
d._timeReceived = "timeReceived";
|
|
281
|
-
}
|
|
282
|
-
return d;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Converts this Record to JSON.
|
|
287
|
-
* @function toJSON
|
|
288
|
-
* @memberof Record
|
|
289
|
-
* @instance
|
|
290
|
-
* @returns {Object.<string,*>} JSON object
|
|
291
|
-
*/
|
|
292
|
-
Record.prototype.toJSON = function toJSON() {
|
|
293
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
return Record;
|
|
297
|
-
})();
|
|
298
|
-
|
|
299
|
-
export const Message = $root.Message = (() => {
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Properties of a Message.
|
|
303
|
-
* @exports IMessage
|
|
304
|
-
* @interface IMessage
|
|
305
|
-
* @property {Message.MessageType|null} [type] Message type
|
|
306
|
-
* @property {number|null} [clusterLevelRaw] Message clusterLevelRaw
|
|
307
|
-
* @property {Uint8Array|null} [key] Message key
|
|
308
|
-
* @property {Uint8Array|null} [record] Message record
|
|
309
|
-
* @property {Array.<Message.IPeer>|null} [closerPeers] Message closerPeers
|
|
310
|
-
* @property {Array.<Message.IPeer>|null} [providerPeers] Message providerPeers
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Constructs a new Message.
|
|
315
|
-
* @exports Message
|
|
316
|
-
* @classdesc Represents a Message.
|
|
317
|
-
* @implements IMessage
|
|
318
|
-
* @constructor
|
|
319
|
-
* @param {IMessage=} [p] Properties to set
|
|
320
|
-
*/
|
|
321
|
-
function Message(p) {
|
|
322
|
-
this.closerPeers = [];
|
|
323
|
-
this.providerPeers = [];
|
|
324
|
-
if (p)
|
|
325
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
326
|
-
if (p[ks[i]] != null)
|
|
327
|
-
this[ks[i]] = p[ks[i]];
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Message type.
|
|
332
|
-
* @member {Message.MessageType|null|undefined} type
|
|
333
|
-
* @memberof Message
|
|
334
|
-
* @instance
|
|
335
|
-
*/
|
|
336
|
-
Message.prototype.type = null;
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Message clusterLevelRaw.
|
|
340
|
-
* @member {number|null|undefined} clusterLevelRaw
|
|
341
|
-
* @memberof Message
|
|
342
|
-
* @instance
|
|
343
|
-
*/
|
|
344
|
-
Message.prototype.clusterLevelRaw = null;
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Message key.
|
|
348
|
-
* @member {Uint8Array|null|undefined} key
|
|
349
|
-
* @memberof Message
|
|
350
|
-
* @instance
|
|
351
|
-
*/
|
|
352
|
-
Message.prototype.key = null;
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Message record.
|
|
356
|
-
* @member {Uint8Array|null|undefined} record
|
|
357
|
-
* @memberof Message
|
|
358
|
-
* @instance
|
|
359
|
-
*/
|
|
360
|
-
Message.prototype.record = null;
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Message closerPeers.
|
|
364
|
-
* @member {Array.<Message.IPeer>} closerPeers
|
|
365
|
-
* @memberof Message
|
|
366
|
-
* @instance
|
|
367
|
-
*/
|
|
368
|
-
Message.prototype.closerPeers = $util.emptyArray;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Message providerPeers.
|
|
372
|
-
* @member {Array.<Message.IPeer>} providerPeers
|
|
373
|
-
* @memberof Message
|
|
374
|
-
* @instance
|
|
375
|
-
*/
|
|
376
|
-
Message.prototype.providerPeers = $util.emptyArray;
|
|
377
|
-
|
|
378
|
-
// OneOf field names bound to virtual getters and setters
|
|
379
|
-
let $oneOfFields;
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Message _type.
|
|
383
|
-
* @member {"type"|undefined} _type
|
|
384
|
-
* @memberof Message
|
|
385
|
-
* @instance
|
|
386
|
-
*/
|
|
387
|
-
Object.defineProperty(Message.prototype, "_type", {
|
|
388
|
-
get: $util.oneOfGetter($oneOfFields = ["type"]),
|
|
389
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Message _clusterLevelRaw.
|
|
394
|
-
* @member {"clusterLevelRaw"|undefined} _clusterLevelRaw
|
|
395
|
-
* @memberof Message
|
|
396
|
-
* @instance
|
|
397
|
-
*/
|
|
398
|
-
Object.defineProperty(Message.prototype, "_clusterLevelRaw", {
|
|
399
|
-
get: $util.oneOfGetter($oneOfFields = ["clusterLevelRaw"]),
|
|
400
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Message _key.
|
|
405
|
-
* @member {"key"|undefined} _key
|
|
406
|
-
* @memberof Message
|
|
407
|
-
* @instance
|
|
408
|
-
*/
|
|
409
|
-
Object.defineProperty(Message.prototype, "_key", {
|
|
410
|
-
get: $util.oneOfGetter($oneOfFields = ["key"]),
|
|
411
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Message _record.
|
|
416
|
-
* @member {"record"|undefined} _record
|
|
417
|
-
* @memberof Message
|
|
418
|
-
* @instance
|
|
419
|
-
*/
|
|
420
|
-
Object.defineProperty(Message.prototype, "_record", {
|
|
421
|
-
get: $util.oneOfGetter($oneOfFields = ["record"]),
|
|
422
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Encodes the specified Message message. Does not implicitly {@link Message.verify|verify} messages.
|
|
427
|
-
* @function encode
|
|
428
|
-
* @memberof Message
|
|
429
|
-
* @static
|
|
430
|
-
* @param {IMessage} m Message message or plain object to encode
|
|
431
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
432
|
-
* @returns {$protobuf.Writer} Writer
|
|
433
|
-
*/
|
|
434
|
-
Message.encode = function encode(m, w) {
|
|
435
|
-
if (!w)
|
|
436
|
-
w = $Writer.create();
|
|
437
|
-
if (m.type != null && Object.hasOwnProperty.call(m, "type"))
|
|
438
|
-
w.uint32(8).int32(m.type);
|
|
439
|
-
if (m.key != null && Object.hasOwnProperty.call(m, "key"))
|
|
440
|
-
w.uint32(18).bytes(m.key);
|
|
441
|
-
if (m.record != null && Object.hasOwnProperty.call(m, "record"))
|
|
442
|
-
w.uint32(26).bytes(m.record);
|
|
443
|
-
if (m.closerPeers != null && m.closerPeers.length) {
|
|
444
|
-
for (var i = 0; i < m.closerPeers.length; ++i)
|
|
445
|
-
$root.Message.Peer.encode(m.closerPeers[i], w.uint32(66).fork()).ldelim();
|
|
446
|
-
}
|
|
447
|
-
if (m.providerPeers != null && m.providerPeers.length) {
|
|
448
|
-
for (var i = 0; i < m.providerPeers.length; ++i)
|
|
449
|
-
$root.Message.Peer.encode(m.providerPeers[i], w.uint32(74).fork()).ldelim();
|
|
450
|
-
}
|
|
451
|
-
if (m.clusterLevelRaw != null && Object.hasOwnProperty.call(m, "clusterLevelRaw"))
|
|
452
|
-
w.uint32(80).int32(m.clusterLevelRaw);
|
|
453
|
-
return w;
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
/**
|
|
457
|
-
* Decodes a Message message from the specified reader or buffer.
|
|
458
|
-
* @function decode
|
|
459
|
-
* @memberof Message
|
|
460
|
-
* @static
|
|
461
|
-
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
462
|
-
* @param {number} [l] Message length if known beforehand
|
|
463
|
-
* @returns {Message} Message
|
|
464
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
465
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
466
|
-
*/
|
|
467
|
-
Message.decode = function decode(r, l) {
|
|
468
|
-
if (!(r instanceof $Reader))
|
|
469
|
-
r = $Reader.create(r);
|
|
470
|
-
var c = l === undefined ? r.len : r.pos + l, m = new $root.Message();
|
|
471
|
-
while (r.pos < c) {
|
|
472
|
-
var t = r.uint32();
|
|
473
|
-
switch (t >>> 3) {
|
|
474
|
-
case 1:
|
|
475
|
-
m.type = r.int32();
|
|
476
|
-
break;
|
|
477
|
-
case 10:
|
|
478
|
-
m.clusterLevelRaw = r.int32();
|
|
479
|
-
break;
|
|
480
|
-
case 2:
|
|
481
|
-
m.key = r.bytes();
|
|
482
|
-
break;
|
|
483
|
-
case 3:
|
|
484
|
-
m.record = r.bytes();
|
|
485
|
-
break;
|
|
486
|
-
case 8:
|
|
487
|
-
if (!(m.closerPeers && m.closerPeers.length))
|
|
488
|
-
m.closerPeers = [];
|
|
489
|
-
m.closerPeers.push($root.Message.Peer.decode(r, r.uint32()));
|
|
490
|
-
break;
|
|
491
|
-
case 9:
|
|
492
|
-
if (!(m.providerPeers && m.providerPeers.length))
|
|
493
|
-
m.providerPeers = [];
|
|
494
|
-
m.providerPeers.push($root.Message.Peer.decode(r, r.uint32()));
|
|
495
|
-
break;
|
|
496
|
-
default:
|
|
497
|
-
r.skipType(t & 7);
|
|
498
|
-
break;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return m;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Creates a Message message from a plain object. Also converts values to their respective internal types.
|
|
506
|
-
* @function fromObject
|
|
507
|
-
* @memberof Message
|
|
508
|
-
* @static
|
|
509
|
-
* @param {Object.<string,*>} d Plain object
|
|
510
|
-
* @returns {Message} Message
|
|
511
|
-
*/
|
|
512
|
-
Message.fromObject = function fromObject(d) {
|
|
513
|
-
if (d instanceof $root.Message)
|
|
514
|
-
return d;
|
|
515
|
-
var m = new $root.Message();
|
|
516
|
-
switch (d.type) {
|
|
517
|
-
case "PUT_VALUE":
|
|
518
|
-
case 0:
|
|
519
|
-
m.type = 0;
|
|
520
|
-
break;
|
|
521
|
-
case "GET_VALUE":
|
|
522
|
-
case 1:
|
|
523
|
-
m.type = 1;
|
|
524
|
-
break;
|
|
525
|
-
case "ADD_PROVIDER":
|
|
526
|
-
case 2:
|
|
527
|
-
m.type = 2;
|
|
528
|
-
break;
|
|
529
|
-
case "GET_PROVIDERS":
|
|
530
|
-
case 3:
|
|
531
|
-
m.type = 3;
|
|
532
|
-
break;
|
|
533
|
-
case "FIND_NODE":
|
|
534
|
-
case 4:
|
|
535
|
-
m.type = 4;
|
|
536
|
-
break;
|
|
537
|
-
case "PING":
|
|
538
|
-
case 5:
|
|
539
|
-
m.type = 5;
|
|
540
|
-
break;
|
|
541
|
-
}
|
|
542
|
-
if (d.clusterLevelRaw != null) {
|
|
543
|
-
m.clusterLevelRaw = d.clusterLevelRaw | 0;
|
|
544
|
-
}
|
|
545
|
-
if (d.key != null) {
|
|
546
|
-
if (typeof d.key === "string")
|
|
547
|
-
$util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0);
|
|
548
|
-
else if (d.key.length)
|
|
549
|
-
m.key = d.key;
|
|
550
|
-
}
|
|
551
|
-
if (d.record != null) {
|
|
552
|
-
if (typeof d.record === "string")
|
|
553
|
-
$util.base64.decode(d.record, m.record = $util.newBuffer($util.base64.length(d.record)), 0);
|
|
554
|
-
else if (d.record.length)
|
|
555
|
-
m.record = d.record;
|
|
556
|
-
}
|
|
557
|
-
if (d.closerPeers) {
|
|
558
|
-
if (!Array.isArray(d.closerPeers))
|
|
559
|
-
throw TypeError(".Message.closerPeers: array expected");
|
|
560
|
-
m.closerPeers = [];
|
|
561
|
-
for (var i = 0; i < d.closerPeers.length; ++i) {
|
|
562
|
-
if (typeof d.closerPeers[i] !== "object")
|
|
563
|
-
throw TypeError(".Message.closerPeers: object expected");
|
|
564
|
-
m.closerPeers[i] = $root.Message.Peer.fromObject(d.closerPeers[i]);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
if (d.providerPeers) {
|
|
568
|
-
if (!Array.isArray(d.providerPeers))
|
|
569
|
-
throw TypeError(".Message.providerPeers: array expected");
|
|
570
|
-
m.providerPeers = [];
|
|
571
|
-
for (var i = 0; i < d.providerPeers.length; ++i) {
|
|
572
|
-
if (typeof d.providerPeers[i] !== "object")
|
|
573
|
-
throw TypeError(".Message.providerPeers: object expected");
|
|
574
|
-
m.providerPeers[i] = $root.Message.Peer.fromObject(d.providerPeers[i]);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return m;
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
import { encodeMessage, decodeMessage, message, bytes, string, enumeration, int32 } from 'protons-runtime';
|
|
4
|
+
export var Record;
|
|
5
|
+
(function (Record) {
|
|
6
|
+
Record.codec = () => {
|
|
7
|
+
return message({
|
|
8
|
+
1: { name: 'key', codec: bytes, optional: true },
|
|
9
|
+
2: { name: 'value', codec: bytes, optional: true },
|
|
10
|
+
3: { name: 'author', codec: bytes, optional: true },
|
|
11
|
+
4: { name: 'signature', codec: bytes, optional: true },
|
|
12
|
+
5: { name: 'timeReceived', codec: string, optional: true }
|
|
13
|
+
});
|
|
578
14
|
};
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
* Creates a plain object from a Message message. Also converts values to other types if specified.
|
|
582
|
-
* @function toObject
|
|
583
|
-
* @memberof Message
|
|
584
|
-
* @static
|
|
585
|
-
* @param {Message} m Message
|
|
586
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
587
|
-
* @returns {Object.<string,*>} Plain object
|
|
588
|
-
*/
|
|
589
|
-
Message.toObject = function toObject(m, o) {
|
|
590
|
-
if (!o)
|
|
591
|
-
o = {};
|
|
592
|
-
var d = {};
|
|
593
|
-
if (o.arrays || o.defaults) {
|
|
594
|
-
d.closerPeers = [];
|
|
595
|
-
d.providerPeers = [];
|
|
596
|
-
}
|
|
597
|
-
if (m.type != null && m.hasOwnProperty("type")) {
|
|
598
|
-
d.type = o.enums === String ? $root.Message.MessageType[m.type] : m.type;
|
|
599
|
-
if (o.oneofs)
|
|
600
|
-
d._type = "type";
|
|
601
|
-
}
|
|
602
|
-
if (m.key != null && m.hasOwnProperty("key")) {
|
|
603
|
-
d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key;
|
|
604
|
-
if (o.oneofs)
|
|
605
|
-
d._key = "key";
|
|
606
|
-
}
|
|
607
|
-
if (m.record != null && m.hasOwnProperty("record")) {
|
|
608
|
-
d.record = o.bytes === String ? $util.base64.encode(m.record, 0, m.record.length) : o.bytes === Array ? Array.prototype.slice.call(m.record) : m.record;
|
|
609
|
-
if (o.oneofs)
|
|
610
|
-
d._record = "record";
|
|
611
|
-
}
|
|
612
|
-
if (m.closerPeers && m.closerPeers.length) {
|
|
613
|
-
d.closerPeers = [];
|
|
614
|
-
for (var j = 0; j < m.closerPeers.length; ++j) {
|
|
615
|
-
d.closerPeers[j] = $root.Message.Peer.toObject(m.closerPeers[j], o);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
if (m.providerPeers && m.providerPeers.length) {
|
|
619
|
-
d.providerPeers = [];
|
|
620
|
-
for (var j = 0; j < m.providerPeers.length; ++j) {
|
|
621
|
-
d.providerPeers[j] = $root.Message.Peer.toObject(m.providerPeers[j], o);
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
if (m.clusterLevelRaw != null && m.hasOwnProperty("clusterLevelRaw")) {
|
|
625
|
-
d.clusterLevelRaw = m.clusterLevelRaw;
|
|
626
|
-
if (o.oneofs)
|
|
627
|
-
d._clusterLevelRaw = "clusterLevelRaw";
|
|
628
|
-
}
|
|
629
|
-
return d;
|
|
15
|
+
Record.encode = (obj) => {
|
|
16
|
+
return encodeMessage(obj, Record.codec());
|
|
630
17
|
};
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
* Converts this Message to JSON.
|
|
634
|
-
* @function toJSON
|
|
635
|
-
* @memberof Message
|
|
636
|
-
* @instance
|
|
637
|
-
* @returns {Object.<string,*>} JSON object
|
|
638
|
-
*/
|
|
639
|
-
Message.prototype.toJSON = function toJSON() {
|
|
640
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
18
|
+
Record.decode = (buf) => {
|
|
19
|
+
return decodeMessage(buf, Record.codec());
|
|
641
20
|
};
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
values[valuesById[1] = "GET_VALUE"] = 1;
|
|
658
|
-
values[valuesById[2] = "ADD_PROVIDER"] = 2;
|
|
659
|
-
values[valuesById[3] = "GET_PROVIDERS"] = 3;
|
|
660
|
-
values[valuesById[4] = "FIND_NODE"] = 4;
|
|
661
|
-
values[valuesById[5] = "PING"] = 5;
|
|
662
|
-
return values;
|
|
663
|
-
})();
|
|
664
|
-
|
|
665
|
-
/**
|
|
666
|
-
* ConnectionType enum.
|
|
667
|
-
* @name Message.ConnectionType
|
|
668
|
-
* @enum {number}
|
|
669
|
-
* @property {number} NOT_CONNECTED=0 NOT_CONNECTED value
|
|
670
|
-
* @property {number} CONNECTED=1 CONNECTED value
|
|
671
|
-
* @property {number} CAN_CONNECT=2 CAN_CONNECT value
|
|
672
|
-
* @property {number} CANNOT_CONNECT=3 CANNOT_CONNECT value
|
|
673
|
-
*/
|
|
674
|
-
Message.ConnectionType = (function() {
|
|
675
|
-
const valuesById = {}, values = Object.create(valuesById);
|
|
676
|
-
values[valuesById[0] = "NOT_CONNECTED"] = 0;
|
|
677
|
-
values[valuesById[1] = "CONNECTED"] = 1;
|
|
678
|
-
values[valuesById[2] = "CAN_CONNECT"] = 2;
|
|
679
|
-
values[valuesById[3] = "CANNOT_CONNECT"] = 3;
|
|
680
|
-
return values;
|
|
681
|
-
})();
|
|
682
|
-
|
|
683
|
-
Message.Peer = (function() {
|
|
684
|
-
|
|
685
|
-
/**
|
|
686
|
-
* Properties of a Peer.
|
|
687
|
-
* @memberof Message
|
|
688
|
-
* @interface IPeer
|
|
689
|
-
* @property {Uint8Array|null} [id] Peer id
|
|
690
|
-
* @property {Array.<Uint8Array>|null} [addrs] Peer addrs
|
|
691
|
-
* @property {Message.ConnectionType|null} [connection] Peer connection
|
|
692
|
-
*/
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* Constructs a new Peer.
|
|
696
|
-
* @memberof Message
|
|
697
|
-
* @classdesc Represents a Peer.
|
|
698
|
-
* @implements IPeer
|
|
699
|
-
* @constructor
|
|
700
|
-
* @param {Message.IPeer=} [p] Properties to set
|
|
701
|
-
*/
|
|
702
|
-
function Peer(p) {
|
|
703
|
-
this.addrs = [];
|
|
704
|
-
if (p)
|
|
705
|
-
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
706
|
-
if (p[ks[i]] != null)
|
|
707
|
-
this[ks[i]] = p[ks[i]];
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
/**
|
|
711
|
-
* Peer id.
|
|
712
|
-
* @member {Uint8Array|null|undefined} id
|
|
713
|
-
* @memberof Message.Peer
|
|
714
|
-
* @instance
|
|
715
|
-
*/
|
|
716
|
-
Peer.prototype.id = null;
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* Peer addrs.
|
|
720
|
-
* @member {Array.<Uint8Array>} addrs
|
|
721
|
-
* @memberof Message.Peer
|
|
722
|
-
* @instance
|
|
723
|
-
*/
|
|
724
|
-
Peer.prototype.addrs = $util.emptyArray;
|
|
725
|
-
|
|
726
|
-
/**
|
|
727
|
-
* Peer connection.
|
|
728
|
-
* @member {Message.ConnectionType|null|undefined} connection
|
|
729
|
-
* @memberof Message.Peer
|
|
730
|
-
* @instance
|
|
731
|
-
*/
|
|
732
|
-
Peer.prototype.connection = null;
|
|
733
|
-
|
|
734
|
-
// OneOf field names bound to virtual getters and setters
|
|
735
|
-
let $oneOfFields;
|
|
736
|
-
|
|
737
|
-
/**
|
|
738
|
-
* Peer _id.
|
|
739
|
-
* @member {"id"|undefined} _id
|
|
740
|
-
* @memberof Message.Peer
|
|
741
|
-
* @instance
|
|
742
|
-
*/
|
|
743
|
-
Object.defineProperty(Peer.prototype, "_id", {
|
|
744
|
-
get: $util.oneOfGetter($oneOfFields = ["id"]),
|
|
745
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
/**
|
|
749
|
-
* Peer _connection.
|
|
750
|
-
* @member {"connection"|undefined} _connection
|
|
751
|
-
* @memberof Message.Peer
|
|
752
|
-
* @instance
|
|
753
|
-
*/
|
|
754
|
-
Object.defineProperty(Peer.prototype, "_connection", {
|
|
755
|
-
get: $util.oneOfGetter($oneOfFields = ["connection"]),
|
|
756
|
-
set: $util.oneOfSetter($oneOfFields)
|
|
757
|
-
});
|
|
758
|
-
|
|
759
|
-
/**
|
|
760
|
-
* Encodes the specified Peer message. Does not implicitly {@link Message.Peer.verify|verify} messages.
|
|
761
|
-
* @function encode
|
|
762
|
-
* @memberof Message.Peer
|
|
763
|
-
* @static
|
|
764
|
-
* @param {Message.IPeer} m Peer message or plain object to encode
|
|
765
|
-
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
766
|
-
* @returns {$protobuf.Writer} Writer
|
|
767
|
-
*/
|
|
768
|
-
Peer.encode = function encode(m, w) {
|
|
769
|
-
if (!w)
|
|
770
|
-
w = $Writer.create();
|
|
771
|
-
if (m.id != null && Object.hasOwnProperty.call(m, "id"))
|
|
772
|
-
w.uint32(10).bytes(m.id);
|
|
773
|
-
if (m.addrs != null && m.addrs.length) {
|
|
774
|
-
for (var i = 0; i < m.addrs.length; ++i)
|
|
775
|
-
w.uint32(18).bytes(m.addrs[i]);
|
|
776
|
-
}
|
|
777
|
-
if (m.connection != null && Object.hasOwnProperty.call(m, "connection"))
|
|
778
|
-
w.uint32(24).int32(m.connection);
|
|
779
|
-
return w;
|
|
21
|
+
})(Record || (Record = {}));
|
|
22
|
+
export var Message;
|
|
23
|
+
(function (Message) {
|
|
24
|
+
let MessageType;
|
|
25
|
+
(function (MessageType) {
|
|
26
|
+
MessageType["PUT_VALUE"] = "PUT_VALUE";
|
|
27
|
+
MessageType["GET_VALUE"] = "GET_VALUE";
|
|
28
|
+
MessageType["ADD_PROVIDER"] = "ADD_PROVIDER";
|
|
29
|
+
MessageType["GET_PROVIDERS"] = "GET_PROVIDERS";
|
|
30
|
+
MessageType["FIND_NODE"] = "FIND_NODE";
|
|
31
|
+
MessageType["PING"] = "PING";
|
|
32
|
+
})(MessageType = Message.MessageType || (Message.MessageType = {}));
|
|
33
|
+
(function (MessageType) {
|
|
34
|
+
MessageType.codec = () => {
|
|
35
|
+
return enumeration(MessageType);
|
|
780
36
|
};
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
*/
|
|
793
|
-
Peer.decode = function decode(r, l) {
|
|
794
|
-
if (!(r instanceof $Reader))
|
|
795
|
-
r = $Reader.create(r);
|
|
796
|
-
var c = l === undefined ? r.len : r.pos + l, m = new $root.Message.Peer();
|
|
797
|
-
while (r.pos < c) {
|
|
798
|
-
var t = r.uint32();
|
|
799
|
-
switch (t >>> 3) {
|
|
800
|
-
case 1:
|
|
801
|
-
m.id = r.bytes();
|
|
802
|
-
break;
|
|
803
|
-
case 2:
|
|
804
|
-
if (!(m.addrs && m.addrs.length))
|
|
805
|
-
m.addrs = [];
|
|
806
|
-
m.addrs.push(r.bytes());
|
|
807
|
-
break;
|
|
808
|
-
case 3:
|
|
809
|
-
m.connection = r.int32();
|
|
810
|
-
break;
|
|
811
|
-
default:
|
|
812
|
-
r.skipType(t & 7);
|
|
813
|
-
break;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
return m;
|
|
37
|
+
})(MessageType = Message.MessageType || (Message.MessageType = {}));
|
|
38
|
+
let ConnectionType;
|
|
39
|
+
(function (ConnectionType) {
|
|
40
|
+
ConnectionType["NOT_CONNECTED"] = "NOT_CONNECTED";
|
|
41
|
+
ConnectionType["CONNECTED"] = "CONNECTED";
|
|
42
|
+
ConnectionType["CAN_CONNECT"] = "CAN_CONNECT";
|
|
43
|
+
ConnectionType["CANNOT_CONNECT"] = "CANNOT_CONNECT";
|
|
44
|
+
})(ConnectionType = Message.ConnectionType || (Message.ConnectionType = {}));
|
|
45
|
+
(function (ConnectionType) {
|
|
46
|
+
ConnectionType.codec = () => {
|
|
47
|
+
return enumeration(ConnectionType);
|
|
817
48
|
};
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
Peer.fromObject = function fromObject(d) {
|
|
828
|
-
if (d instanceof $root.Message.Peer)
|
|
829
|
-
return d;
|
|
830
|
-
var m = new $root.Message.Peer();
|
|
831
|
-
if (d.id != null) {
|
|
832
|
-
if (typeof d.id === "string")
|
|
833
|
-
$util.base64.decode(d.id, m.id = $util.newBuffer($util.base64.length(d.id)), 0);
|
|
834
|
-
else if (d.id.length)
|
|
835
|
-
m.id = d.id;
|
|
836
|
-
}
|
|
837
|
-
if (d.addrs) {
|
|
838
|
-
if (!Array.isArray(d.addrs))
|
|
839
|
-
throw TypeError(".Message.Peer.addrs: array expected");
|
|
840
|
-
m.addrs = [];
|
|
841
|
-
for (var i = 0; i < d.addrs.length; ++i) {
|
|
842
|
-
if (typeof d.addrs[i] === "string")
|
|
843
|
-
$util.base64.decode(d.addrs[i], m.addrs[i] = $util.newBuffer($util.base64.length(d.addrs[i])), 0);
|
|
844
|
-
else if (d.addrs[i].length)
|
|
845
|
-
m.addrs[i] = d.addrs[i];
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
switch (d.connection) {
|
|
849
|
-
case "NOT_CONNECTED":
|
|
850
|
-
case 0:
|
|
851
|
-
m.connection = 0;
|
|
852
|
-
break;
|
|
853
|
-
case "CONNECTED":
|
|
854
|
-
case 1:
|
|
855
|
-
m.connection = 1;
|
|
856
|
-
break;
|
|
857
|
-
case "CAN_CONNECT":
|
|
858
|
-
case 2:
|
|
859
|
-
m.connection = 2;
|
|
860
|
-
break;
|
|
861
|
-
case "CANNOT_CONNECT":
|
|
862
|
-
case 3:
|
|
863
|
-
m.connection = 3;
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
return m;
|
|
49
|
+
})(ConnectionType = Message.ConnectionType || (Message.ConnectionType = {}));
|
|
50
|
+
let Peer;
|
|
51
|
+
(function (Peer) {
|
|
52
|
+
Peer.codec = () => {
|
|
53
|
+
return message({
|
|
54
|
+
1: { name: 'id', codec: bytes, optional: true },
|
|
55
|
+
2: { name: 'addrs', codec: bytes, repeats: true },
|
|
56
|
+
3: { name: 'connection', codec: Message.ConnectionType.codec(), optional: true }
|
|
57
|
+
});
|
|
867
58
|
};
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
* Creates a plain object from a Peer message. Also converts values to other types if specified.
|
|
871
|
-
* @function toObject
|
|
872
|
-
* @memberof Message.Peer
|
|
873
|
-
* @static
|
|
874
|
-
* @param {Message.Peer} m Peer
|
|
875
|
-
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
876
|
-
* @returns {Object.<string,*>} Plain object
|
|
877
|
-
*/
|
|
878
|
-
Peer.toObject = function toObject(m, o) {
|
|
879
|
-
if (!o)
|
|
880
|
-
o = {};
|
|
881
|
-
var d = {};
|
|
882
|
-
if (o.arrays || o.defaults) {
|
|
883
|
-
d.addrs = [];
|
|
884
|
-
}
|
|
885
|
-
if (m.id != null && m.hasOwnProperty("id")) {
|
|
886
|
-
d.id = o.bytes === String ? $util.base64.encode(m.id, 0, m.id.length) : o.bytes === Array ? Array.prototype.slice.call(m.id) : m.id;
|
|
887
|
-
if (o.oneofs)
|
|
888
|
-
d._id = "id";
|
|
889
|
-
}
|
|
890
|
-
if (m.addrs && m.addrs.length) {
|
|
891
|
-
d.addrs = [];
|
|
892
|
-
for (var j = 0; j < m.addrs.length; ++j) {
|
|
893
|
-
d.addrs[j] = o.bytes === String ? $util.base64.encode(m.addrs[j], 0, m.addrs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.addrs[j]) : m.addrs[j];
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
if (m.connection != null && m.hasOwnProperty("connection")) {
|
|
897
|
-
d.connection = o.enums === String ? $root.Message.ConnectionType[m.connection] : m.connection;
|
|
898
|
-
if (o.oneofs)
|
|
899
|
-
d._connection = "connection";
|
|
900
|
-
}
|
|
901
|
-
return d;
|
|
59
|
+
Peer.encode = (obj) => {
|
|
60
|
+
return encodeMessage(obj, Peer.codec());
|
|
902
61
|
};
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
* Converts this Peer to JSON.
|
|
906
|
-
* @function toJSON
|
|
907
|
-
* @memberof Message.Peer
|
|
908
|
-
* @instance
|
|
909
|
-
* @returns {Object.<string,*>} JSON object
|
|
910
|
-
*/
|
|
911
|
-
Peer.prototype.toJSON = function toJSON() {
|
|
912
|
-
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
62
|
+
Peer.decode = (buf) => {
|
|
63
|
+
return decodeMessage(buf, Peer.codec());
|
|
913
64
|
};
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
|
|
65
|
+
})(Peer = Message.Peer || (Message.Peer = {}));
|
|
66
|
+
Message.codec = () => {
|
|
67
|
+
return message({
|
|
68
|
+
1: { name: 'type', codec: Message.MessageType.codec(), optional: true },
|
|
69
|
+
10: { name: 'clusterLevelRaw', codec: int32, optional: true },
|
|
70
|
+
2: { name: 'key', codec: bytes, optional: true },
|
|
71
|
+
3: { name: 'record', codec: bytes, optional: true },
|
|
72
|
+
8: { name: 'closerPeers', codec: Message.Peer.codec(), repeats: true },
|
|
73
|
+
9: { name: 'providerPeers', codec: Message.Peer.codec(), repeats: true }
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
Message.encode = (obj) => {
|
|
77
|
+
return encodeMessage(obj, Message.codec());
|
|
78
|
+
};
|
|
79
|
+
Message.decode = (buf) => {
|
|
80
|
+
return decodeMessage(buf, Message.codec());
|
|
81
|
+
};
|
|
82
|
+
})(Message || (Message = {}));
|
|
83
|
+
//# sourceMappingURL=dht.js.map
|