helia-coord 1.5.4 → 1.5.6
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/lib/adapters/gist.js
CHANGED
|
@@ -8,7 +8,12 @@ import axios from 'axios'
|
|
|
8
8
|
|
|
9
9
|
class Gist {
|
|
10
10
|
constructor (localConfig = {}) {
|
|
11
|
+
// Encapsulate dependencies
|
|
11
12
|
this.axios = axios
|
|
13
|
+
|
|
14
|
+
// Bind 'this' object to all subfunctions
|
|
15
|
+
this.getCRList = this.getCRList.bind(this)
|
|
16
|
+
this.getCRList2 = this.getCRList2.bind(this)
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
// Retrieve a JSON file from a GitHub Gist
|
|
@@ -46,6 +51,43 @@ class Gist {
|
|
|
46
51
|
throw err
|
|
47
52
|
}
|
|
48
53
|
}
|
|
54
|
+
|
|
55
|
+
// Retrieve a JSON file from bootstrap.psfoundation.info
|
|
56
|
+
async getCRList2 () {
|
|
57
|
+
try {
|
|
58
|
+
// Public CRs
|
|
59
|
+
// https://gist.github.com/christroutner/048ea1a4b635a055c6bb63d48c373806
|
|
60
|
+
const gistUrl =
|
|
61
|
+
'https://bootstrap.psfoundation.info/bootstrap.json'
|
|
62
|
+
|
|
63
|
+
// Retrieve the gist from github.com.
|
|
64
|
+
const result = await this.axios.get(gistUrl)
|
|
65
|
+
console.log('result.data: ', result.data)
|
|
66
|
+
|
|
67
|
+
// Get the current content of the gist.
|
|
68
|
+
const content = result.data
|
|
69
|
+
// console.log('content: ', content)
|
|
70
|
+
|
|
71
|
+
// Parse the JSON string into an Object.
|
|
72
|
+
// const object = JSON.parse(content)
|
|
73
|
+
const object = content
|
|
74
|
+
// console.log('object: ', object)
|
|
75
|
+
|
|
76
|
+
// Keep the linter happy.
|
|
77
|
+
const nullFunc = () => {}
|
|
78
|
+
nullFunc(object)
|
|
79
|
+
|
|
80
|
+
// return object
|
|
81
|
+
return object
|
|
82
|
+
// return {
|
|
83
|
+
// browser: [],
|
|
84
|
+
// node: []
|
|
85
|
+
// }
|
|
86
|
+
} catch (err) {
|
|
87
|
+
console.error('Error attempting to download GitHub Gist of alternative servers.')
|
|
88
|
+
throw err
|
|
89
|
+
}
|
|
90
|
+
}
|
|
49
91
|
}
|
|
50
92
|
|
|
51
93
|
export default Gist
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
- addRelay() - Add a new relay to the state.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
// Global npm libraries
|
|
10
|
+
import RetryQueue from '@chris.troutner/retry-queue'
|
|
11
|
+
|
|
9
12
|
// Local libraries
|
|
10
13
|
import globalConfig from '../../config/global-config.js'
|
|
11
14
|
|
|
@@ -22,6 +25,12 @@ class RelayUseCases {
|
|
|
22
25
|
// Encapsulate dependencies
|
|
23
26
|
this.config = globalConfig
|
|
24
27
|
|
|
28
|
+
this.retryQueue = new RetryQueue({
|
|
29
|
+
concurrency: 1,
|
|
30
|
+
attempts: 5,
|
|
31
|
+
retryPeriod: 1000
|
|
32
|
+
})
|
|
33
|
+
|
|
25
34
|
// Initialize v1 relay list. Allows user to overwrite with local config.
|
|
26
35
|
this.bootstrapRelays = []
|
|
27
36
|
if (localConfig.bootstrapRelays) {
|
|
@@ -57,7 +66,8 @@ class RelayUseCases {
|
|
|
57
66
|
// to all of the ones in the list.
|
|
58
67
|
async getCRGist (thisNode) {
|
|
59
68
|
try {
|
|
60
|
-
const gistCRs = await this.adapters.gist.
|
|
69
|
+
// const gistCRs = await this.adapters.gist.getCRList2()
|
|
70
|
+
const gistCRs = await this.retryQueue.addToQueue(this.adapters.gist.getCRList2, {})
|
|
61
71
|
|
|
62
72
|
let gistRelays
|
|
63
73
|
if (thisNode.type === 'browser') {
|
package/package.json
CHANGED
|
@@ -76,7 +76,7 @@ describe('#relay-Use-Cases', () => {
|
|
|
76
76
|
}],
|
|
77
77
|
recommendedPeers: []
|
|
78
78
|
}
|
|
79
|
-
sandbox.stub(uut.adapters.gist, '
|
|
79
|
+
sandbox.stub(uut.adapters.gist, 'getCRList2').resolves(data)
|
|
80
80
|
sandbox.stub(uut, 'removeDuplicates').resolves()
|
|
81
81
|
|
|
82
82
|
const result = await uut.getCRGist(thisNode)
|
|
@@ -100,7 +100,7 @@ describe('#relay-Use-Cases', () => {
|
|
|
100
100
|
node: [],
|
|
101
101
|
recommendedPeers: []
|
|
102
102
|
}
|
|
103
|
-
sandbox.stub(uut.adapters.gist, '
|
|
103
|
+
sandbox.stub(uut.adapters.gist, 'getCRList2').resolves(data)
|
|
104
104
|
sandbox.stub(uut, 'removeDuplicates').resolves()
|
|
105
105
|
|
|
106
106
|
const result = await uut.getCRGist(thisNode)
|
|
@@ -117,7 +117,7 @@ describe('#relay-Use-Cases', () => {
|
|
|
117
117
|
ipfsId: '123'
|
|
118
118
|
}]
|
|
119
119
|
}
|
|
120
|
-
sandbox.stub(uut.adapters.gist, '
|
|
120
|
+
sandbox.stub(uut.adapters.gist, 'getCRList2').resolves(data)
|
|
121
121
|
sandbox.stub(uut, 'removeDuplicates').resolves()
|
|
122
122
|
|
|
123
123
|
const result = await uut.getCRGist(thisNode)
|
|
@@ -128,7 +128,8 @@ describe('#relay-Use-Cases', () => {
|
|
|
128
128
|
it('should catch and throw errors', async () => {
|
|
129
129
|
try {
|
|
130
130
|
// Force desired code path.
|
|
131
|
-
sandbox.stub(uut.adapters.gist, '
|
|
131
|
+
// sandbox.stub(uut.adapters.gist, 'getCRList2').rejects(new Error('test error'))
|
|
132
|
+
sandbox.stub(uut.retryQueue, 'addToQueue').rejects(new Error('test error'))
|
|
132
133
|
|
|
133
134
|
await uut.getCRGist()
|
|
134
135
|
|