@ar.io/wayfinder-core 0.0.1
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/LICENSE +201 -0
- package/README.md +318 -0
- package/dist/gateways/network.d.ts +39 -0
- package/dist/gateways/network.d.ts.map +1 -0
- package/dist/gateways/network.js +62 -0
- package/dist/gateways/simple-cache.d.ts +51 -0
- package/dist/gateways/simple-cache.d.ts.map +1 -0
- package/dist/gateways/simple-cache.js +66 -0
- package/dist/gateways/static.d.ts +26 -0
- package/dist/gateways/static.d.ts.map +1 -0
- package/dist/gateways/static.js +9 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/routing/ping.d.ts +19 -0
- package/dist/routing/ping.d.ts.map +1 -0
- package/dist/routing/ping.js +77 -0
- package/dist/routing/preferred-with-fallback.d.ts +34 -0
- package/dist/routing/preferred-with-fallback.d.ts.map +1 -0
- package/dist/routing/preferred-with-fallback.js +41 -0
- package/dist/routing/random.d.ts +24 -0
- package/dist/routing/random.d.ts.map +1 -0
- package/dist/routing/random.js +9 -0
- package/dist/routing/round-robin.d.ts +50 -0
- package/dist/routing/round-robin.d.ts.map +1 -0
- package/dist/routing/round-robin.js +41 -0
- package/dist/routing/static.d.ts +49 -0
- package/dist/routing/static.d.ts.map +1 -0
- package/dist/routing/static.js +37 -0
- package/dist/utils/ario.d.ts +28 -0
- package/dist/utils/ario.d.ts.map +1 -0
- package/dist/utils/ario.js +27 -0
- package/dist/utils/base64.d.ts +21 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +51 -0
- package/dist/utils/hash.d.ts +10 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +81 -0
- package/dist/utils/random.d.ts +25 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +26 -0
- package/dist/verification/data-root-verifier.d.ts +28 -0
- package/dist/verification/data-root-verifier.d.ts.map +1 -0
- package/dist/verification/data-root-verifier.js +129 -0
- package/dist/verification/hash-verifier.d.ts +28 -0
- package/dist/verification/hash-verifier.d.ts.map +1 -0
- package/dist/verification/hash-verifier.js +108 -0
- package/dist/wayfinder.d.ts +301 -0
- package/dist/wayfinder.d.ts.map +1 -0
- package/dist/wayfinder.js +498 -0
- package/package.json +44 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { defaultLogger } from '../wayfinder.js';
|
|
19
|
+
export class SimpleCacheGatewaysProvider {
|
|
20
|
+
gatewaysProvider;
|
|
21
|
+
ttlSeconds;
|
|
22
|
+
lastUpdated;
|
|
23
|
+
gatewaysCache;
|
|
24
|
+
logger;
|
|
25
|
+
constructor({ gatewaysProvider, ttlSeconds = 60 * 60, // 1 hour
|
|
26
|
+
logger = defaultLogger, }) {
|
|
27
|
+
this.gatewaysCache = [];
|
|
28
|
+
this.gatewaysProvider = gatewaysProvider;
|
|
29
|
+
this.ttlSeconds = ttlSeconds;
|
|
30
|
+
this.lastUpdated = 0;
|
|
31
|
+
this.logger = logger;
|
|
32
|
+
}
|
|
33
|
+
async getGateways() {
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
if (this.gatewaysCache.length === 0 ||
|
|
36
|
+
now - this.lastUpdated > this.ttlSeconds * 1000) {
|
|
37
|
+
try {
|
|
38
|
+
this.logger.debug('Cache expired, fetching new gateways', {
|
|
39
|
+
cacheAge: now - this.lastUpdated,
|
|
40
|
+
ttlSeconds: this.ttlSeconds,
|
|
41
|
+
});
|
|
42
|
+
// preserve the cache if the fetch fails
|
|
43
|
+
const allGateways = await this.gatewaysProvider.getGateways();
|
|
44
|
+
this.gatewaysCache = allGateways;
|
|
45
|
+
this.lastUpdated = now;
|
|
46
|
+
this.logger.debug('Updated gateways cache', {
|
|
47
|
+
gatewayCount: allGateways.length,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
this.logger.error('Failed to fetch gateways', {
|
|
52
|
+
error: error.message,
|
|
53
|
+
stack: error.stack,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.logger.debug('Using cached gateways', {
|
|
59
|
+
cacheAge: now - this.lastUpdated,
|
|
60
|
+
ttlSeconds: this.ttlSeconds,
|
|
61
|
+
gatewayCount: this.gatewaysCache.length,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return this.gatewaysCache;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { GatewaysProvider } from '../../types/wayfinder.js';
|
|
19
|
+
export declare class StaticGatewaysProvider implements GatewaysProvider {
|
|
20
|
+
private gateways;
|
|
21
|
+
constructor({ gateways }: {
|
|
22
|
+
gateways: string[];
|
|
23
|
+
});
|
|
24
|
+
getGateways(): Promise<URL[]>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=static.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/gateways/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,QAAQ,CAAQ;gBACZ,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;IAI1C,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;CAGpC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
export * from './wayfinder.js';
|
|
19
|
+
export * from './routing/random.js';
|
|
20
|
+
export * from './routing/static.js';
|
|
21
|
+
export * from './routing/ping.js';
|
|
22
|
+
export * from './routing/round-robin.js';
|
|
23
|
+
export * from './routing/preferred-with-fallback.js';
|
|
24
|
+
export * from './gateways/network.js';
|
|
25
|
+
export * from './gateways/simple-cache.js';
|
|
26
|
+
export * from './gateways/static.js';
|
|
27
|
+
export * from './verification/data-root-verifier.js';
|
|
28
|
+
export * from './verification/hash-verifier.js';
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,cAAc,gBAAgB,CAAC;AAG/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sCAAsC,CAAC;AAGrD,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AAGrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,iCAAiC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
export * from './wayfinder.js';
|
|
19
|
+
// routing strategies
|
|
20
|
+
export * from './routing/random.js';
|
|
21
|
+
export * from './routing/static.js';
|
|
22
|
+
export * from './routing/ping.js';
|
|
23
|
+
export * from './routing/round-robin.js';
|
|
24
|
+
export * from './routing/preferred-with-fallback.js';
|
|
25
|
+
// gateways providers
|
|
26
|
+
export * from './gateways/network.js';
|
|
27
|
+
export * from './gateways/simple-cache.js';
|
|
28
|
+
export * from './gateways/static.js';
|
|
29
|
+
// verification strategies
|
|
30
|
+
export * from './verification/data-root-verifier.js';
|
|
31
|
+
export * from './verification/hash-verifier.js';
|
|
32
|
+
// TODO: signature verifier
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
2
|
+
import { Logger } from '../wayfinder.js';
|
|
3
|
+
export declare class FastestPingRoutingStrategy implements RoutingStrategy {
|
|
4
|
+
private timeoutMs;
|
|
5
|
+
private probePath;
|
|
6
|
+
private logger;
|
|
7
|
+
private maxConcurrency;
|
|
8
|
+
constructor({ timeoutMs, maxConcurrency, probePath, // TODO: limit to allowed /ar-io and arweave node endpoints
|
|
9
|
+
logger, }?: {
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
maxConcurrency?: number;
|
|
12
|
+
probePath?: string;
|
|
13
|
+
logger?: Logger;
|
|
14
|
+
});
|
|
15
|
+
selectGateway({ gateways }: {
|
|
16
|
+
gateways: URL[];
|
|
17
|
+
}): Promise<URL>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/routing/ping.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAS;gBAEnB,EACV,SAAe,EACf,cAAmB,EACnB,SAAyB,EAAE,2DAA2D;IACtF,MAAsB,GACvB,GAAE;QACD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ;IAOA,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CA2DrE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { pLimit } from 'plimit-lit';
|
|
19
|
+
import { defaultLogger } from '../wayfinder.js';
|
|
20
|
+
export class FastestPingRoutingStrategy {
|
|
21
|
+
timeoutMs;
|
|
22
|
+
probePath;
|
|
23
|
+
logger;
|
|
24
|
+
maxConcurrency;
|
|
25
|
+
constructor({ timeoutMs = 500, maxConcurrency = 50, probePath = '/ar-io/info', // TODO: limit to allowed /ar-io and arweave node endpoints
|
|
26
|
+
logger = defaultLogger, } = {}) {
|
|
27
|
+
this.timeoutMs = timeoutMs;
|
|
28
|
+
this.probePath = probePath;
|
|
29
|
+
this.logger = logger;
|
|
30
|
+
this.maxConcurrency = maxConcurrency;
|
|
31
|
+
}
|
|
32
|
+
async selectGateway({ gateways }) {
|
|
33
|
+
if (gateways.length === 0) {
|
|
34
|
+
const error = new Error('No gateways provided');
|
|
35
|
+
this.logger.error('Failed to select gateway', { error: error.message });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
this.logger.debug(`Pinging ${gateways.length} gateways with timeout ${this.timeoutMs}ms`, {
|
|
39
|
+
gateways: gateways.map((g) => g.toString()),
|
|
40
|
+
timeoutMs: this.timeoutMs,
|
|
41
|
+
probePath: this.probePath,
|
|
42
|
+
});
|
|
43
|
+
const throttle = pLimit(Math.min(this.maxConcurrency, gateways.length));
|
|
44
|
+
const pingPromises = gateways.map(async (gateway) => {
|
|
45
|
+
return throttle(async () => {
|
|
46
|
+
const pingUrl = `${gateway.toString().replace(/\/$/, '')}${this.probePath}`;
|
|
47
|
+
this.logger.debug(`Pinging gateway ${gateway.toString()}`, {
|
|
48
|
+
gateway: gateway.toString(),
|
|
49
|
+
pingUrl,
|
|
50
|
+
});
|
|
51
|
+
const startTime = Date.now();
|
|
52
|
+
const response = await fetch(pingUrl, {
|
|
53
|
+
method: 'HEAD',
|
|
54
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
55
|
+
});
|
|
56
|
+
if (response.ok) {
|
|
57
|
+
// clear the queue to prevent the next gateway from being pinged
|
|
58
|
+
throttle.clearQueue();
|
|
59
|
+
return { gateway, durationMs: Date.now() - startTime };
|
|
60
|
+
}
|
|
61
|
+
throw new Error('Failed to ping gateway', {
|
|
62
|
+
cause: {
|
|
63
|
+
gateway: gateway.toString(),
|
|
64
|
+
probePath: this.probePath,
|
|
65
|
+
status: response.status,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
const { gateway, durationMs } = await Promise.any(pingPromises);
|
|
71
|
+
this.logger.debug('Successfully selected fastest gateway', {
|
|
72
|
+
gateway: gateway.toString(),
|
|
73
|
+
durationMs,
|
|
74
|
+
});
|
|
75
|
+
return gateway;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
19
|
+
import { Logger } from '../wayfinder.js';
|
|
20
|
+
export declare class PreferredWithFallbackRoutingStrategy implements RoutingStrategy {
|
|
21
|
+
readonly name = "preferred-with-fallback";
|
|
22
|
+
private preferredGateway;
|
|
23
|
+
private fallbackStrategy;
|
|
24
|
+
private logger;
|
|
25
|
+
constructor({ preferredGateway, fallbackStrategy, logger, }: {
|
|
26
|
+
preferredGateway: string;
|
|
27
|
+
fallbackStrategy?: RoutingStrategy;
|
|
28
|
+
logger?: Logger;
|
|
29
|
+
});
|
|
30
|
+
selectGateway({ gateways }: {
|
|
31
|
+
gateways: URL[];
|
|
32
|
+
}): Promise<URL>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=preferred-with-fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preferred-with-fallback.d.ts","sourceRoot":"","sources":["../../src/routing/preferred-with-fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAGxD,qBAAa,oCAAqC,YAAW,eAAe;IAC1E,SAAgB,IAAI,6BAA6B;IACjD,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,gBAAgB,EAChB,gBAAmD,EACnD,MAAsB,GACvB,EAAE;QACD,gBAAgB,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,eAAe,CAAC;QACnC,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAMK,aAAa,CAAC,EAAE,QAAa,EAAE,EAAE;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CAoC1E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defaultLogger } from '../wayfinder.js';
|
|
2
|
+
import { FastestPingRoutingStrategy } from './ping.js';
|
|
3
|
+
export class PreferredWithFallbackRoutingStrategy {
|
|
4
|
+
name = 'preferred-with-fallback';
|
|
5
|
+
preferredGateway;
|
|
6
|
+
fallbackStrategy;
|
|
7
|
+
logger;
|
|
8
|
+
constructor({ preferredGateway, fallbackStrategy = new FastestPingRoutingStrategy(), logger = defaultLogger, }) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.fallbackStrategy = fallbackStrategy;
|
|
11
|
+
this.preferredGateway = new URL(preferredGateway);
|
|
12
|
+
}
|
|
13
|
+
async selectGateway({ gateways = [] }) {
|
|
14
|
+
this.logger.debug('Attempting to connect to preferred gateway', {
|
|
15
|
+
preferredGateway: this.preferredGateway.toString(),
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
// Check if the preferred gateway is responsive
|
|
19
|
+
const response = await fetch(this.preferredGateway.toString(), {
|
|
20
|
+
method: 'HEAD',
|
|
21
|
+
signal: AbortSignal.timeout(1000),
|
|
22
|
+
});
|
|
23
|
+
if (response.ok) {
|
|
24
|
+
this.logger.debug('Successfully connected to preferred gateway', {
|
|
25
|
+
preferredGateway: this.preferredGateway.toString(),
|
|
26
|
+
});
|
|
27
|
+
return this.preferredGateway;
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Preferred gateway responded with status: ${response.status}`);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
this.logger.warn('Failed to connect to preferred gateway, falling back to alternative strategy', {
|
|
33
|
+
preferredGateway: this.preferredGateway.toString(),
|
|
34
|
+
error: error instanceof Error ? error.message : String(error),
|
|
35
|
+
fallbackStrategy: this.fallbackStrategy.constructor.name,
|
|
36
|
+
});
|
|
37
|
+
// Fall back to the provided routing strategy
|
|
38
|
+
return this.fallbackStrategy.selectGateway({ gateways });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
19
|
+
export declare class RandomRoutingStrategy implements RoutingStrategy {
|
|
20
|
+
selectGateway({ gateways }: {
|
|
21
|
+
gateways: URL[];
|
|
22
|
+
}): Promise<URL>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/routing/random.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAG3D,qBAAa,qBAAsB,YAAW,eAAe;IACrD,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,GAAG,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CAMrE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
19
|
+
/**
|
|
20
|
+
* WayFinder
|
|
21
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
22
|
+
*
|
|
23
|
+
* This program is free software: you can redistribute it and/or modify
|
|
24
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
25
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
26
|
+
* (at your option) any later version.
|
|
27
|
+
*
|
|
28
|
+
* This program is distributed in the hope that it will be useful,
|
|
29
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
30
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
31
|
+
* GNU Affero General Public License for more details.
|
|
32
|
+
*
|
|
33
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
34
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
35
|
+
*/
|
|
36
|
+
import { Logger } from '../wayfinder.js';
|
|
37
|
+
export declare class RoundRobinRoutingStrategy implements RoutingStrategy {
|
|
38
|
+
readonly name = "round-robin";
|
|
39
|
+
private gateways;
|
|
40
|
+
private currentIndex;
|
|
41
|
+
private logger;
|
|
42
|
+
constructor({ gateways, logger, }: {
|
|
43
|
+
gateways: URL[];
|
|
44
|
+
logger?: Logger;
|
|
45
|
+
});
|
|
46
|
+
selectGateway({ gateways, }?: {
|
|
47
|
+
gateways?: URL[];
|
|
48
|
+
}): Promise<URL>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=round-robin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round-robin.d.ts","sourceRoot":"","sources":["../../src/routing/round-robin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,yBAA0B,YAAW,eAAe;IAC/D,SAAgB,IAAI,iBAAiB;IACrC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,QAAQ,EACR,MAAsB,GACvB,EAAE;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,aAAa,CAAC,EAClB,QAAa,GACd,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;KACb,GAAG,OAAO,CAAC,GAAG,CAAC;CActB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { defaultLogger } from '../wayfinder.js';
|
|
19
|
+
export class RoundRobinRoutingStrategy {
|
|
20
|
+
name = 'round-robin';
|
|
21
|
+
gateways;
|
|
22
|
+
currentIndex;
|
|
23
|
+
logger;
|
|
24
|
+
constructor({ gateways, logger = defaultLogger, }) {
|
|
25
|
+
this.gateways = gateways;
|
|
26
|
+
this.currentIndex = 0;
|
|
27
|
+
this.logger = logger;
|
|
28
|
+
}
|
|
29
|
+
// provided gateways are ignored
|
|
30
|
+
async selectGateway({ gateways = [], } = {}) {
|
|
31
|
+
if (gateways.length > 0) {
|
|
32
|
+
this.logger.warn('RoundRobinRoutingStrategy does not accept provided gateways. Ignoring provided gateways...', {
|
|
33
|
+
providedGateways: gateways.length,
|
|
34
|
+
internalGateways: this.gateways,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const gateway = this.gateways[this.currentIndex];
|
|
38
|
+
this.currentIndex = (this.currentIndex + 1) % this.gateways.length;
|
|
39
|
+
return gateway;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { RoutingStrategy } from '../../types/wayfinder.js';
|
|
19
|
+
/**
|
|
20
|
+
* WayFinder
|
|
21
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
22
|
+
*
|
|
23
|
+
* This program is free software: you can redistribute it and/or modify
|
|
24
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
25
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
26
|
+
* (at your option) any later version.
|
|
27
|
+
*
|
|
28
|
+
* This program is distributed in the hope that it will be useful,
|
|
29
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
30
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
31
|
+
* GNU Affero General Public License for more details.
|
|
32
|
+
*
|
|
33
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
34
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
35
|
+
*/
|
|
36
|
+
import { Logger } from '../wayfinder.js';
|
|
37
|
+
export declare class StaticRoutingStrategy implements RoutingStrategy {
|
|
38
|
+
readonly name = "static";
|
|
39
|
+
private gateway;
|
|
40
|
+
private logger;
|
|
41
|
+
constructor({ gateway, logger, }: {
|
|
42
|
+
gateway: string;
|
|
43
|
+
logger?: Logger;
|
|
44
|
+
});
|
|
45
|
+
selectGateway({ gateways, }?: {
|
|
46
|
+
gateways?: URL[];
|
|
47
|
+
}): Promise<URL>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=static.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../../src/routing/static.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAExD,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,SAAgB,IAAI,YAAY;IAChC,OAAO,CAAC,OAAO,CAAM;IACrB,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,OAAO,EACP,MAAsB,GACvB,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;IAOK,aAAa,CAAC,EAClB,QAAa,GACd,GAAE;QACD,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;KACb,GAAG,OAAO,CAAC,GAAG,CAAC;CAYtB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
import { defaultLogger } from '../wayfinder.js';
|
|
19
|
+
export class StaticRoutingStrategy {
|
|
20
|
+
name = 'static';
|
|
21
|
+
gateway;
|
|
22
|
+
logger;
|
|
23
|
+
constructor({ gateway, logger = defaultLogger, }) {
|
|
24
|
+
this.logger = logger;
|
|
25
|
+
this.gateway = new URL(gateway);
|
|
26
|
+
}
|
|
27
|
+
// provided gateways are ignored
|
|
28
|
+
async selectGateway({ gateways = [], } = {}) {
|
|
29
|
+
if (gateways.length > 0) {
|
|
30
|
+
this.logger.warn('StaticRoutingStrategy does not accept provided gateways. Ignoring provided gateways...', {
|
|
31
|
+
providedGateways: gateways.length,
|
|
32
|
+
internalGateway: this.gateway,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return this.gateway;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
export declare const arioGatewayHeaders: {
|
|
19
|
+
digest: string;
|
|
20
|
+
verified: string;
|
|
21
|
+
txId: string;
|
|
22
|
+
processId: string;
|
|
23
|
+
dataItemOffset: string;
|
|
24
|
+
dataItemDataOffset: string;
|
|
25
|
+
dataItemSize: string;
|
|
26
|
+
rootTransactionId: string;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=ario.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ario.d.ts","sourceRoot":"","sources":["../../src/utils/ario.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;CAS9B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WayFinder
|
|
3
|
+
* Copyright (C) 2022-2025 Permanent Data Solutions, Inc. All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU Affero General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
export const arioGatewayHeaders = {
|
|
19
|
+
digest: 'x-ar-io-digest',
|
|
20
|
+
verified: 'x-ar-io-verified',
|
|
21
|
+
txId: 'x-arns-resolved-tx-id',
|
|
22
|
+
processId: 'x-arns-resolved-process-id',
|
|
23
|
+
dataItemOffset: 'x-ar-io-data-item-offset',
|
|
24
|
+
dataItemDataOffset: 'x-ar-io-data-item-data-offset',
|
|
25
|
+
dataItemSize: 'x-ar-io-data-item-size',
|
|
26
|
+
rootTransactionId: 'x-ar-io-root-transaction-id',
|
|
27
|
+
};
|