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

Add syncPolicy callback for per-document authorization #350

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

max-dekock
Copy link

This PR adds a syncPolicy callback to the repo configuration. It will be called whenever a sync message is received from a peer, and if it returns false, syncing will be blocked, and the repo will respond with a doc-unavailable message.

Currently, if sharePolicy returns true, the repo will still send sync messages to peers even if syncPolicy would return false. If this is undesirable, another possibility is to only share if syncPolicy and sharePolicy both return true.

@@ -85,6 +85,18 @@ export class CollectionSynchronizer extends Synchronizer {
)

const documentId = message.documentId
const senderId = message.senderId
const okToSync = await this.repo.syncPolicy(senderId, documentId)
Copy link

@twop twop Jun 9, 2024

Choose a reason for hiding this comment

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

was casually observing Discord and took a look at the PR, hence pardon my intrusion, just wanted to mention that await somePromise will always put a new event into the event loop at the very end, thus even an innocent no-op (like async () => true) can create a lot of latency if the event loop is busy/saturated. So it is possible that it might be better to make it optional and thus not awaiting as the default behavior.

@pvh pvh force-pushed the main branch 2 times, most recently from e61f8e3 to d3d1a7d Compare July 26, 2024 20:13
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.

2 participants