libp2p 0.35.8-a4bba35 → 0.35.8-ff32eba
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/index.min.js +22 -22
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/config.d.ts +2 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +7 -2
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/errors.d.ts +2 -0
- package/dist/src/fetch/constants.d.ts +2 -0
- package/dist/src/fetch/constants.d.ts.map +1 -0
- package/dist/src/fetch/index.d.ts +76 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/proto.d.ts +134 -0
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +110 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/peer-store/address-book.d.ts +3 -1
- package/dist/src/peer-store/address-book.d.ts.map +1 -1
- package/dist/src/peer-store/index.d.ts +5 -2
- package/dist/src/peer-store/index.d.ts.map +1 -1
- package/dist/src/peer-store/store.d.ts.map +1 -1
- package/dist/src/types.d.ts +90 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/upgrader.d.ts +8 -2
- package/dist/src/upgrader.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/circuit/auto-relay.js +36 -22
- package/src/config.js +2 -0
- package/src/connection-manager/auto-dialler.js +15 -6
- package/src/connection-manager/index.js +3 -0
- package/src/dialer/index.js +20 -1
- package/src/errors.js +2 -0
- package/src/fetch/README.md +36 -0
- package/src/fetch/constants.js +6 -0
- package/src/fetch/index.js +159 -0
- package/src/fetch/proto.d.ts +134 -0
- package/src/fetch/proto.js +333 -0
- package/src/fetch/proto.proto +15 -0
- package/src/identify/index.js +21 -17
- package/src/index.js +40 -1
- package/src/peer-store/address-book.js +41 -28
- package/src/peer-store/index.js +4 -2
- package/src/peer-store/store.js +19 -6
- package/src/types.ts +98 -0
- package/src/upgrader.js +29 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as $protobuf from "protobufjs";
|
|
2
|
+
/** Properties of a FetchRequest. */
|
|
3
|
+
export interface IFetchRequest {
|
|
4
|
+
|
|
5
|
+
/** FetchRequest identifier */
|
|
6
|
+
identifier?: (string|null);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Represents a FetchRequest. */
|
|
10
|
+
export class FetchRequest implements IFetchRequest {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Constructs a new FetchRequest.
|
|
14
|
+
* @param [p] Properties to set
|
|
15
|
+
*/
|
|
16
|
+
constructor(p?: IFetchRequest);
|
|
17
|
+
|
|
18
|
+
/** FetchRequest identifier. */
|
|
19
|
+
public identifier: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Encodes the specified FetchRequest message. Does not implicitly {@link FetchRequest.verify|verify} messages.
|
|
23
|
+
* @param m FetchRequest message or plain object to encode
|
|
24
|
+
* @param [w] Writer to encode to
|
|
25
|
+
* @returns Writer
|
|
26
|
+
*/
|
|
27
|
+
public static encode(m: IFetchRequest, w?: $protobuf.Writer): $protobuf.Writer;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Decodes a FetchRequest message from the specified reader or buffer.
|
|
31
|
+
* @param r Reader or buffer to decode from
|
|
32
|
+
* @param [l] Message length if known beforehand
|
|
33
|
+
* @returns FetchRequest
|
|
34
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
35
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
36
|
+
*/
|
|
37
|
+
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): FetchRequest;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a FetchRequest message from a plain object. Also converts values to their respective internal types.
|
|
41
|
+
* @param d Plain object
|
|
42
|
+
* @returns FetchRequest
|
|
43
|
+
*/
|
|
44
|
+
public static fromObject(d: { [k: string]: any }): FetchRequest;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates a plain object from a FetchRequest message. Also converts values to other types if specified.
|
|
48
|
+
* @param m FetchRequest
|
|
49
|
+
* @param [o] Conversion options
|
|
50
|
+
* @returns Plain object
|
|
51
|
+
*/
|
|
52
|
+
public static toObject(m: FetchRequest, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Converts this FetchRequest to JSON.
|
|
56
|
+
* @returns JSON object
|
|
57
|
+
*/
|
|
58
|
+
public toJSON(): { [k: string]: any };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Properties of a FetchResponse. */
|
|
62
|
+
export interface IFetchResponse {
|
|
63
|
+
|
|
64
|
+
/** FetchResponse status */
|
|
65
|
+
status?: (FetchResponse.StatusCode|null);
|
|
66
|
+
|
|
67
|
+
/** FetchResponse data */
|
|
68
|
+
data?: (Uint8Array|null);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Represents a FetchResponse. */
|
|
72
|
+
export class FetchResponse implements IFetchResponse {
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Constructs a new FetchResponse.
|
|
76
|
+
* @param [p] Properties to set
|
|
77
|
+
*/
|
|
78
|
+
constructor(p?: IFetchResponse);
|
|
79
|
+
|
|
80
|
+
/** FetchResponse status. */
|
|
81
|
+
public status: FetchResponse.StatusCode;
|
|
82
|
+
|
|
83
|
+
/** FetchResponse data. */
|
|
84
|
+
public data: Uint8Array;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Encodes the specified FetchResponse message. Does not implicitly {@link FetchResponse.verify|verify} messages.
|
|
88
|
+
* @param m FetchResponse message or plain object to encode
|
|
89
|
+
* @param [w] Writer to encode to
|
|
90
|
+
* @returns Writer
|
|
91
|
+
*/
|
|
92
|
+
public static encode(m: IFetchResponse, w?: $protobuf.Writer): $protobuf.Writer;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Decodes a FetchResponse message from the specified reader or buffer.
|
|
96
|
+
* @param r Reader or buffer to decode from
|
|
97
|
+
* @param [l] Message length if known beforehand
|
|
98
|
+
* @returns FetchResponse
|
|
99
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
100
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
101
|
+
*/
|
|
102
|
+
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): FetchResponse;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Creates a FetchResponse message from a plain object. Also converts values to their respective internal types.
|
|
106
|
+
* @param d Plain object
|
|
107
|
+
* @returns FetchResponse
|
|
108
|
+
*/
|
|
109
|
+
public static fromObject(d: { [k: string]: any }): FetchResponse;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Creates a plain object from a FetchResponse message. Also converts values to other types if specified.
|
|
113
|
+
* @param m FetchResponse
|
|
114
|
+
* @param [o] Conversion options
|
|
115
|
+
* @returns Plain object
|
|
116
|
+
*/
|
|
117
|
+
public static toObject(m: FetchResponse, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Converts this FetchResponse to JSON.
|
|
121
|
+
* @returns JSON object
|
|
122
|
+
*/
|
|
123
|
+
public toJSON(): { [k: string]: any };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export namespace FetchResponse {
|
|
127
|
+
|
|
128
|
+
/** StatusCode enum. */
|
|
129
|
+
enum StatusCode {
|
|
130
|
+
OK = 0,
|
|
131
|
+
NOT_FOUND = 1,
|
|
132
|
+
ERROR = 2
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/*eslint-disable*/
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var $protobuf = require("protobufjs/minimal");
|
|
5
|
+
|
|
6
|
+
// Common aliases
|
|
7
|
+
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
|
8
|
+
|
|
9
|
+
// Exported root namespace
|
|
10
|
+
var $root = $protobuf.roots["libp2p-fetch"] || ($protobuf.roots["libp2p-fetch"] = {});
|
|
11
|
+
|
|
12
|
+
$root.FetchRequest = (function() {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Properties of a FetchRequest.
|
|
16
|
+
* @exports IFetchRequest
|
|
17
|
+
* @interface IFetchRequest
|
|
18
|
+
* @property {string|null} [identifier] FetchRequest identifier
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a new FetchRequest.
|
|
23
|
+
* @exports FetchRequest
|
|
24
|
+
* @classdesc Represents a FetchRequest.
|
|
25
|
+
* @implements IFetchRequest
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param {IFetchRequest=} [p] Properties to set
|
|
28
|
+
*/
|
|
29
|
+
function FetchRequest(p) {
|
|
30
|
+
if (p)
|
|
31
|
+
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
32
|
+
if (p[ks[i]] != null)
|
|
33
|
+
this[ks[i]] = p[ks[i]];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* FetchRequest identifier.
|
|
38
|
+
* @member {string} identifier
|
|
39
|
+
* @memberof FetchRequest
|
|
40
|
+
* @instance
|
|
41
|
+
*/
|
|
42
|
+
FetchRequest.prototype.identifier = "";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Encodes the specified FetchRequest message. Does not implicitly {@link FetchRequest.verify|verify} messages.
|
|
46
|
+
* @function encode
|
|
47
|
+
* @memberof FetchRequest
|
|
48
|
+
* @static
|
|
49
|
+
* @param {IFetchRequest} m FetchRequest message or plain object to encode
|
|
50
|
+
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
51
|
+
* @returns {$protobuf.Writer} Writer
|
|
52
|
+
*/
|
|
53
|
+
FetchRequest.encode = function encode(m, w) {
|
|
54
|
+
if (!w)
|
|
55
|
+
w = $Writer.create();
|
|
56
|
+
if (m.identifier != null && Object.hasOwnProperty.call(m, "identifier"))
|
|
57
|
+
w.uint32(10).string(m.identifier);
|
|
58
|
+
return w;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Decodes a FetchRequest message from the specified reader or buffer.
|
|
63
|
+
* @function decode
|
|
64
|
+
* @memberof FetchRequest
|
|
65
|
+
* @static
|
|
66
|
+
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
67
|
+
* @param {number} [l] Message length if known beforehand
|
|
68
|
+
* @returns {FetchRequest} FetchRequest
|
|
69
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
70
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
71
|
+
*/
|
|
72
|
+
FetchRequest.decode = function decode(r, l) {
|
|
73
|
+
if (!(r instanceof $Reader))
|
|
74
|
+
r = $Reader.create(r);
|
|
75
|
+
var c = l === undefined ? r.len : r.pos + l, m = new $root.FetchRequest();
|
|
76
|
+
while (r.pos < c) {
|
|
77
|
+
var t = r.uint32();
|
|
78
|
+
switch (t >>> 3) {
|
|
79
|
+
case 1:
|
|
80
|
+
m.identifier = r.string();
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
r.skipType(t & 7);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return m;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Creates a FetchRequest message from a plain object. Also converts values to their respective internal types.
|
|
92
|
+
* @function fromObject
|
|
93
|
+
* @memberof FetchRequest
|
|
94
|
+
* @static
|
|
95
|
+
* @param {Object.<string,*>} d Plain object
|
|
96
|
+
* @returns {FetchRequest} FetchRequest
|
|
97
|
+
*/
|
|
98
|
+
FetchRequest.fromObject = function fromObject(d) {
|
|
99
|
+
if (d instanceof $root.FetchRequest)
|
|
100
|
+
return d;
|
|
101
|
+
var m = new $root.FetchRequest();
|
|
102
|
+
if (d.identifier != null) {
|
|
103
|
+
m.identifier = String(d.identifier);
|
|
104
|
+
}
|
|
105
|
+
return m;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates a plain object from a FetchRequest message. Also converts values to other types if specified.
|
|
110
|
+
* @function toObject
|
|
111
|
+
* @memberof FetchRequest
|
|
112
|
+
* @static
|
|
113
|
+
* @param {FetchRequest} m FetchRequest
|
|
114
|
+
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
115
|
+
* @returns {Object.<string,*>} Plain object
|
|
116
|
+
*/
|
|
117
|
+
FetchRequest.toObject = function toObject(m, o) {
|
|
118
|
+
if (!o)
|
|
119
|
+
o = {};
|
|
120
|
+
var d = {};
|
|
121
|
+
if (o.defaults) {
|
|
122
|
+
d.identifier = "";
|
|
123
|
+
}
|
|
124
|
+
if (m.identifier != null && m.hasOwnProperty("identifier")) {
|
|
125
|
+
d.identifier = m.identifier;
|
|
126
|
+
}
|
|
127
|
+
return d;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Converts this FetchRequest to JSON.
|
|
132
|
+
* @function toJSON
|
|
133
|
+
* @memberof FetchRequest
|
|
134
|
+
* @instance
|
|
135
|
+
* @returns {Object.<string,*>} JSON object
|
|
136
|
+
*/
|
|
137
|
+
FetchRequest.prototype.toJSON = function toJSON() {
|
|
138
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
return FetchRequest;
|
|
142
|
+
})();
|
|
143
|
+
|
|
144
|
+
$root.FetchResponse = (function() {
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Properties of a FetchResponse.
|
|
148
|
+
* @exports IFetchResponse
|
|
149
|
+
* @interface IFetchResponse
|
|
150
|
+
* @property {FetchResponse.StatusCode|null} [status] FetchResponse status
|
|
151
|
+
* @property {Uint8Array|null} [data] FetchResponse data
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Constructs a new FetchResponse.
|
|
156
|
+
* @exports FetchResponse
|
|
157
|
+
* @classdesc Represents a FetchResponse.
|
|
158
|
+
* @implements IFetchResponse
|
|
159
|
+
* @constructor
|
|
160
|
+
* @param {IFetchResponse=} [p] Properties to set
|
|
161
|
+
*/
|
|
162
|
+
function FetchResponse(p) {
|
|
163
|
+
if (p)
|
|
164
|
+
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
165
|
+
if (p[ks[i]] != null)
|
|
166
|
+
this[ks[i]] = p[ks[i]];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* FetchResponse status.
|
|
171
|
+
* @member {FetchResponse.StatusCode} status
|
|
172
|
+
* @memberof FetchResponse
|
|
173
|
+
* @instance
|
|
174
|
+
*/
|
|
175
|
+
FetchResponse.prototype.status = 0;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* FetchResponse data.
|
|
179
|
+
* @member {Uint8Array} data
|
|
180
|
+
* @memberof FetchResponse
|
|
181
|
+
* @instance
|
|
182
|
+
*/
|
|
183
|
+
FetchResponse.prototype.data = $util.newBuffer([]);
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Encodes the specified FetchResponse message. Does not implicitly {@link FetchResponse.verify|verify} messages.
|
|
187
|
+
* @function encode
|
|
188
|
+
* @memberof FetchResponse
|
|
189
|
+
* @static
|
|
190
|
+
* @param {IFetchResponse} m FetchResponse message or plain object to encode
|
|
191
|
+
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
192
|
+
* @returns {$protobuf.Writer} Writer
|
|
193
|
+
*/
|
|
194
|
+
FetchResponse.encode = function encode(m, w) {
|
|
195
|
+
if (!w)
|
|
196
|
+
w = $Writer.create();
|
|
197
|
+
if (m.status != null && Object.hasOwnProperty.call(m, "status"))
|
|
198
|
+
w.uint32(8).int32(m.status);
|
|
199
|
+
if (m.data != null && Object.hasOwnProperty.call(m, "data"))
|
|
200
|
+
w.uint32(18).bytes(m.data);
|
|
201
|
+
return w;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Decodes a FetchResponse message from the specified reader or buffer.
|
|
206
|
+
* @function decode
|
|
207
|
+
* @memberof FetchResponse
|
|
208
|
+
* @static
|
|
209
|
+
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
210
|
+
* @param {number} [l] Message length if known beforehand
|
|
211
|
+
* @returns {FetchResponse} FetchResponse
|
|
212
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
213
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
214
|
+
*/
|
|
215
|
+
FetchResponse.decode = function decode(r, l) {
|
|
216
|
+
if (!(r instanceof $Reader))
|
|
217
|
+
r = $Reader.create(r);
|
|
218
|
+
var c = l === undefined ? r.len : r.pos + l, m = new $root.FetchResponse();
|
|
219
|
+
while (r.pos < c) {
|
|
220
|
+
var t = r.uint32();
|
|
221
|
+
switch (t >>> 3) {
|
|
222
|
+
case 1:
|
|
223
|
+
m.status = r.int32();
|
|
224
|
+
break;
|
|
225
|
+
case 2:
|
|
226
|
+
m.data = r.bytes();
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
r.skipType(t & 7);
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return m;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Creates a FetchResponse message from a plain object. Also converts values to their respective internal types.
|
|
238
|
+
* @function fromObject
|
|
239
|
+
* @memberof FetchResponse
|
|
240
|
+
* @static
|
|
241
|
+
* @param {Object.<string,*>} d Plain object
|
|
242
|
+
* @returns {FetchResponse} FetchResponse
|
|
243
|
+
*/
|
|
244
|
+
FetchResponse.fromObject = function fromObject(d) {
|
|
245
|
+
if (d instanceof $root.FetchResponse)
|
|
246
|
+
return d;
|
|
247
|
+
var m = new $root.FetchResponse();
|
|
248
|
+
switch (d.status) {
|
|
249
|
+
case "OK":
|
|
250
|
+
case 0:
|
|
251
|
+
m.status = 0;
|
|
252
|
+
break;
|
|
253
|
+
case "NOT_FOUND":
|
|
254
|
+
case 1:
|
|
255
|
+
m.status = 1;
|
|
256
|
+
break;
|
|
257
|
+
case "ERROR":
|
|
258
|
+
case 2:
|
|
259
|
+
m.status = 2;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
if (d.data != null) {
|
|
263
|
+
if (typeof d.data === "string")
|
|
264
|
+
$util.base64.decode(d.data, m.data = $util.newBuffer($util.base64.length(d.data)), 0);
|
|
265
|
+
else if (d.data.length)
|
|
266
|
+
m.data = d.data;
|
|
267
|
+
}
|
|
268
|
+
return m;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Creates a plain object from a FetchResponse message. Also converts values to other types if specified.
|
|
273
|
+
* @function toObject
|
|
274
|
+
* @memberof FetchResponse
|
|
275
|
+
* @static
|
|
276
|
+
* @param {FetchResponse} m FetchResponse
|
|
277
|
+
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
278
|
+
* @returns {Object.<string,*>} Plain object
|
|
279
|
+
*/
|
|
280
|
+
FetchResponse.toObject = function toObject(m, o) {
|
|
281
|
+
if (!o)
|
|
282
|
+
o = {};
|
|
283
|
+
var d = {};
|
|
284
|
+
if (o.defaults) {
|
|
285
|
+
d.status = o.enums === String ? "OK" : 0;
|
|
286
|
+
if (o.bytes === String)
|
|
287
|
+
d.data = "";
|
|
288
|
+
else {
|
|
289
|
+
d.data = [];
|
|
290
|
+
if (o.bytes !== Array)
|
|
291
|
+
d.data = $util.newBuffer(d.data);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (m.status != null && m.hasOwnProperty("status")) {
|
|
295
|
+
d.status = o.enums === String ? $root.FetchResponse.StatusCode[m.status] : m.status;
|
|
296
|
+
}
|
|
297
|
+
if (m.data != null && m.hasOwnProperty("data")) {
|
|
298
|
+
d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data;
|
|
299
|
+
}
|
|
300
|
+
return d;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Converts this FetchResponse to JSON.
|
|
305
|
+
* @function toJSON
|
|
306
|
+
* @memberof FetchResponse
|
|
307
|
+
* @instance
|
|
308
|
+
* @returns {Object.<string,*>} JSON object
|
|
309
|
+
*/
|
|
310
|
+
FetchResponse.prototype.toJSON = function toJSON() {
|
|
311
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* StatusCode enum.
|
|
316
|
+
* @name FetchResponse.StatusCode
|
|
317
|
+
* @enum {number}
|
|
318
|
+
* @property {number} OK=0 OK value
|
|
319
|
+
* @property {number} NOT_FOUND=1 NOT_FOUND value
|
|
320
|
+
* @property {number} ERROR=2 ERROR value
|
|
321
|
+
*/
|
|
322
|
+
FetchResponse.StatusCode = (function() {
|
|
323
|
+
var valuesById = {}, values = Object.create(valuesById);
|
|
324
|
+
values[valuesById[0] = "OK"] = 0;
|
|
325
|
+
values[valuesById[1] = "NOT_FOUND"] = 1;
|
|
326
|
+
values[valuesById[2] = "ERROR"] = 2;
|
|
327
|
+
return values;
|
|
328
|
+
})();
|
|
329
|
+
|
|
330
|
+
return FetchResponse;
|
|
331
|
+
})();
|
|
332
|
+
|
|
333
|
+
module.exports = $root;
|
package/src/identify/index.js
CHANGED
|
@@ -267,25 +267,25 @@ class IdentifyService {
|
|
|
267
267
|
* @returns {Promise<void>}
|
|
268
268
|
*/
|
|
269
269
|
async _handleIdentify ({ connection, stream }) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
try {
|
|
271
|
+
let publicKey = new Uint8Array(0)
|
|
272
|
+
if (this.peerId.pubKey) {
|
|
273
|
+
publicKey = this.peerId.pubKey.bytes
|
|
274
|
+
}
|
|
274
275
|
|
|
275
|
-
|
|
276
|
-
|
|
276
|
+
const signedPeerRecord = await this.peerStore.addressBook.getRawEnvelope(this.peerId)
|
|
277
|
+
const protocols = await this.peerStore.protoBook.get(this.peerId)
|
|
277
278
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
279
|
+
const message = Message.Identify.encode({
|
|
280
|
+
protocolVersion: this._host.protocolVersion,
|
|
281
|
+
agentVersion: this._host.agentVersion,
|
|
282
|
+
publicKey,
|
|
283
|
+
listenAddrs: this._libp2p.multiaddrs.map((ma) => ma.bytes),
|
|
284
|
+
signedPeerRecord,
|
|
285
|
+
observedAddr: connection.remoteAddr.bytes,
|
|
286
|
+
protocols
|
|
287
|
+
}).finish()
|
|
287
288
|
|
|
288
|
-
try {
|
|
289
289
|
await pipe(
|
|
290
290
|
[message],
|
|
291
291
|
lp.encode(),
|
|
@@ -343,7 +343,11 @@ class IdentifyService {
|
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
// Update the protocols
|
|
346
|
-
|
|
346
|
+
try {
|
|
347
|
+
await this.peerStore.protoBook.set(id, message.protocols)
|
|
348
|
+
} catch (/** @type {any} */ err) {
|
|
349
|
+
log.error('received invalid protocols', err)
|
|
350
|
+
}
|
|
347
351
|
}
|
|
348
352
|
|
|
349
353
|
/**
|
package/src/index.js
CHANGED
|
@@ -31,6 +31,7 @@ const PubsubAdapter = require('./pubsub-adapter')
|
|
|
31
31
|
const Registrar = require('./registrar')
|
|
32
32
|
const ping = require('./ping')
|
|
33
33
|
const IdentifyService = require('./identify')
|
|
34
|
+
const FetchService = require('./fetch')
|
|
34
35
|
const NatManager = require('./nat-manager')
|
|
35
36
|
const { updateSelfPeerRecord } = require('./record/utils')
|
|
36
37
|
|
|
@@ -47,6 +48,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|
|
47
48
|
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
|
|
48
49
|
* @typedef {import('interface-datastore').Datastore} Datastore
|
|
49
50
|
* @typedef {import('./pnet')} Protector
|
|
51
|
+
* @typedef {import('./types').ConnectionGater} ConnectionGater
|
|
50
52
|
* @typedef {Object} PersistentPeerStoreOptions
|
|
51
53
|
* @property {number} [threshold]
|
|
52
54
|
*/
|
|
@@ -105,6 +107,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|
|
105
107
|
* @property {Libp2pModules} modules libp2p modules to use
|
|
106
108
|
* @property {import('./address-manager').AddressManagerOptions} [addresses]
|
|
107
109
|
* @property {import('./connection-manager').ConnectionManagerOptions} [connectionManager]
|
|
110
|
+
* @property {Partial<import('./types').ConnectionGater>} [connectionGater]
|
|
108
111
|
* @property {Datastore} [datastore]
|
|
109
112
|
* @property {import('./dialer').DialerOptions} [dialer]
|
|
110
113
|
* @property {import('./identify/index').HostProperties} [host] libp2p host
|
|
@@ -171,10 +174,25 @@ class Libp2p extends EventEmitter {
|
|
|
171
174
|
this.metrics = metrics
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
/** @type {ConnectionGater} */
|
|
178
|
+
this.connectionGater = {
|
|
179
|
+
denyDialPeer: async () => Promise.resolve(false),
|
|
180
|
+
denyDialMultiaddr: async () => Promise.resolve(false),
|
|
181
|
+
denyInboundConnection: async () => Promise.resolve(false),
|
|
182
|
+
denyOutboundConnection: async () => Promise.resolve(false),
|
|
183
|
+
denyInboundEncryptedConnection: async () => Promise.resolve(false),
|
|
184
|
+
denyOutboundEncryptedConnection: async () => Promise.resolve(false),
|
|
185
|
+
denyInboundUpgradedConnection: async () => Promise.resolve(false),
|
|
186
|
+
denyOutboundUpgradedConnection: async () => Promise.resolve(false),
|
|
187
|
+
filterMultiaddrForPeer: async () => Promise.resolve(true),
|
|
188
|
+
...this._options.connectionGater
|
|
189
|
+
}
|
|
190
|
+
|
|
174
191
|
/** @type {import('./peer-store/types').PeerStore} */
|
|
175
192
|
this.peerStore = new PeerStore({
|
|
176
193
|
peerId: this.peerId,
|
|
177
|
-
datastore: (this.datastore && this._options.peerStore.persistence) ? this.datastore : new MemoryDatastore()
|
|
194
|
+
datastore: (this.datastore && this._options.peerStore.persistence) ? this.datastore : new MemoryDatastore(),
|
|
195
|
+
addressFilter: this.connectionGater.filterMultiaddrForPeer
|
|
178
196
|
})
|
|
179
197
|
|
|
180
198
|
// Addresses {listen, announce, noAnnounce}
|
|
@@ -219,6 +237,7 @@ class Libp2p extends EventEmitter {
|
|
|
219
237
|
|
|
220
238
|
// Setup the Upgrader
|
|
221
239
|
this.upgrader = new Upgrader({
|
|
240
|
+
connectionGater: this.connectionGater,
|
|
222
241
|
localPeer: this.peerId,
|
|
223
242
|
metrics: this.metrics,
|
|
224
243
|
onConnection: (connection) => this.connectionManager.onConnect(connection),
|
|
@@ -261,6 +280,7 @@ class Libp2p extends EventEmitter {
|
|
|
261
280
|
|
|
262
281
|
this.dialer = new Dialer({
|
|
263
282
|
transportManager: this.transportManager,
|
|
283
|
+
connectionGater: this.connectionGater,
|
|
264
284
|
peerStore: this.peerStore,
|
|
265
285
|
metrics: this.metrics,
|
|
266
286
|
...this._options.dialer
|
|
@@ -323,6 +343,8 @@ class Libp2p extends EventEmitter {
|
|
|
323
343
|
ping.mount(this)
|
|
324
344
|
|
|
325
345
|
this._onDiscoveryPeer = this._onDiscoveryPeer.bind(this)
|
|
346
|
+
|
|
347
|
+
this.fetchService = new FetchService(this)
|
|
326
348
|
}
|
|
327
349
|
|
|
328
350
|
/**
|
|
@@ -356,6 +378,10 @@ class Libp2p extends EventEmitter {
|
|
|
356
378
|
await this.handle(Object.values(IdentifyService.getProtocolStr(this)), this.identifyService.handleMessage)
|
|
357
379
|
}
|
|
358
380
|
|
|
381
|
+
if (this.fetchService) {
|
|
382
|
+
await this.handle(FetchService.PROTOCOL, this.fetchService.handleMessage)
|
|
383
|
+
}
|
|
384
|
+
|
|
359
385
|
try {
|
|
360
386
|
await this._onStarting()
|
|
361
387
|
await this._onDidStart()
|
|
@@ -407,6 +433,8 @@ class Libp2p extends EventEmitter {
|
|
|
407
433
|
await this.natManager.stop()
|
|
408
434
|
await this.transportManager.close()
|
|
409
435
|
|
|
436
|
+
this.unhandle(FetchService.PROTOCOL)
|
|
437
|
+
|
|
410
438
|
ping.unmount(this)
|
|
411
439
|
this.dialer.destroy()
|
|
412
440
|
} catch (/** @type {any} */ err) {
|
|
@@ -559,6 +587,17 @@ class Libp2p extends EventEmitter {
|
|
|
559
587
|
)
|
|
560
588
|
}
|
|
561
589
|
|
|
590
|
+
/**
|
|
591
|
+
* Sends a request to fetch the value associated with the given key from the given peer.
|
|
592
|
+
*
|
|
593
|
+
* @param {PeerId|Multiaddr} peer
|
|
594
|
+
* @param {string} key
|
|
595
|
+
* @returns {Promise<Uint8Array | null>}
|
|
596
|
+
*/
|
|
597
|
+
fetch (peer, key) {
|
|
598
|
+
return this.fetchService.fetch(peer, key)
|
|
599
|
+
}
|
|
600
|
+
|
|
562
601
|
/**
|
|
563
602
|
* Pings the given peer in order to obtain the operation latency.
|
|
564
603
|
*
|