@libp2p/fetch 3.0.21 → 3.0.22-0f07e3df5

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.
@@ -1,5 +1,5 @@
1
1
  import type { Fetch as FetchInterface, FetchComponents, FetchInit, LookupFunction } from './index.js';
2
- import type { AbortOptions, PeerId, Startable, IncomingStreamData } from '@libp2p/interface';
2
+ import type { AbortOptions, Stream, PeerId, Startable } from '@libp2p/interface';
3
3
  /**
4
4
  * A simple libp2p protocol for requesting a value corresponding to a key from a peer.
5
5
  * Developers can register one or more lookup function for retrieving the value corresponding to
@@ -12,7 +12,6 @@ export declare class Fetch implements Startable, FetchInterface {
12
12
  private readonly lookupFunctions;
13
13
  private started;
14
14
  private readonly init;
15
- private readonly log;
16
15
  constructor(components: FetchComponents, init?: FetchInit);
17
16
  readonly [Symbol.toStringTag] = "@libp2p/fetch";
18
17
  start(): Promise<void>;
@@ -27,7 +26,7 @@ export declare class Fetch implements Startable, FetchInterface {
27
26
  * responds based on looking up the key in the request via the lookup callback that corresponds
28
27
  * to the key's prefix.
29
28
  */
30
- handleMessage(data: IncomingStreamData): Promise<void>;
29
+ handleMessage(stream: Stream): Promise<void>;
31
30
  /**
32
31
  * Given a key, finds the appropriate function for looking up its corresponding value, based on
33
32
  * the key's prefix.
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/fetch.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,IAAI,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AACrG,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAI5G;;;;;GAKG;AACH,qBAAa,KAAM,YAAW,SAAS,EAAE,cAAc;IACrD,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC,OAAO,CAAC,QAAQ,CAA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,MAAM,mBAAmB,CAAA;AAIhF;;;;;GAKG;AACH,qBAAa,KAAM,YAAW,SAAS,EAAE,cAAc;IACrD,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA6B;IAC7D,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;gBAEnB,UAAU,EAAE,eAAe,EAAE,IAAI,GAAE,SAAc;IAU9D,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,mBAAkB;IAEzC,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAQvB,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAK5B,SAAS,IAAK,OAAO;IAIrB;;OAEG;IACG,KAAK,CAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IA4DjH;;;;OAIG;IACG,aAAa,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+CnD;;;OAGG;IACH,kBAAkB,CAAE,GAAG,EAAE,MAAM,GAAG;QAAE,EAAE,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;IAepF;;;;;;;;;;OAUG;IACH,sBAAsB,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI;IAQrE;;;;;;;;;;OAUG;IACH,wBAAwB,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI;CAWzE"}
package/dist/src/fetch.js CHANGED
@@ -1,11 +1,11 @@
1
- import { AbortError, InvalidMessageError, InvalidParametersError, ProtocolError } from '@libp2p/interface';
2
- import { pbStream } from 'it-protobuf-stream';
1
+ import { InvalidMessageError, InvalidParametersError, ProtocolError } from '@libp2p/interface';
2
+ import { pbStream } from '@libp2p/utils';
3
3
  import { setMaxListeners } from 'main-event';
4
4
  import { fromString as uint8arrayFromString } from 'uint8arrays/from-string';
5
5
  import { toString as uint8arrayToString } from 'uint8arrays/to-string';
6
6
  import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js';
7
7
  import { FetchRequest, FetchResponse } from './pb/proto.js';
8
- const DEFAULT_TIMEOUT = 10000;
8
+ const DEFAULT_TIMEOUT = 10_000;
9
9
  /**
10
10
  * A simple libp2p protocol for requesting a value corresponding to a key from a peer.
11
11
  * Developers can register one or more lookup function for retrieving the value corresponding to
@@ -18,27 +18,17 @@ export class Fetch {
18
18
  lookupFunctions;
19
19
  started;
20
20
  init;
21
- log;
22
21
  constructor(components, init = {}) {
23
- this.log = components.logger.forComponent('libp2p:fetch');
24
22
  this.started = false;
25
23
  this.components = components;
26
24
  this.protocol = `/${init.protocolPrefix ?? 'libp2p'}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`;
27
25
  this.lookupFunctions = new Map(); // Maps key prefix to value lookup function
28
- this.handleMessage = this.handleMessage.bind(this);
29
26
  this.init = init;
27
+ this.handleMessage = this.handleMessage.bind(this);
30
28
  }
31
29
  [Symbol.toStringTag] = '@libp2p/fetch';
32
30
  async start() {
33
- await this.components.registrar.handle(this.protocol, (data) => {
34
- void this.handleMessage(data)
35
- .then(async () => {
36
- await data.stream.close();
37
- })
38
- .catch(err => {
39
- this.log.error('error handling message - %e', err);
40
- });
41
- }, {
31
+ await this.components.registrar.handle(this.protocol, this.handleMessage, {
42
32
  maxInboundStreams: this.init.maxInboundStreams,
43
33
  maxOutboundStreams: this.init.maxOutboundStreams
44
34
  });
@@ -58,50 +48,44 @@ export class Fetch {
58
48
  if (typeof key === 'string') {
59
49
  key = uint8arrayFromString(key);
60
50
  }
61
- this.log.trace('dialing %s to %p', this.protocol, peer);
62
- const connection = await this.components.connectionManager.openConnection(peer, options);
63
- let signal = options.signal;
64
- let stream;
65
- let onAbort = () => { };
66
51
  // create a timeout if no abort signal passed
67
- if (signal == null) {
52
+ if (options.signal == null) {
68
53
  const timeout = this.init.timeout ?? DEFAULT_TIMEOUT;
69
- this.log.trace('using default timeout of %d ms', timeout);
70
- signal = AbortSignal.timeout(timeout);
54
+ const signal = AbortSignal.timeout(timeout);
71
55
  setMaxListeners(Infinity, signal);
72
- }
73
- try {
74
- stream = await connection.newStream(this.protocol, {
56
+ options = {
57
+ ...options,
75
58
  signal
76
- });
77
- onAbort = () => {
78
- stream?.abort(new AbortError());
79
59
  };
80
- // make stream abortable
81
- signal.addEventListener('abort', onAbort, { once: true });
82
- this.log.trace('fetch %m', key);
60
+ }
61
+ let stream;
62
+ try {
63
+ const connection = await this.components.connectionManager.openConnection(peer, options);
64
+ stream = await connection.newStream(this.protocol, options);
65
+ const log = stream.log.newScope('fetch');
66
+ log.trace('fetch %m', key);
83
67
  const pb = pbStream(stream);
84
68
  await pb.write({
85
69
  identifier: key
86
70
  }, FetchRequest, options);
87
71
  const response = await pb.read(FetchResponse, options);
88
- await pb.unwrap().close(options);
72
+ await stream.close(options);
89
73
  switch (response.status) {
90
74
  case (FetchResponse.StatusCode.OK): {
91
- this.log.trace('received status OK for %m', key);
75
+ log.trace('received status OK for %m', key);
92
76
  return response.data;
93
77
  }
94
78
  case (FetchResponse.StatusCode.NOT_FOUND): {
95
- this.log('received status NOT_FOUND for %m', key);
79
+ log('received status NOT_FOUND for %m', key);
96
80
  return;
97
81
  }
98
82
  case (FetchResponse.StatusCode.ERROR): {
99
- this.log('received status ERROR for %m', key);
83
+ log('received status ERROR for %m', key);
100
84
  const errMsg = uint8arrayToString(response.data);
101
85
  throw new ProtocolError('Error in fetch protocol response: ' + errMsg);
102
86
  }
103
87
  default: {
104
- this.log('received status unknown for %m', key);
88
+ log('received status unknown for %m', key);
105
89
  throw new InvalidMessageError('Unknown response status');
106
90
  }
107
91
  }
@@ -110,64 +94,52 @@ export class Fetch {
110
94
  stream?.abort(err);
111
95
  throw err;
112
96
  }
113
- finally {
114
- signal.removeEventListener('abort', onAbort);
115
- if (stream != null) {
116
- await stream.close();
117
- }
118
- }
119
97
  }
120
98
  /**
121
99
  * Invoked when a fetch request is received. Reads the request message off the given stream and
122
100
  * responds based on looking up the key in the request via the lookup callback that corresponds
123
101
  * to the key's prefix.
124
102
  */
125
- async handleMessage(data) {
126
- const { stream } = data;
103
+ async handleMessage(stream) {
104
+ const log = stream.log.newScope('fetch');
127
105
  const signal = AbortSignal.timeout(this.init.timeout ?? DEFAULT_TIMEOUT);
128
- try {
129
- const pb = pbStream(stream);
130
- const request = await pb.read(FetchRequest, {
131
- signal
132
- });
133
- let response;
134
- const key = uint8arrayToString(request.identifier);
135
- const lookup = this._getLookupFunction(key);
136
- if (lookup == null) {
137
- this.log.trace('sending status ERROR for %m', request.identifier);
138
- const errMsg = uint8arrayFromString('No lookup function registered for key');
139
- response = { status: FetchResponse.StatusCode.ERROR, data: errMsg };
140
- }
141
- else {
142
- this.log.trace('lookup data with identifier %s', lookup.prefix);
143
- try {
144
- const data = await lookup.fn(request.identifier);
145
- if (data == null) {
146
- this.log.trace('sending status NOT_FOUND for %m', request.identifier);
147
- response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) };
148
- }
149
- else {
150
- this.log.trace('sending status OK for %m', request.identifier);
151
- response = { status: FetchResponse.StatusCode.OK, data };
152
- }
106
+ const pb = pbStream(stream);
107
+ const request = await pb.read(FetchRequest, {
108
+ signal
109
+ });
110
+ let response;
111
+ const key = uint8arrayToString(request.identifier);
112
+ const lookup = this._getLookupFunction(key);
113
+ if (lookup == null) {
114
+ log.trace('sending status ERROR for %m', request.identifier);
115
+ const errMsg = uint8arrayFromString('No lookup function registered for key');
116
+ response = { status: FetchResponse.StatusCode.ERROR, data: errMsg };
117
+ }
118
+ else {
119
+ log.trace('lookup data with identifier %s', lookup.prefix);
120
+ try {
121
+ const data = await lookup.fn(request.identifier);
122
+ if (data == null) {
123
+ log.trace('sending status NOT_FOUND for %m', request.identifier);
124
+ response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) };
153
125
  }
154
- catch (err) {
155
- this.log.error('error during lookup of %m - %e', request.identifier, err);
156
- const errMsg = uint8arrayFromString(err.message);
157
- response = { status: FetchResponse.StatusCode.ERROR, data: errMsg };
126
+ else {
127
+ log.trace('sending status OK for %m', request.identifier);
128
+ response = { status: FetchResponse.StatusCode.OK, data };
158
129
  }
159
130
  }
160
- await pb.write(response, FetchResponse, {
161
- signal
162
- });
163
- await pb.unwrap().close({
164
- signal
165
- });
166
- }
167
- catch (err) {
168
- this.log.error('error answering fetch request - %e', err);
169
- stream.abort(err);
131
+ catch (err) {
132
+ log.error('error during lookup of %m - %e', request.identifier, err);
133
+ const errMsg = uint8arrayFromString(err.message);
134
+ response = { status: FetchResponse.StatusCode.ERROR, data: errMsg };
135
+ }
170
136
  }
137
+ await pb.write(response, FetchResponse, {
138
+ signal
139
+ });
140
+ await stream.close({
141
+ signal
142
+ });
171
143
  }
172
144
  /**
173
145
  * Given a key, finds the appropriate function for looking up its corresponding value, based on
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC1G,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CA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ACH,kBAAkB,CAAE,GAAW;QAC7B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC;YACjD,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC3B,MAAM,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBAE3C,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;oBACf,OAAO;wBACL,EAAE;wBACF,MAAM;qBACP,CAAA;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACH,sBAAsB,CAAE,MAAc,EAAE,MAAsB;QAC5D,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,sBAAsB,CAAC,0CAA0C,MAAM,sBAAsB,CAAC,CAAA;QAC1G,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;IAED;;;;;;;;;;OAUG;IACH,wBAAwB,CAAE,MAAc,EAAE,MAAuB;QAC/D,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAEvD,IAAI,cAAc,KAAK,MAAM,EAAE,CAAC;gBAC9B,OAAM;YACR,CAAC;QACH,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC;CACF"}
@@ -41,7 +41,7 @@
41
41
  * })
42
42
  * ```
43
43
  */
44
- import type { AbortOptions, ComponentLogger, PeerId } from '@libp2p/interface';
44
+ import type { AbortOptions, PeerId } from '@libp2p/interface';
45
45
  import type { ConnectionManager, Registrar } from '@libp2p/interface-internal';
46
46
  export interface FetchInit {
47
47
  protocolPrefix?: string;
@@ -65,7 +65,6 @@ export interface LookupFunction {
65
65
  export interface FetchComponents {
66
66
  registrar: Registrar;
67
67
  connectionManager: ConnectionManager;
68
- logger: ComponentLogger;
69
68
  }
70
69
  export interface Fetch {
71
70
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAE9E,MAAM,WAAW,SAAS;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,KAAK;IACpB;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;IAEtG;;;;;;;;;;OAUG;IACH,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAAA;IAEpE;;;;;;;;;;OAUG;IACH,wBAAwB,CAAC,MAAM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Ac,GAAG,IAAI,CAAA;CACxE;AAED,wBAAgB,KAAK,CAAE,IAAI,GAAE,SAAc,GAAG,CAAC,UAAU,EAAE,eAAe,KAAK,KAAK,CAEnF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAiEhD,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzD,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAgEhD,MAAM,UAAU,KAAK,CAAE,OAAkB,EAAE;IACzC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/fetch",
3
- "version": "3.0.21",
3
+ "version": "3.0.22-0f07e3df5",
4
4
  "description": "Implementation of the Fetch Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-fetch#readme",
@@ -45,22 +45,20 @@
45
45
  "doc-check": "aegir doc-check"
46
46
  },
47
47
  "dependencies": {
48
- "@libp2p/interface": "^2.10.5",
49
- "@libp2p/interface-internal": "^2.3.18",
50
- "it-protobuf-stream": "^2.0.2",
48
+ "@libp2p/interface": "2.11.0-0f07e3df5",
49
+ "@libp2p/interface-internal": "2.3.19-0f07e3df5",
50
+ "@libp2p/utils": "6.7.2-0f07e3df5",
51
51
  "main-event": "^1.0.1",
52
- "protons-runtime": "^5.5.0",
52
+ "protons-runtime": "^5.6.0",
53
53
  "uint8arraylist": "^2.4.8",
54
54
  "uint8arrays": "^5.1.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@libp2p/crypto": "^5.1.7",
58
- "@libp2p/logger": "^5.1.21",
59
- "@libp2p/peer-id": "^5.1.8",
60
- "aegir": "^47.0.14",
61
- "it-pair": "^2.0.6",
62
- "protons": "^7.6.1",
63
- "sinon": "^20.0.0",
57
+ "@libp2p/crypto": "5.1.8-0f07e3df5",
58
+ "@libp2p/peer-id": "5.1.9-0f07e3df5",
59
+ "aegir": "^47.0.21",
60
+ "protons": "^7.7.0",
61
+ "sinon": "^21.0.0",
64
62
  "sinon-ts": "^2.0.0"
65
63
  },
66
64
  "sideEffects": false
package/src/fetch.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { AbortError, InvalidMessageError, InvalidParametersError, ProtocolError } from '@libp2p/interface'
2
- import { pbStream } from 'it-protobuf-stream'
1
+ import { InvalidMessageError, InvalidParametersError, ProtocolError } from '@libp2p/interface'
2
+ import { pbStream } from '@libp2p/utils'
3
3
  import { setMaxListeners } from 'main-event'
4
4
  import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
5
5
  import { toString as uint8arrayToString } from 'uint8arrays/to-string'
6
6
  import { PROTOCOL_NAME, PROTOCOL_VERSION } from './constants.js'
7
7
  import { FetchRequest, FetchResponse } from './pb/proto.js'
8
8
  import type { Fetch as FetchInterface, FetchComponents, FetchInit, LookupFunction } from './index.js'
9
- import type { AbortOptions, Logger, Stream, PeerId, Startable, IncomingStreamData } from '@libp2p/interface'
9
+ import type { AbortOptions, Stream, PeerId, Startable } from '@libp2p/interface'
10
10
 
11
- const DEFAULT_TIMEOUT = 10000
11
+ const DEFAULT_TIMEOUT = 10_000
12
12
 
13
13
  /**
14
14
  * A simple libp2p protocol for requesting a value corresponding to a key from a peer.
@@ -22,30 +22,21 @@ export class Fetch implements Startable, FetchInterface {
22
22
  private readonly lookupFunctions: Map<string, LookupFunction>
23
23
  private started: boolean
24
24
  private readonly init: FetchInit
25
- private readonly log: Logger
26
25
 
27
26
  constructor (components: FetchComponents, init: FetchInit = {}) {
28
- this.log = components.logger.forComponent('libp2p:fetch')
29
27
  this.started = false
30
28
  this.components = components
31
29
  this.protocol = `/${init.protocolPrefix ?? 'libp2p'}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
32
30
  this.lookupFunctions = new Map() // Maps key prefix to value lookup function
33
- this.handleMessage = this.handleMessage.bind(this)
34
31
  this.init = init
32
+
33
+ this.handleMessage = this.handleMessage.bind(this)
35
34
  }
36
35
 
37
36
  readonly [Symbol.toStringTag] = '@libp2p/fetch'
38
37
 
39
38
  async start (): Promise<void> {
40
- await this.components.registrar.handle(this.protocol, (data) => {
41
- void this.handleMessage(data)
42
- .then(async () => {
43
- await data.stream.close()
44
- })
45
- .catch(err => {
46
- this.log.error('error handling message - %e', err)
47
- })
48
- }, {
39
+ await this.components.registrar.handle(this.protocol, this.handleMessage, {
49
40
  maxInboundStreams: this.init.maxInboundStreams,
50
41
  maxOutboundStreams: this.init.maxOutboundStreams
51
42
  })
@@ -69,35 +60,26 @@ export class Fetch implements Startable, FetchInterface {
69
60
  key = uint8arrayFromString(key)
70
61
  }
71
62
 
72
- this.log.trace('dialing %s to %p', this.protocol, peer)
73
-
74
- const connection = await this.components.connectionManager.openConnection(peer, options)
75
- let signal = options.signal
76
- let stream: Stream | undefined
77
- let onAbort = (): void => {}
78
-
79
63
  // create a timeout if no abort signal passed
80
- if (signal == null) {
64
+ if (options.signal == null) {
81
65
  const timeout = this.init.timeout ?? DEFAULT_TIMEOUT
82
- this.log.trace('using default timeout of %d ms', timeout)
83
- signal = AbortSignal.timeout(timeout)
84
-
66
+ const signal = AbortSignal.timeout(timeout)
85
67
  setMaxListeners(Infinity, signal)
86
- }
87
68
 
88
- try {
89
- stream = await connection.newStream(this.protocol, {
69
+ options = {
70
+ ...options,
90
71
  signal
91
- })
92
-
93
- onAbort = () => {
94
- stream?.abort(new AbortError())
95
72
  }
73
+ }
74
+
75
+ let stream: Stream | undefined
96
76
 
97
- // make stream abortable
98
- signal.addEventListener('abort', onAbort, { once: true })
77
+ try {
78
+ const connection = await this.components.connectionManager.openConnection(peer, options)
79
+ stream = await connection.newStream(this.protocol, options)
99
80
 
100
- this.log.trace('fetch %m', key)
81
+ const log = stream.log.newScope('fetch')
82
+ log.trace('fetch %m', key)
101
83
 
102
84
  const pb = pbStream(stream)
103
85
  await pb.write({
@@ -105,35 +87,31 @@ export class Fetch implements Startable, FetchInterface {
105
87
  }, FetchRequest, options)
106
88
 
107
89
  const response = await pb.read(FetchResponse, options)
108
- await pb.unwrap().close(options)
90
+
91
+ await stream.close(options)
109
92
 
110
93
  switch (response.status) {
111
94
  case (FetchResponse.StatusCode.OK): {
112
- this.log.trace('received status OK for %m', key)
95
+ log.trace('received status OK for %m', key)
113
96
  return response.data
114
97
  }
115
98
  case (FetchResponse.StatusCode.NOT_FOUND): {
116
- this.log('received status NOT_FOUND for %m', key)
99
+ log('received status NOT_FOUND for %m', key)
117
100
  return
118
101
  }
119
102
  case (FetchResponse.StatusCode.ERROR): {
120
- this.log('received status ERROR for %m', key)
103
+ log('received status ERROR for %m', key)
121
104
  const errMsg = uint8arrayToString(response.data)
122
105
  throw new ProtocolError('Error in fetch protocol response: ' + errMsg)
123
106
  }
124
107
  default: {
125
- this.log('received status unknown for %m', key)
108
+ log('received status unknown for %m', key)
126
109
  throw new InvalidMessageError('Unknown response status')
127
110
  }
128
111
  }
129
112
  } catch (err: any) {
130
113
  stream?.abort(err)
131
114
  throw err
132
- } finally {
133
- signal.removeEventListener('abort', onAbort)
134
- if (stream != null) {
135
- await stream.close()
136
- }
137
115
  }
138
116
  }
139
117
 
@@ -142,56 +120,51 @@ export class Fetch implements Startable, FetchInterface {
142
120
  * responds based on looking up the key in the request via the lookup callback that corresponds
143
121
  * to the key's prefix.
144
122
  */
145
- async handleMessage (data: IncomingStreamData): Promise<void> {
146
- const { stream } = data
123
+ async handleMessage (stream: Stream): Promise<void> {
124
+ const log = stream.log.newScope('fetch')
147
125
  const signal = AbortSignal.timeout(this.init.timeout ?? DEFAULT_TIMEOUT)
148
126
 
149
- try {
150
- const pb = pbStream(stream)
151
- const request = await pb.read(FetchRequest, {
152
- signal
153
- })
127
+ const pb = pbStream(stream)
128
+ const request = await pb.read(FetchRequest, {
129
+ signal
130
+ })
154
131
 
155
- let response: FetchResponse
156
- const key = uint8arrayToString(request.identifier)
132
+ let response: FetchResponse
133
+ const key = uint8arrayToString(request.identifier)
157
134
 
158
- const lookup = this._getLookupFunction(key)
135
+ const lookup = this._getLookupFunction(key)
159
136
 
160
- if (lookup == null) {
161
- this.log.trace('sending status ERROR for %m', request.identifier)
162
- const errMsg = uint8arrayFromString('No lookup function registered for key')
163
- response = { status: FetchResponse.StatusCode.ERROR, data: errMsg }
164
- } else {
165
- this.log.trace('lookup data with identifier %s', lookup.prefix)
166
-
167
- try {
168
- const data = await lookup.fn(request.identifier)
169
-
170
- if (data == null) {
171
- this.log.trace('sending status NOT_FOUND for %m', request.identifier)
172
- response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) }
173
- } else {
174
- this.log.trace('sending status OK for %m', request.identifier)
175
- response = { status: FetchResponse.StatusCode.OK, data }
176
- }
177
- } catch (err: any) {
178
- this.log.error('error during lookup of %m - %e', request.identifier, err)
179
- const errMsg = uint8arrayFromString(err.message)
180
- response = { status: FetchResponse.StatusCode.ERROR, data: errMsg }
137
+ if (lookup == null) {
138
+ log.trace('sending status ERROR for %m', request.identifier)
139
+ const errMsg = uint8arrayFromString('No lookup function registered for key')
140
+ response = { status: FetchResponse.StatusCode.ERROR, data: errMsg }
141
+ } else {
142
+ log.trace('lookup data with identifier %s', lookup.prefix)
143
+
144
+ try {
145
+ const data = await lookup.fn(request.identifier)
146
+
147
+ if (data == null) {
148
+ log.trace('sending status NOT_FOUND for %m', request.identifier)
149
+ response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) }
150
+ } else {
151
+ log.trace('sending status OK for %m', request.identifier)
152
+ response = { status: FetchResponse.StatusCode.OK, data }
181
153
  }
154
+ } catch (err: any) {
155
+ log.error('error during lookup of %m - %e', request.identifier, err)
156
+ const errMsg = uint8arrayFromString(err.message)
157
+ response = { status: FetchResponse.StatusCode.ERROR, data: errMsg }
182
158
  }
159
+ }
183
160
 
184
- await pb.write(response, FetchResponse, {
185
- signal
186
- })
161
+ await pb.write(response, FetchResponse, {
162
+ signal
163
+ })
187
164
 
188
- await pb.unwrap().close({
189
- signal
190
- })
191
- } catch (err: any) {
192
- this.log.error('error answering fetch request - %e', err)
193
- stream.abort(err)
194
- }
165
+ await stream.close({
166
+ signal
167
+ })
195
168
  }
196
169
 
197
170
  /**
package/src/index.ts CHANGED
@@ -43,7 +43,7 @@
43
43
  */
44
44
 
45
45
  import { Fetch as FetchClass } from './fetch.js'
46
- import type { AbortOptions, ComponentLogger, PeerId } from '@libp2p/interface'
46
+ import type { AbortOptions, PeerId } from '@libp2p/interface'
47
47
  import type { ConnectionManager, Registrar } from '@libp2p/interface-internal'
48
48
 
49
49
  export interface FetchInit {
@@ -71,7 +71,6 @@ export interface LookupFunction {
71
71
  export interface FetchComponents {
72
72
  registrar: Registrar
73
73
  connectionManager: ConnectionManager
74
- logger: ComponentLogger
75
74
  }
76
75
 
77
76
  export interface Fetch {
@@ -1,12 +0,0 @@
1
- {
2
- "Fetch": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.Fetch.html",
3
- ".:Fetch": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.Fetch.html",
4
- "FetchComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchComponents.html",
5
- ".:FetchComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchComponents.html",
6
- "FetchInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchInit.html",
7
- ".:FetchInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.FetchInit.html",
8
- "LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.LookupFunction.html",
9
- ".:LookupFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_fetch.LookupFunction.html",
10
- "fetch": "https://libp2p.github.io/js-libp2p/functions/_libp2p_fetch.fetch.html",
11
- ".:fetch": "https://libp2p.github.io/js-libp2p/functions/_libp2p_fetch.fetch.html"
12
- }