Skip to content

Commit

Permalink
Merge pull request #72 from AudiusProject/jowlee-updateBuild-script
Browse files Browse the repository at this point in the history
Update script to peer IPFS in CI
  • Loading branch information
jowlee committed Mar 5, 2021
1 parent ed445e5 commit 9a29c46
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/protocol-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@types/react-virtualized": "^9.21.10",
"@types/semver": "^6.2.1",
"@types/url-join": "^4.0.0",
"abort-controller": "^3.0.0",
"env-cmd": "^9.0.3",
"node-fetch": "^2.6.1",
"prettier": "^1.19.1",
Expand Down
38 changes: 33 additions & 5 deletions packages/protocol-dashboard/scripts/updateBuild.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs')
const fetch = require('node-fetch')
const AbortController = require('abort-controller')

const args = process.argv
console.log(process.argv)
Expand Down Expand Up @@ -30,15 +31,42 @@ const config = {

const endpoint = config[env].gaEndpoint

const CONTENT_NODE_PEER_TIMEOUT = 1000 /* ms */ * 30 /* sec */

const updateContentNodePeers = async () => {
const res = await fetch(`${endpoint}/protocol_dashboard/peer_content_nodes`)
const response = await res.json()
console.log({ response })
if (!response.success) {
console.error('unable to update content node ipfs peers')
const contentNodesRes = await fetch(`${endpoint}/protocol_dashboard/content_nodes`)
const contentNodes = await contentNodesRes.json()
const ipfsRes = await fetch(`${endpoint}/protocol_dashboard/ipfs`)
const ipfsId = await ipfsRes.json()
const addr = ipfsId.addresses[0]
const connections = {}
for (let cn of contentNodes) {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), CONTENT_NODE_PEER_TIMEOUT)
try {
// make a req to each CN /ipfs_peer_info with url query caller_ipfs_id
const response = await fetch(
`${cn.endpoint}/ipfs_peer_info?caller_ipfs_id=${encodeURIComponent(addr)}`,
{ signal: controller.signal }
)
const responseJson = await response.json()
if (responseJson.data && responseJson.data.id) {
connections[cn.endpoint] = true
} else {
connections[cn.endpoint] = false
}
} catch (error) {
connections[cn.endpoint] = false
} finally {
clearTimeout(timeout)
}
}
if (Object.values(connections).every((isConnected) => !isConnected)) {
console.error('unable to update peer with a single ipfs content node')
process.exit(1)
}
console.log('Added ipfs peers')
console.log(JSON.stringify(connections, null, ' '))
}

const updateGABuild = async () => {
Expand Down

0 comments on commit 9a29c46

Please sign in to comment.