libp2p 0.35.8 → 0.36.0
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 +55 -0
- package/dist/src/circuit/auto-relay.d.ts +8 -10
- 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 +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -2
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/content-routing/utils.d.ts +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +12 -7
- 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 +4 -4
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +116 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/metrics/index.d.ts +9 -4
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/tracked-map.d.ts +6 -1
- package/dist/src/metrics/tracked-map.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-store/address-book.d.ts +30 -84
- package/dist/src/peer-store/address-book.d.ts.map +1 -1
- package/dist/src/peer-store/index.d.ts +28 -94
- package/dist/src/peer-store/index.d.ts.map +1 -1
- package/dist/src/peer-store/key-book.d.ts +31 -15
- package/dist/src/peer-store/key-book.d.ts.map +1 -1
- package/dist/src/peer-store/metadata-book.d.ts +33 -29
- package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
- package/dist/src/peer-store/pb/peer.d.ts +222 -0
- package/dist/src/peer-store/proto-book.d.ts +27 -28
- package/dist/src/peer-store/proto-book.d.ts.map +1 -1
- package/dist/src/peer-store/store.d.ts +73 -0
- package/dist/src/peer-store/store.d.ts.map +1 -0
- package/dist/src/peer-store/types.d.ts +202 -0
- package/dist/src/peer-store/types.d.ts.map +1 -0
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/record/peer-record/index.d.ts +2 -2
- package/dist/src/record/peer-record/index.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +5 -5
- package/dist/src/registrar.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 +23 -26
- package/src/circuit/auto-relay.js +52 -38
- package/src/config.js +2 -0
- package/src/connection-manager/auto-dialler.js +20 -8
- package/src/connection-manager/index.js +42 -22
- package/src/content-routing/utils.js +4 -4
- package/src/dialer/dial-request.js +4 -1
- package/src/dialer/index.js +38 -8
- 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 +47 -38
- package/src/index.js +72 -27
- package/src/metrics/index.js +15 -8
- package/src/metrics/tracked-map.js +40 -14
- package/src/peer-routing.js +4 -1
- package/src/peer-store/address-book.js +254 -226
- package/src/peer-store/index.js +79 -110
- package/src/peer-store/key-book.js +99 -54
- package/src/peer-store/metadata-book.js +171 -101
- package/src/peer-store/pb/peer.d.ts +222 -0
- package/src/peer-store/pb/peer.js +643 -0
- package/src/peer-store/pb/peer.proto +31 -0
- package/src/peer-store/proto-book.js +171 -105
- package/src/peer-store/store.js +263 -0
- package/src/peer-store/types.ts +245 -0
- package/src/ping/index.js +6 -0
- package/src/record/peer-record/index.js +1 -1
- package/src/record/utils.js +1 -1
- package/src/registrar.js +4 -4
- package/src/types.ts +98 -0
- package/src/upgrader.js +32 -2
- package/dist/src/peer-store/book.d.ts +0 -81
- package/dist/src/peer-store/book.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/consts.d.ts +0 -6
- package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/index.d.ts +0 -129
- package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/book.js +0 -124
- package/src/peer-store/persistent/consts.js +0 -15
- package/src/peer-store/persistent/index.js +0 -408
- package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/src/peer-store/persistent/pb/address-book.js +0 -522
- package/src/peer-store/persistent/pb/address-book.proto +0 -27
- package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/persistent/pb/proto-book.js +0 -157
- package/src/peer-store/persistent/pb/proto-book.proto +0 -5
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const debug = require('debug')
|
|
4
|
+
const log = Object.assign(debug('libp2p:fetch'), {
|
|
5
|
+
error: debug('libp2p:fetch:err')
|
|
6
|
+
})
|
|
7
|
+
const errCode = require('err-code')
|
|
8
|
+
const { codes } = require('../errors')
|
|
9
|
+
const lp = require('it-length-prefixed')
|
|
10
|
+
const { FetchRequest, FetchResponse } = require('./proto')
|
|
11
|
+
// @ts-ignore it-handshake does not export types
|
|
12
|
+
const handshake = require('it-handshake')
|
|
13
|
+
const { PROTOCOL } = require('./constants')
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {import('../')} Libp2p
|
|
17
|
+
* @typedef {import('multiaddr').Multiaddr} Multiaddr
|
|
18
|
+
* @typedef {import('peer-id')} PeerId
|
|
19
|
+
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
|
|
20
|
+
* @typedef {(key: string) => Promise<Uint8Array | null>} LookupFunction
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A simple libp2p protocol for requesting a value corresponding to a key from a peer.
|
|
25
|
+
* Developers can register one or more lookup function for retrieving the value corresponding to
|
|
26
|
+
* a given key. Each lookup function must act on a distinct part of the overall key space, defined
|
|
27
|
+
* by a fixed prefix that all keys that should be routed to that lookup function will start with.
|
|
28
|
+
*/
|
|
29
|
+
class FetchProtocol {
|
|
30
|
+
/**
|
|
31
|
+
* @param {Libp2p} libp2p
|
|
32
|
+
*/
|
|
33
|
+
constructor (libp2p) {
|
|
34
|
+
this._lookupFunctions = new Map() // Maps key prefix to value lookup function
|
|
35
|
+
this._libp2p = libp2p
|
|
36
|
+
this.handleMessage = this.handleMessage.bind(this)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sends a request to fetch the value associated with the given key from the given peer.
|
|
41
|
+
*
|
|
42
|
+
* @param {PeerId|Multiaddr} peer
|
|
43
|
+
* @param {string} key
|
|
44
|
+
* @returns {Promise<Uint8Array | null>}
|
|
45
|
+
*/
|
|
46
|
+
async fetch (peer, key) {
|
|
47
|
+
// @ts-ignore multiaddr might not have toB58String
|
|
48
|
+
log('dialing %s to %s', this._protocol, peer.toB58String ? peer.toB58String() : peer)
|
|
49
|
+
|
|
50
|
+
const connection = await this._libp2p.dial(peer)
|
|
51
|
+
const { stream } = await connection.newStream(FetchProtocol.PROTOCOL)
|
|
52
|
+
const shake = handshake(stream)
|
|
53
|
+
|
|
54
|
+
// send message
|
|
55
|
+
const request = new FetchRequest({ identifier: key })
|
|
56
|
+
shake.write(lp.encode.single(FetchRequest.encode(request).finish()))
|
|
57
|
+
|
|
58
|
+
// read response
|
|
59
|
+
const response = FetchResponse.decode((await lp.decode.fromReader(shake.reader).next()).value.slice())
|
|
60
|
+
switch (response.status) {
|
|
61
|
+
case (FetchResponse.StatusCode.OK): {
|
|
62
|
+
return response.data
|
|
63
|
+
}
|
|
64
|
+
case (FetchResponse.StatusCode.NOT_FOUND): {
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
case (FetchResponse.StatusCode.ERROR): {
|
|
68
|
+
const errmsg = (new TextDecoder()).decode(response.data)
|
|
69
|
+
throw errCode(new Error('Error in fetch protocol response: ' + errmsg), codes.ERR_INVALID_PARAMETERS)
|
|
70
|
+
}
|
|
71
|
+
default: {
|
|
72
|
+
throw errCode(new Error('Unknown response status'), codes.ERR_INVALID_MESSAGE)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Invoked when a fetch request is received. Reads the request message off the given stream and
|
|
79
|
+
* responds based on looking up the key in the request via the lookup callback that corresponds
|
|
80
|
+
* to the key's prefix.
|
|
81
|
+
*
|
|
82
|
+
* @param {object} options
|
|
83
|
+
* @param {MuxedStream} options.stream
|
|
84
|
+
* @param {string} options.protocol
|
|
85
|
+
*/
|
|
86
|
+
async handleMessage (options) {
|
|
87
|
+
const { stream } = options
|
|
88
|
+
const shake = handshake(stream)
|
|
89
|
+
const request = FetchRequest.decode((await lp.decode.fromReader(shake.reader).next()).value.slice())
|
|
90
|
+
|
|
91
|
+
let response
|
|
92
|
+
const lookup = this._getLookupFunction(request.identifier)
|
|
93
|
+
if (lookup) {
|
|
94
|
+
const data = await lookup(request.identifier)
|
|
95
|
+
if (data) {
|
|
96
|
+
response = new FetchResponse({ status: FetchResponse.StatusCode.OK, data })
|
|
97
|
+
} else {
|
|
98
|
+
response = new FetchResponse({ status: FetchResponse.StatusCode.NOT_FOUND })
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
const errmsg = (new TextEncoder()).encode('No lookup function registered for key: ' + request.identifier)
|
|
102
|
+
response = new FetchResponse({ status: FetchResponse.StatusCode.ERROR, data: errmsg })
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
shake.write(lp.encode.single(FetchResponse.encode(response).finish()))
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Given a key, finds the appropriate function for looking up its corresponding value, based on
|
|
110
|
+
* the key's prefix.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} key
|
|
113
|
+
*/
|
|
114
|
+
_getLookupFunction (key) {
|
|
115
|
+
for (const prefix of this._lookupFunctions.keys()) {
|
|
116
|
+
if (key.startsWith(prefix)) {
|
|
117
|
+
return this._lookupFunctions.get(prefix)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
125
|
+
* share the same prefix.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} prefix
|
|
128
|
+
* @param {LookupFunction} lookup
|
|
129
|
+
*/
|
|
130
|
+
registerLookupFunction (prefix, lookup) {
|
|
131
|
+
if (this._lookupFunctions.has(prefix)) {
|
|
132
|
+
throw errCode(new Error("Fetch protocol handler for key prefix '" + prefix + "' already registered"), codes.ERR_KEY_ALREADY_EXISTS)
|
|
133
|
+
}
|
|
134
|
+
this._lookupFunctions.set(prefix, lookup)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
139
|
+
* share the same prefix.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} prefix
|
|
142
|
+
* @param {LookupFunction} [lookup]
|
|
143
|
+
*/
|
|
144
|
+
unregisterLookupFunction (prefix, lookup) {
|
|
145
|
+
if (lookup != null) {
|
|
146
|
+
const existingLookup = this._lookupFunctions.get(prefix)
|
|
147
|
+
|
|
148
|
+
if (existingLookup !== lookup) {
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this._lookupFunctions.delete(prefix)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
FetchProtocol.PROTOCOL = PROTOCOL
|
|
158
|
+
|
|
159
|
+
exports = module.exports = FetchProtocol
|
|
@@ -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;
|