holepunchto / hyperdrive

Hyperdrive is a secure, real time distributed file system
Apache License 2.0
1.86k stars 135 forks source link

Update event not firing. #284

Closed RangerMauve closed 4 years ago

RangerMauve commented 4 years ago

Hey, I was posting about this on discord before but I just verified it with a test repo.

It looks like the update event in hyperdrive isn't firing. My gut feeling was that it's got something to do with the append event not firing on the metadata feed on peers when there's new blocks that we didn't download, but I'm not sure.

Here's a reproducible case for the issue: https://github.com/RangerMauve/hyperdrive-update-test

const hyperdrive = require('hyperdrive')
const RAM = require('random-access-memory')

const writer = hyperdrive(RAM)

const WRITE_DELAY = 1000

writer.ready(() => {
  const reader = hyperdrive(RAM, writer.key)

  function write () {
    writer.writeFile('/example.txt', `${new Date()}: Hello World!`, () => console.log('wrote'))
  }

  reader.on('update', () => console.log('update'))
  writer.once('peer-open', () => setInterval(write, WRITE_DELAY))

  reader.ready(() => {
    const stream1 = writer.replicate(true, { live: true })
    const stream2 = reader.replicate(false, { live: true })

    stream1.pipe(stream2).pipe(stream1)
  })
})

When I run this, I see a single update at the beginning, then a series of wrote events without corresponding update events.

Am I maybe misconfiguring something?

mafintosh commented 4 years ago

You are not reading any file so no update is fetched except for the initial one that loads the content feed

RangerMauve commented 4 years ago

Ah, so the update event doesn't happen unless I read files? I guess I've misunderstood what the update event does. Is there no event to react to when files have changed remotely?

RangerMauve commented 4 years ago

Oh cool. Thank you for the clarification. I guess the thing I really needed here was the watch API. 😁