Skip to content
Snippets Groups Projects
Commit 11bcac4c authored by Michał "rysiek" Woźniak's avatar Michał "rysiek" Woźniak :lock:
Browse files

configurable concurrency in the gateway-ipns plugin

parent 79665ebd
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,12 @@
'https://ipfs.sloppyta.co/ipns/', // UK
'https://gateway.temporal.cloud/ipns/', // Germany
'https://ipfs.best-practice.se/ipns/' // Sweden
]
],
// how many simultaneous connections to gateways we want
// more concurrency means higher chance of a request succeeding
// but uses morebandwidth and other resources;
// 3 seems a reasonable default
concurrency: 3
}
// merge the defaults with settings from SamizdatConfig
......@@ -55,15 +60,16 @@
// https://<gateway_address>/<pubkey>/<rest_of_URL>
var ipnsUrl = config.ipnsPubkey + url.replace(/https?:\/\/[^/]+/, '')
// pick 3 gateways, at random
// we don't want to modify the original gateways array
var sourceGateways = [...config.ipfsGateways]
// if we have fewer than 3 gateways configured, use all of them
if (sourceGateways.length <= 3) {
// if we have fewer than the configured concurrency, use all of them
if (sourceGateways.length <= config.concurrency) {
var useGateways = sourceGateways
// otherwise get 3 at random
// otherwise get `config.concurrency` gateways at random
} else {
var useGateways = new Array()
while (useGateways.length < 3) {
while (useGateways.length < config.concurrency) {
// put in the address while we're at it
useGateways.push(
sourceGateways
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment