Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client crashes when no next tick set #5

Open
robertkowalski opened this issue Nov 23, 2018 · 1 comment
Open

client crashes when no next tick set #5

robertkowalski opened this issue Nov 23, 2018 · 1 comment

Comments

@robertkowalski
Copy link

robertkowalski commented Nov 23, 2018

my first noise server! :)

noise-network returns a noise stream on connect(), but it crashes when i do not use nextTick

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)
        }
      )
    })
 // })
@emilbayes
Copy link
Owner

This was fixed here: f4c573c but it is missing tests and update to noise-network

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants