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

implement instant replies #24

Open
estebanabaroa opened this issue Dec 14, 2023 · 3 comments
Open

implement instant replies #24

estebanabaroa opened this issue Dec 14, 2023 · 3 comments

Comments

@estebanabaroa
Copy link
Member

estebanabaroa commented Dec 14, 2023

steps to get instant replies:

assuming the user calls plebbit.createComment({pubsub: true, cid: 'Qm...'}) and comment.update()

join pubsub /last-reply/Qm...

  • fetch key /last-reply/Qm... using libp2p fetch protocol

the value received is (all peers must store the last answer they have and answer the fetch protocol with it)

CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number (first reply is 0, last reply is the previous children count)
}

validate the sub comment update signature

the last reply has the highest reply.sequenceNumber (property added by sub owner)

whenever the last reply changes, download all the replies you don't yet have by scrolling reply.previousCid

emit comment 'update' event by adding the new replies to the comment.replies

for as long as the user is joined to the pubsub, keep listening for new replies and emitting updates. possibly implement comment.pubsubStop() or just use comment.stop() which already exists to leave the pubsub.

TODO: eventually think of how we would consolidate page cids with the comment.replies, maybe we have an array comment.newReplies or something for new replies

steps to publish instant replies:

assuming the user calls plebbit.createComment({pubsub: true, parentCid: 'Qm...'}) and comment.publish()

publish comment normally, and wait for challenge verification. challenge verifications must contain challengeVerificationMessage.publication.update:

CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number
}

join pubsub /last-reply/Qm...

  • fetch key /last-reply/Qm... using libp2p fetch protocol
    if sequenceNumber is lower than your sequence number, publish your own comment update received from the sub owner
CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number
}

spam mitigation

random people can't spam because all the comment updates are signed by the sub owner and have a sequence number, so not signed or duplicate comments can be ignored/blocked from the pubsub

@Rinse12
Copy link
Member

Rinse12 commented Jan 3, 2024

Are we able to implement this at the moment or do we need to modify Kubo?

@estebanabaroa
Copy link
Member Author

estebanabaroa commented Jan 3, 2024

Are we able to implement this at the moment or do we need to modify Kubo?

I believe we would implement this in javascript only for now, because writing it in go would be pretty complicated, and most people use the browser/mobile version anyway.

I wrote an example of how to use the fetch protocol here to add persistence to ipns over pubsub (@helia/ipns doesnt have it yet) https://github.com/estebanabaroa/custom-pubsub/blob/master/demo3.js

It works but I wasn't able to make it interoperate with kubo, so I might be doing something wrong. I will write a more direct example of how we would use pubsub and the fetch protocol when I have time, so you could wait for that to start working on it.

I think instant replies is fairly high priority to get a prototype working though, so that plebchan can work more like 4chan. We should work on it soon imo.

@estebanabaroa
Copy link
Member Author

estebanabaroa commented Aug 31, 2024

the value received is (all peers must store the last answer they have and answer the fetch protocol with it)

CommentUpdate {
  cid: string
  signature: Signature
  sequenceNumber: number (first reply is 0, last reply is the previous children count)
}

we probably actually want to send the full {comment, update} similar to PageComment type of the protocol, this way peers dont have to fetch the comment from IPFS, though peers probably want to add the comment to IPFS when they receive it, so they can seed it, for people who join the pubsub late and haven't received all the comments.

which means

challenge verifications must contain challengeVerificationMessage.publication.update:

challengeVerificationMessage should probably be something like challengeVerificationMessage.comment and challengeVerificationMessage.commentUpdate

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