Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit ae8fd30

Browse files
committed
feat: pinpoint
1 parent 64080b4 commit ae8fd30

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"progress": "^2.0.1",
151151
"promisify-es6": "^1.0.3",
152152
"pull-abortable": "^4.1.1",
153+
"pull-catch": "^1.0.0",
153154
"pull-defer": "~0.2.3",
154155
"pull-file": "^1.1.0",
155156
"pull-ndjson": "~0.1.1",

src/core/components/ping-pull-stream.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ module.exports = function pingPullStream (self) {
2222
getPeer(self._libp2pNode, source, peerId, (err, peer) => {
2323
if (err) {
2424
log.error(err)
25-
source.push(err)
26-
source.end()
25+
source.end(err)
2726
return
2827
}
2928

src/http/api/resources/ping.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Joi = require('joi')
44
const pull = require('pull-stream')
5+
const pullatch = require('pull-catch')
56
const toStream = require('pull-stream-to-stream')
67
const ndjson = require('pull-ndjson')
78
const PassThrough = require('readable-stream').PassThrough
@@ -23,9 +24,19 @@ exports.get = {
2324
handler: (request, reply) => {
2425
const ipfs = request.server.app.ipfs
2526
const peerId = request.query.arg
27+
2628
// Default count to 10
2729
const count = request.query.n || request.query.count || 10
2830

31+
// Streams from pull-stream-to-stream don't seem to be compatible
32+
// with the stream2 readable interface
33+
// see: https://github.com/hapijs/hapi/blob/c23070a3de1b328876d5e64e679a147fafb04b38/lib/response.js#L533
34+
// and: https://github.com/pull-stream/pull-stream-to-stream/blob/e436acee18b71af8e71d1b5d32eee642351517c7/index.js#L28
35+
36+
// TODO: here lies the issue
37+
// The fact that ping can fail after it starts writting some success ndjson
38+
// responses is not very friendly to how Hapi expects this stream to work
39+
// This multiple stream transformation and stiching is a nightmare
2940
const source = pull(
3041
ipfs.pingPullStream(peerId, { count: count }),
3142
pull.map((chunk) => ({
@@ -36,10 +47,6 @@ exports.get = {
3647
ndjson.serialize()
3748
)
3849

39-
// Streams from pull-stream-to-stream don't seem to be compatible
40-
// with the stream2 readable interface
41-
// see: https://github.com/hapijs/hapi/blob/c23070a3de1b328876d5e64e679a147fafb04b38/lib/response.js#L533
42-
// and: https://github.com/pull-stream/pull-stream-to-stream/blob/e436acee18b71af8e71d1b5d32eee642351517c7/index.js#L28
4350
const responseStream = toStream.source(source)
4451
const stream2 = new PassThrough()
4552
pump(responseStream, stream2)

0 commit comments

Comments
 (0)