-
Notifications
You must be signed in to change notification settings - Fork 8
/
local-transfer.js
55 lines (50 loc) · 1.78 KB
/
local-transfer.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
'use strict'
const fs = require('fs')
const { file } = require('./lib/fixtures.js')
const { build } = require('./schema/results')
const run = require('./lib/runner')
const { once } = require('stream-iterators-utils')
const { description } = require('./config').parseParams()
/**
* Cat file between two peers using catReadableStream.
* js0 -> js1 - A test between two JS IPFS nodes
* @async
* @function localTransfer
* @param {array} peerArray - An array of IPFS peers used during the test.
* @param {string} name - Name of the test used as sending results to the file with same name and data point in dashboard.
* @param {boolean} warmup - Not implemented.
* @param {string} fileSet - Describes file or list of files used for the test.
* @param {string} version - Version of IPFS used in benchmark.
* @return {Promise<Object>} The data from the benchamrk
*/
const localTransfer = async (peerArray, name, warmup, fileSet, version) => {
const filePath = await file(fileSet)
const fileStream = fs.createReadStream(filePath)
const peerA = peerArray[0]
const peerB = peerArray[1]
const peerAId = await peerA.id()
peerB.swarm.connect(peerAId.addresses[0])
const inserted = await peerA.add(fileStream)
const start = process.hrtime()
let stream = peerB.catReadableStream(inserted[0].hash)
// endof steam
stream.resume()
// we cannot use end-of-stream/pump for some reason here
// investigate.
// https://github.com/ipfs/js-ipfs/issues/1774
await once(stream, 'end')
const end = process.hrtime(start)
return build({
name: name,
warmup: warmup,
file_set: fileSet,
file: filePath,
meta: { version: version },
description: `Cat file ${description} js0 -> js1`,
duration: {
s: end[0],
ms: end[1] / 1000000
}
})
}
run(localTransfer, 3)