Open robertkowalski opened 5 years ago
my first noise server! :)
noise-network returns a noise stream on connect(), but it crashes when i do not use nextTick
connect()
first guess: probably we need one inside noise-peer to fix the issue.
server.js
'use strict' const noise = require('noise-network') const server = noise.createServer() const stream = require('stream') const hypercore = require('hypercore') const { write } = require('length-prefixed-message') const stats = require('./stats') const feed = hypercore(`./test`) server.on('connection', function (encryptedStream) { write(encryptedStream, JSON.stringify({ key: feed.key.toString('hex') })) stream.pipeline( encryptedStream, feed.replicate({ live: true }), encryptedStream, (err) => { console.log('replication ended', err) } ) }) const keyPair = noise.seedKeygen(Buffer.alloc(32, 'secret')) server.listen(keyPair, function () { console.log('Server is listening on:', server.publicKey.toString('hex')) })
client.js
const client = noise.connect('a9a5544b217d38cc0165d3fce9381e38464025d26d1e7e38c4ce4a729e73410b') // when no process.nextTick is used, client crashes // process.nextTick(function () { read(client, (msg) => { msg = msg.toString() const p = JSON.parse(msg) const feed = hypercore(`./client-dbs/local-${testGroup}-${id}`, p.key) stream.pipeline( client, feed.replicate({ live: true }), client, (err) => { console.log('replication ended', err) } ) }) // })
This was fixed here: https://github.com/emilbayes/noise-peer/commit/f4c573c508cecdba092467427d9fc75d65bb5b60 but it is missing tests and update to noise-network
my first noise server! :)
noise-network returns a noise stream on
connect()
, but it crashes when i do not use nextTickfirst guess: probably we need one inside noise-peer to fix the issue.
server.js
client.js