Skip to content

Conversation

@utanapishtim
Copy link

@utanapishtim utanapishtim commented Apr 8, 2023

This pull request captures the work required to firewall peers on replication, effectively re-implements #291 for v10.

It works by:

  1. waiting for the noiseStream to connect
  2. authenticating the peer
  3. attaching the mux and session to the replicator

This allows for finer-grained firewalling of individual hypercores, it mirrors the hyperdht firewall api.

open questions

  • Does mux need to be corked before and uncorked after firewalling? No.
  • Is this the right api?

open work

  • update the README if the api looks right
  • update Corestore to support a firewall option

@utanapishtim utanapishtim changed the title enables firewalling peers on replication enables firewalling replication on a per-peer basis Apr 8, 2023
index.js Outdated
this.replicator.attachTo(mux, session)

const maybeAttach = (allow) => {
if (!allow) return mux.destroy()
Copy link
Author

@utanapishtim utanapishtim Apr 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafintosh I don't think this is correct. Suppose someone passes replicate a Protomux instance, should we really destroy if replication is firewalled? What if they are running other protocols on the mux instance? It would be nice to signal firewalling a bit more responsibly. If we noop, the caller has no indication that replication has been firewalled. We can't throw because the chain of methods is sync and throwing is ugly, no need to panic on getting firewalled. We could emit a firewalled event or error on mux.stream...that's the best I can come up with right now. Some guidance would be appreciated.

@utanapishtim
Copy link
Author

utanapishtim commented Apr 10, 2023

Updated so a user can set or pass down an onfirewalled hook that gets called if firewall returns false for a given remotePublicKey on the noise stream backing a mux instance, the firewalled mux instance and the core itself are passed to the hook. The user could choose to destroy the mux instance or send some message to the peer on the other side of the stream.


mux.stream.noiseStream.opened.then(() => {
const { remotePublicKey } = mux.stream.noiseStream
opts.firewall(remotePublicKey, this).then(maybeAttach, mux.destroy.bind(mux))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are unable to successfully return a firewall verdict, it feels right to panic on the mux and destroy.

this.wait = opts.wait !== false
this.timeout = opts.timeout || 0
this.firewall = opts.firewall || null
this.onfirewalled = opts.onfirewalled || noop
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the default implementation be (mux) => mux.destroy()?

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

Successfully merging this pull request may close these issues.

1 participant