@pkcprotocol/pkc-js 0.0.53 → 0.0.54

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.
Files changed (55) hide show
  1. package/dist/browser/generated-version.d.ts +1 -1
  2. package/dist/browser/generated-version.js +1 -1
  3. package/dist/browser/pkc/pkc.d.ts +2 -1
  4. package/dist/browser/pkc/pkc.js +17 -10
  5. package/dist/browser/pkc/pkc.js.map +1 -1
  6. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
  7. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
  8. package/dist/browser/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  9. package/dist/browser/runtime/node/address-rewriter-db.d.ts +32 -0
  10. package/dist/browser/runtime/node/address-rewriter-db.js +156 -0
  11. package/dist/browser/runtime/node/address-rewriter-db.js.map +1 -0
  12. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.d.ts +46 -0
  13. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js +512 -0
  14. package/dist/browser/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
  15. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
  16. package/dist/browser/runtime/node/{setup-kubo-http-routers.js → setup-kubo-address-rewriter-and-http-router.js} +96 -18
  17. package/dist/browser/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  18. package/dist/bundled/bundle-manifest.json +43 -26
  19. package/dist/bundled/chunks/{helia-for-pkc-C7iz4N_u.js → helia-for-pkc-B_qcguXh.js} +2 -2
  20. package/dist/bundled/chunks/{local-community-BC8evwle.js → local-community-B6lpBLfD.js} +2 -2
  21. package/dist/bundled/chunks/{local-community-BwRiKAD-.js → local-community-D6jAtedZ.js} +1 -1
  22. package/dist/bundled/chunks/{node-LV4itBPZ.js → node-Buwttv5o.js} +2854 -283
  23. package/dist/bundled/chunks/{rpc-local-community-BJOyJhKy.js → rpc-local-community-DaIpxfd_.js} +1 -1
  24. package/dist/bundled/chunks/{schema-GS_Tj3Qx.js → schema-CeeqV5ES.js} +1 -1
  25. package/dist/bundled/chunks/{util-DuVBTVzc.js → util-sg6BmkRA.js} +1 -1
  26. package/dist/bundled/index.js +1 -1
  27. package/dist/bundled/rpc/src/index.js +4 -4
  28. package/dist/node/generated-version.d.ts +1 -1
  29. package/dist/node/generated-version.js +1 -1
  30. package/dist/node/pkc/pkc.d.ts +2 -1
  31. package/dist/node/pkc/pkc.js +17 -10
  32. package/dist/node/pkc/pkc.js.map +1 -1
  33. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.d.ts +1 -0
  34. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js +4 -0
  35. package/dist/node/runtime/browser/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  36. package/dist/node/runtime/node/address-rewriter-db.d.ts +32 -0
  37. package/dist/node/runtime/node/address-rewriter-db.js +156 -0
  38. package/dist/node/runtime/node/address-rewriter-db.js.map +1 -0
  39. package/dist/node/runtime/node/addresses-rewriter-proxy-server.d.ts +46 -0
  40. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js +512 -0
  41. package/dist/node/runtime/node/addresses-rewriter-proxy-server.js.map +1 -0
  42. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.d.ts +4 -0
  43. package/dist/node/runtime/node/{setup-kubo-http-routers.js → setup-kubo-address-rewriter-and-http-router.js} +96 -18
  44. package/dist/node/runtime/node/setup-kubo-address-rewriter-and-http-router.js.map +1 -0
  45. package/package.json +2 -2
  46. package/dist/browser/runtime/browser/setup-kubo-http-routers.d.ts +0 -1
  47. package/dist/browser/runtime/browser/setup-kubo-http-routers.js +0 -4
  48. package/dist/browser/runtime/browser/setup-kubo-http-routers.js.map +0 -1
  49. package/dist/browser/runtime/node/setup-kubo-http-routers.d.ts +0 -2
  50. package/dist/browser/runtime/node/setup-kubo-http-routers.js.map +0 -1
  51. package/dist/node/runtime/browser/setup-kubo-http-routers.d.ts +0 -1
  52. package/dist/node/runtime/browser/setup-kubo-http-routers.js +0 -4
  53. package/dist/node/runtime/browser/setup-kubo-http-routers.js.map +0 -1
  54. package/dist/node/runtime/node/setup-kubo-http-routers.d.ts +0 -2
  55. package/dist/node/runtime/node/setup-kubo-http-routers.js.map +0 -1
@@ -0,0 +1,512 @@
1
+ import http from "node:http";
2
+ import https from "node:https";
3
+ import Logger from "../../logger.js";
4
+ import * as remeda from "remeda";
5
+ import retry from "retry";
6
+ import { hideClassPrivateProps } from "../../util.js";
7
+ import { AddressRewriterDatabase } from "./address-rewriter-db.js";
8
+ const debug = Logger("pkc-js:addresses-rewriter");
9
+ const MAX_BODY_PREVIEW_BYTES = 4096;
10
+ export class AddressesRewriterProxyServer {
11
+ constructor({ kuboClients: kuboClient, port, hostname, proxyTargetUrl, pkc }) {
12
+ this._requestLogBuffer = [];
13
+ this._isWritingLogs = false;
14
+ // Failed keys retry logic
15
+ this._failedKeys = new Set();
16
+ this._isRetrying = false;
17
+ this.addresses = {};
18
+ this.kuboClients = kuboClient;
19
+ this.port = port;
20
+ this.hostname = hostname || "127.0.0.1";
21
+ this.proxyTarget = new URL(proxyTargetUrl);
22
+ this.server = http.createServer((req, res) => this._proxyRequestRewrite(req, res));
23
+ this._storageKeyName = `httprouter_proxy_${proxyTargetUrl}`;
24
+ this._pkc = pkc;
25
+ // Environment-based logging toggle
26
+ const envValue = process.env.ENABLE_LOGGING_OF_ADDRESS_REWRITER_PROXY;
27
+ this._loggingEnabled = envValue === "1" || envValue?.toLowerCase() === "true";
28
+ // Initialize database only when logging is enabled
29
+ if (this._loggingEnabled) {
30
+ const kuboConfig = this.kuboClients?.[0]?.getEndpointConfig();
31
+ this._db = new AddressRewriterDatabase(this._pkc.dataPath, kuboConfig, this.proxyTarget);
32
+ }
33
+ else {
34
+ this._db = null;
35
+ }
36
+ // Create HTTP agents with connection pooling and keep-alive
37
+ this._httpAgent = new http.Agent({
38
+ keepAlive: true,
39
+ keepAliveMsecs: 30000,
40
+ maxSockets: 50,
41
+ timeout: 10000
42
+ });
43
+ this._httpsAgent = new https.Agent({
44
+ keepAlive: true,
45
+ keepAliveMsecs: 30000,
46
+ maxSockets: 50,
47
+ timeout: 10000
48
+ });
49
+ hideClassPrivateProps(this);
50
+ }
51
+ async listen(callback) {
52
+ if (this._loggingEnabled && this._db) {
53
+ await this._db.initialize();
54
+ debug("Request logging enabled for addresses rewriter proxy");
55
+ }
56
+ else {
57
+ debug("Request logging disabled for addresses rewriter proxy");
58
+ }
59
+ await this._startUpdateAddressesLoop();
60
+ if (this._loggingEnabled) {
61
+ this._startRequestLogging();
62
+ }
63
+ await this._startFailedKeysRetry();
64
+ this.server.on("error", (err) => debug.error("Error with address rewriter proxy", this.server.address(), "Proxy target", this.proxyTarget, err));
65
+ this.server.listen(this.port, this.hostname, callback);
66
+ debug("Addresses rewriter proxy at", this.hostname + ":" + this.port, "started listening to forward requests to", this.proxyTarget.host, `- request logging ${this._loggingEnabled ? "enabled" : "disabled"}`);
67
+ await this._pkc._storage.setItem(this._storageKeyName, `http://${this.hostname}:${this.port}`);
68
+ }
69
+ async destroy() {
70
+ this.server.close();
71
+ if (this._updateAddressesInterval) {
72
+ clearInterval(this._updateAddressesInterval);
73
+ }
74
+ if (this._logWriteInterval) {
75
+ clearInterval(this._logWriteInterval);
76
+ }
77
+ if (this._retryInterval) {
78
+ clearInterval(this._retryInterval);
79
+ }
80
+ // Write any remaining logs before destroying
81
+ await this._writeRequestLogs();
82
+ // Close database connection
83
+ this._db?.close();
84
+ // Destroy HTTP agents to clean up connections
85
+ this._httpAgent.destroy();
86
+ this._httpsAgent.destroy();
87
+ await this._pkc._storage.removeItem(this._storageKeyName);
88
+ }
89
+ _proxyRequestRewrite(req, res) {
90
+ // get post body
91
+ let reqBody = "";
92
+ req.on("data", (chunk) => {
93
+ reqBody += chunk.toString();
94
+ });
95
+ // wait for full post body
96
+ req.on("end", () => {
97
+ // Only track and rewrite PUT/POST requests (provider registration)
98
+ const shouldRewrite = req.method === "PUT" || req.method === "POST";
99
+ // Create request log entry for PUT/POST requests
100
+ let requestLogEntry = null;
101
+ if (shouldRewrite) {
102
+ const keys = this._extractKeysFromRequestBody(reqBody);
103
+ const shouldLogRequest = this._loggingEnabled;
104
+ if (keys.length > 0 || shouldLogRequest) {
105
+ requestLogEntry = {
106
+ keys,
107
+ receivedAt: Date.now(),
108
+ success: false,
109
+ method: req.method || "UNKNOWN",
110
+ url: req.url || "/",
111
+ retryCount: 0,
112
+ bodyPreview: shouldLogRequest ? this._createBodyPreview(reqBody) : undefined
113
+ };
114
+ if (shouldLogRequest) {
115
+ this._requestLogBuffer.push(requestLogEntry);
116
+ }
117
+ }
118
+ }
119
+ // rewrite body with up to date addresses (only for PUT/POST)
120
+ let rewrittenBody = reqBody;
121
+ if (shouldRewrite && rewrittenBody) {
122
+ try {
123
+ const json = JSON.parse(rewrittenBody);
124
+ if (json.Providers && Array.isArray(json.Providers)) {
125
+ for (const provider of json.Providers) {
126
+ const peerId = provider?.Payload?.ID;
127
+ if (peerId && this.addresses[peerId]) {
128
+ provider.Payload.Addrs = this.addresses[peerId];
129
+ }
130
+ }
131
+ rewrittenBody = JSON.stringify(json);
132
+ }
133
+ }
134
+ catch (e) {
135
+ const error = e;
136
+ debug("proxy body rewrite error:", error, "body", rewrittenBody, req.url, req.method);
137
+ }
138
+ }
139
+ // proxy the request
140
+ this._proxyRequest(req, res, rewrittenBody, requestLogEntry);
141
+ });
142
+ // Handle request errors
143
+ req.on("error", (err) => {
144
+ debug.trace("Request error:", req.url, req.method, req.headers, reqBody, err);
145
+ if (!res.headersSent) {
146
+ debug.trace("Request error:", req.url, req.method, req.headers, reqBody, err);
147
+ res.writeHead(500);
148
+ res.end("Internal Server Error");
149
+ }
150
+ });
151
+ }
152
+ _proxyRequest(req, res, rewrittenBody, requestLogEntry) {
153
+ if (requestLogEntry) {
154
+ requestLogEntry.retryCount = 0;
155
+ requestLogEntry.transmittedAt = Date.now();
156
+ }
157
+ const { request: httpRequest } = this.proxyTarget.protocol === "https:" ? https : http;
158
+ const agent = this.proxyTarget.protocol === "https:" ? this._httpsAgent : this._httpAgent;
159
+ const requestOptions = {
160
+ hostname: this.proxyTarget.hostname,
161
+ protocol: this.proxyTarget.protocol,
162
+ path: req.url,
163
+ method: req.method,
164
+ headers: {
165
+ ...req.headers,
166
+ // Node lowercases all incoming header names, so req.headers always carries
167
+ // `content-length` regardless of the casing kubo used on the wire. Overriding the
168
+ // lowercase key alone covers every case; a second uppercase key would only emit a
169
+ // duplicate Content-Length header that some routers reject.
170
+ "content-length": Buffer.byteLength(rewrittenBody),
171
+ host: this.proxyTarget.host
172
+ },
173
+ agent,
174
+ timeout: 10000
175
+ };
176
+ if (this.proxyTarget.port) {
177
+ requestOptions.port = this.proxyTarget.port;
178
+ }
179
+ const proxyReq = httpRequest(requestOptions);
180
+ // Handle timeout
181
+ proxyReq.setTimeout(10000, () => {
182
+ debug.trace("Proxy request timed out", requestOptions);
183
+ if (requestLogEntry) {
184
+ requestLogEntry.success = false;
185
+ requestLogEntry.statusCode = 504;
186
+ requestLogEntry.error = "Request timeout";
187
+ // Add failed keys to retry set
188
+ if (requestLogEntry.keys) {
189
+ const sizeBefore = this._failedKeys.size;
190
+ requestLogEntry.keys.forEach((key) => this._failedKeys.add(key));
191
+ const sizeAfter = this._failedKeys.size;
192
+ if (sizeAfter > sizeBefore) {
193
+ // Save to database when new keys are added
194
+ this._saveFailedKeysToDatabase();
195
+ }
196
+ }
197
+ }
198
+ proxyReq.destroy();
199
+ if (!res.headersSent) {
200
+ res.writeHead(504);
201
+ res.end("Gateway Timeout");
202
+ }
203
+ });
204
+ // Handle proxy request errors
205
+ proxyReq.on("error", (e) => {
206
+ proxyReq.destroy();
207
+ if (requestLogEntry) {
208
+ requestLogEntry.success = false;
209
+ requestLogEntry.statusCode = 500;
210
+ requestLogEntry.error = `Proxy error: ${e.message}`;
211
+ debug.trace(`Updated log entry with error for keys: ${requestLogEntry.keys.join(", ")}`);
212
+ // Add failed keys to retry set
213
+ if (requestLogEntry.keys) {
214
+ const sizeBefore = this._failedKeys.size;
215
+ requestLogEntry.keys.forEach((key) => this._failedKeys.add(key));
216
+ const sizeAfter = this._failedKeys.size;
217
+ if (sizeAfter > sizeBefore) {
218
+ // Save to database when new keys are added
219
+ this._saveFailedKeysToDatabase();
220
+ }
221
+ }
222
+ }
223
+ if (!res.headersSent) {
224
+ debug.trace("address rewriter proxy error:", e, "Request options", requestOptions);
225
+ res.writeHead(500);
226
+ res.end("Internal Server Error");
227
+ }
228
+ });
229
+ // Handle the proxy response
230
+ proxyReq.on("response", (proxyRes) => {
231
+ const statusCode = proxyRes.statusCode || 500;
232
+ const isSuccess = statusCode >= 200 && statusCode < 300;
233
+ if (requestLogEntry) {
234
+ requestLogEntry.success = isSuccess;
235
+ requestLogEntry.statusCode = statusCode;
236
+ if (!isSuccess) {
237
+ requestLogEntry.error = `HTTP ${statusCode}`;
238
+ // Add failed keys to retry set
239
+ if (requestLogEntry.keys) {
240
+ const sizeBefore = this._failedKeys.size;
241
+ requestLogEntry.keys.forEach((key) => this._failedKeys.add(key));
242
+ const sizeAfter = this._failedKeys.size;
243
+ if (sizeAfter > sizeBefore) {
244
+ // Save to database when new keys are added
245
+ this._saveFailedKeysToDatabase();
246
+ }
247
+ }
248
+ }
249
+ }
250
+ // Handle proxy response errors
251
+ proxyRes.on("error", (err) => {
252
+ debug.trace("Proxy response error:", err);
253
+ if (!res.headersSent) {
254
+ res.writeHead(500);
255
+ res.end("Proxy Response Error");
256
+ }
257
+ if (requestLogEntry) {
258
+ requestLogEntry.success = false;
259
+ requestLogEntry.statusCode = 500;
260
+ requestLogEntry.error = `Proxy response error: ${err.message}`;
261
+ }
262
+ proxyRes.destroy(err);
263
+ });
264
+ // Forward successful response
265
+ if (!res.headersSent) {
266
+ res.writeHead(statusCode, proxyRes.headers);
267
+ proxyRes.pipe(res);
268
+ }
269
+ res.on("finish", () => {
270
+ proxyRes.resume();
271
+ });
272
+ });
273
+ proxyReq.write(rewrittenBody);
274
+ proxyReq.end();
275
+ }
276
+ // get up to date listen addresses from kubo every x minutes
277
+ async _startUpdateAddressesLoop() {
278
+ if (!this.kuboClients?.length)
279
+ throw Error("should have a defined kubo rpc client option to start the address rewriter");
280
+ const isRetriableError = (error) => {
281
+ if (typeof error !== "object" || error === null)
282
+ return false;
283
+ const err = error;
284
+ return err.response?.status === 500 || err.status === 500 || err.statusCode === 500;
285
+ };
286
+ const tryUpdateAddressesForClient = async (kuboClient) => {
287
+ return new Promise((resolve) => {
288
+ const operation = retry.operation({
289
+ retries: 3,
290
+ factor: 2,
291
+ minTimeout: 1000,
292
+ maxTimeout: 8000
293
+ });
294
+ operation.attempt(async (currentAttempt) => {
295
+ try {
296
+ const idRes = await kuboClient.id();
297
+ const swarmAddrsRes = await kuboClient.swarm.addrs();
298
+ const peerId = idRes.id.toString();
299
+ if (typeof peerId !== "string")
300
+ throw Error("Failed to get Peer ID of kubo node");
301
+ const swarmListeningAddresses = swarmAddrsRes.filter((swarmAddr) => swarmAddr.id.toString() === peerId);
302
+ const addresses = remeda.unique([
303
+ ...idRes.addresses.map((addr) => addr.toString()),
304
+ ...remeda.flatten(swarmListeningAddresses.map((swarmAddr) => swarmAddr.addrs.map((addr) => addr.toString())))
305
+ ]);
306
+ if (addresses.length === 0) {
307
+ throw Error(`Failed to get any addresses for peer ${peerId}`);
308
+ }
309
+ this.addresses[peerId] = addresses;
310
+ resolve();
311
+ }
312
+ catch (e) {
313
+ const error = e;
314
+ if (isRetriableError(error)) {
315
+ debug(`tryUpdateAddresses attempt ${currentAttempt}/4 failed with 500 error:`, error.message, {
316
+ kuboConfig: kuboClient.getEndpointConfig()
317
+ });
318
+ if (operation.retry(error))
319
+ return;
320
+ }
321
+ debug("tryUpdateAddresses error:", error.message, { kuboConfig: kuboClient.getEndpointConfig() });
322
+ resolve(); // Don't reject, just log and continue with other clients
323
+ }
324
+ });
325
+ });
326
+ };
327
+ const tryUpdateAddresses = async () => {
328
+ const promises = this.kuboClients.map(tryUpdateAddressesForClient);
329
+ await Promise.allSettled(promises);
330
+ };
331
+ await tryUpdateAddresses();
332
+ this._updateAddressesInterval = setInterval(tryUpdateAddresses, 1000 * 60);
333
+ }
334
+ _extractKeysFromRequestBody(body) {
335
+ try {
336
+ const json = JSON.parse(body);
337
+ const keys = [];
338
+ if (json.Providers && Array.isArray(json.Providers)) {
339
+ for (const provider of json.Providers) {
340
+ if (provider?.Payload?.Keys) {
341
+ keys.push(...provider.Payload.Keys);
342
+ }
343
+ }
344
+ }
345
+ return keys;
346
+ }
347
+ catch {
348
+ return [];
349
+ }
350
+ }
351
+ _createBodyPreview(body) {
352
+ const buffer = Buffer.from(body, "utf8");
353
+ if (buffer.length <= MAX_BODY_PREVIEW_BYTES)
354
+ return body;
355
+ const truncated = buffer.subarray(0, MAX_BODY_PREVIEW_BYTES).toString("utf8");
356
+ const truncatedBytes = buffer.length - MAX_BODY_PREVIEW_BYTES;
357
+ return `${truncated}...[truncated ${truncatedBytes} bytes]`;
358
+ }
359
+ async _writeRequestLogs() {
360
+ if (!this._loggingEnabled || !this._db) {
361
+ return;
362
+ }
363
+ if (this._requestLogBuffer.length === 0 || this._isWritingLogs) {
364
+ return;
365
+ }
366
+ this._isWritingLogs = true;
367
+ const logsToWrite = [...this._requestLogBuffer];
368
+ this._requestLogBuffer = []; // Clear buffer immediately to prevent duplicates
369
+ try {
370
+ this._db.insertRequestLogs(logsToWrite);
371
+ debug.trace(`Wrote ${logsToWrite.length} new request log entries to SQLite database`);
372
+ }
373
+ catch (error) {
374
+ debug.error(`Failed to write request logs to SQLite database:`, error);
375
+ // Put logs back in buffer on failure
376
+ this._requestLogBuffer.unshift(...logsToWrite);
377
+ }
378
+ finally {
379
+ this._isWritingLogs = false;
380
+ }
381
+ }
382
+ _startRequestLogging() {
383
+ if (!this._loggingEnabled || !this._db) {
384
+ return;
385
+ }
386
+ const writeInterval = 5 * 1000; // 5 seconds
387
+ this._logWriteInterval = setInterval(async () => {
388
+ await this._writeRequestLogs();
389
+ }, writeInterval);
390
+ }
391
+ async _startFailedKeysRetry() {
392
+ // Load failed keys from database on startup
393
+ this._loadFailedKeysFromDatabase();
394
+ // Start 2-minute interval for retrying failed keys
395
+ const retryInterval = 2 * 60 * 1000; // 2 minutes
396
+ this._retryInterval = setInterval(async () => {
397
+ // Skip if a previous run is still going; the per-key provide loop can exceed the
398
+ // interval, and overlapping runs would race on _failedKeys and double-provide.
399
+ if (this._isRetrying) {
400
+ debug.trace("Previous failed-keys retry still running, skipping this tick");
401
+ return;
402
+ }
403
+ this._isRetrying = true;
404
+ try {
405
+ await this._retryFailedKeys();
406
+ }
407
+ finally {
408
+ this._isRetrying = false;
409
+ }
410
+ }, retryInterval);
411
+ debug(`Started failed keys retry with ${this._failedKeys.size} keys from previous sessions`);
412
+ }
413
+ _loadFailedKeysFromDatabase() {
414
+ if (!this._loggingEnabled || !this._db) {
415
+ return;
416
+ }
417
+ try {
418
+ const keys = this._db.loadFailedKeys();
419
+ keys.forEach((key) => this._failedKeys.add(key));
420
+ debug(`Loaded ${keys.length} failed keys from database`);
421
+ }
422
+ catch (error) {
423
+ debug.error("Failed to load failed keys from database:", error);
424
+ throw error;
425
+ }
426
+ }
427
+ _saveFailedKeysToDatabase() {
428
+ if (!this._loggingEnabled || !this._db) {
429
+ return;
430
+ }
431
+ try {
432
+ const keys = Array.from(this._failedKeys);
433
+ this._db.saveFailedKeys(keys);
434
+ if (keys.length === 0) {
435
+ debug.trace(`All keys successfully provided - no failed keys to save`);
436
+ }
437
+ else {
438
+ debug.trace(`Saved ${keys.length} failed keys to database`);
439
+ }
440
+ }
441
+ catch (error) {
442
+ debug.error("Failed to save failed keys to database:", error);
443
+ throw error;
444
+ }
445
+ }
446
+ async _retryFailedKeys() {
447
+ if (this._failedKeys.size === 0) {
448
+ debug.trace(`No failed keys to retry - all keys successfully provided`);
449
+ return;
450
+ }
451
+ debug(`Retrying ${this._failedKeys.size} failed keys`);
452
+ const keysToRetry = Array.from(this._failedKeys);
453
+ const kuboClient = this.kuboClients?.[0];
454
+ if (!kuboClient) {
455
+ debug.error("No kubo client available for retry");
456
+ return;
457
+ }
458
+ const successfulKeys = [];
459
+ const stillFailedKeys = [];
460
+ const keysToDiscard = [];
461
+ // Process each key individually to get better granular control
462
+ for (const key of keysToRetry) {
463
+ try {
464
+ debug.trace(`Providing key to HTTP routers: ${key}`);
465
+ const events = [];
466
+ for await (const event of kuboClient.routing.provide(key, { recursive: true, verbose: true })) {
467
+ events.push(event);
468
+ debug(`Routing provide event for ${key}:`, event);
469
+ }
470
+ successfulKeys.push(key);
471
+ debug.trace(`Successfully provided key: ${key}`);
472
+ // Log successful reprovide attempt
473
+ this._logReprovideAttempt(key, true, undefined, false);
474
+ }
475
+ catch (error) {
476
+ const errorMessage = error instanceof Error ? error.message : String(error);
477
+ const isBlockNotLocal = errorMessage.includes("block") && errorMessage.includes("not found locally");
478
+ // Log failed reprovide attempt
479
+ this._logReprovideAttempt(key, false, errorMessage, isBlockNotLocal);
480
+ // If block not found locally, discard this key - no point in retrying
481
+ if (isBlockNotLocal) {
482
+ keysToDiscard.push(key);
483
+ debug.trace(`Discarding key ${key} - block not found locally, will not retry`);
484
+ }
485
+ else {
486
+ stillFailedKeys.push(key);
487
+ debug.trace(`Failed to provide key ${key}:`, error);
488
+ }
489
+ }
490
+ }
491
+ // Remove successful keys and keys to discard from failed set
492
+ successfulKeys.forEach((key) => this._failedKeys.delete(key));
493
+ keysToDiscard.forEach((key) => this._failedKeys.delete(key));
494
+ // Save updated failed keys to database
495
+ this._saveFailedKeysToDatabase();
496
+ debug.trace(`Retry completed: ${successfulKeys.length} successful, ${stillFailedKeys.length} still failed, ${keysToDiscard.length} discarded`);
497
+ }
498
+ _logReprovideAttempt(key, success, error, blockNotLocal) {
499
+ if (!this._loggingEnabled || !this._db) {
500
+ return;
501
+ }
502
+ try {
503
+ this._db.insertReprovideLog(key, success, error, blockNotLocal);
504
+ debug.trace(`Logged reprovide attempt for key ${key}: success=${success}, blockNotLocal=${blockNotLocal}`);
505
+ }
506
+ catch (error) {
507
+ debug.error(`Failed to log reprovide attempt for key ${key}:`, error);
508
+ throw error;
509
+ }
510
+ }
511
+ }
512
+ //# sourceMappingURL=addresses-rewriter-proxy-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addresses-rewriter-proxy-server.js","sourceRoot":"","sources":["../../../../src/runtime/node/addresses-rewriter-proxy-server.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,uBAAuB,EAAmB,MAAM,0BAA0B,CAAC;AACpF,MAAM,KAAK,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAClD,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAUpC,MAAM,OAAO,4BAA4B;IA2BrC,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,EAA4B;QAd9F,sBAAiB,GAAsB,EAAE,CAAC;QAC1C,mBAAc,GAAG,KAAK,CAAC;QAG/B,0BAA0B;QAClB,gBAAW,GAAgB,IAAI,GAAG,EAAE,CAAC;QAErC,gBAAW,GAAG,KAAK,CAAC;QAQxB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QAEpB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,WAAW,CAAC;QACxC,IAAI,CAAC,WAAW,GAAG,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