Commit 8b3dd7e5 authored by Michał "rysiek" Woźniak's avatar Michał "rysiek" Woźniak 🔒

gateway-ipns bugfix: gateways are now correctly randomized from the...

gateway-ipns bugfix: gateways are now correctly randomized from the pre-configured list, without affecting the list itself
parent f64c40f3
Pipeline #46247 failed with stage
in 60 minutes
......@@ -52,19 +52,27 @@ Promise.any = async (promises) => {
*/
let fetchContentFromGatewayIPNS = (url) => {
console.log(`Samizdat: pre-configured gateways:\n ${gateways.join('\n ')}`)
// we're going to try a random gateway and building an URL of the form:
// https://<gateway_address>/<ipnsPubkey>/<rest_of_URL>
var ipnsUrl = ipnsPubKey + url.replace(/https?:\/\/[^/]+/, '')
// pick 3 gateways, at random
var useGateways = new Array()
while (useGateways.length < 3) {
// put in the address while we're at it
useGateways.push(
gateways
.splice(Math.floor(Math.random() * gateways.length), 1)[0] + ipnsUrl
)
var sourceGateways = [...gateways]
// if we have fewer than 3 gateways configured, use all of them
if (sourceGateways.length <= 3) {
var useGateways = sourceGateways
// otherwise get 3 at random
} else {
var useGateways = new Array()
while (useGateways.length < 3) {
// put in the address while we're at it
useGateways.push(
sourceGateways
.splice(Math.floor(Math.random() * sourceGateways.length), 1)[0] + ipnsUrl
)
}
}
// debug log
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment