Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libre
Samizdat
Commits
11bcac4c
Commit
11bcac4c
authored
Oct 03, 2020
by
Michał Woźniak
Browse files
configurable concurrency in the gateway-ipns plugin
parent
79665ebd
Changes
1
Hide whitespace changes
Inline
Side-by-side
plugins/gateway-ipns.js
View file @
11bcac4c
...
...
@@ -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
,
a
t random
//
we don't want to modify the original
gateways a
rray
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment