-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual-check.js
57 lines (52 loc) · 2.13 KB
/
manual-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Usage:
// zinnia run manual-check.js
//
import Spark, { getRetrievalUrl } from './lib/spark.js'
import { getMinerPeerId as defaultGetMinerPeerId } from './lib/miner-info.js'
// The task to check, replace with your own values
const task = {
cid: 'bafkreih25dih6ug3xtj73vswccw423b56ilrwmnos4cbwhrceudopdp5sq',
minerId: 'f0frisbii'
}
const getMinerPeerId = (minerId) =>
minerId === 'f0frisbii'
? '12D3KooWC8gXxg9LoJ9h3hy3jzBkEAxamyHEQJKtRmAuBuvoMzpr'
: defaultGetMinerPeerId(minerId)
// Run the check
const spark = new Spark({ getMinerPeerId })
const stats = { ...task, indexerResult: null, statusCode: null, byteLength: 0 }
await spark.executeRetrievalCheck(task, stats)
console.log('Measurement: %o', stats)
if (stats.providerAddress && stats.statusCode !== 200) {
console.log('\nThe retrieval failed.')
switch (stats.protocol) {
case 'graphsync':
console.log('You can get more details by running Lassie manually:\n')
console.log(
' lassie fetch -o /dev/null -vv --dag-scope block --protocols graphsync --providers %s %s',
JSON.stringify(stats.providerAddress),
task.cid
)
console.log('\nHow to install Lassie: https://github.com/filecoin-project/lassie?tab=readme-ov-file#installation')
break
case 'http':
try {
const url = getRetrievalUrl(stats.protocol, stats.providerAddress, task.cid)
console.log('You can get more details by requesting the following URL yourself:\n')
console.log(' %s', url)
console.log('\nE.g. using `curl`:')
console.log(' curl -i %s', JSON.stringify(url))
console.log('\nYou can also test the retrieval using Lassie:\n')
console.log(
' lassie fetch -o /dev/null -vv --dag-scope block --protocols http --providers %s %s',
JSON.stringify(stats.providerAddress),
task.cid
)
console.log('\nHow to install Lassie: https://github.com/filecoin-project/lassie?tab=readme-ov-file#installation')
} catch (err) {
console.log('The provider address %j cannot be converted to a URL: %s', stats.providerAddress, err.message ?? err)
}
break
}
}