-
Notifications
You must be signed in to change notification settings - Fork 191
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
Per topic validation #56
Comments
/cc @whyrusleeping thoughts? |
Note: if we want to do this on a per-subscription basis, we'd probably want to forward messages that validate against at least one of the validators ("or", not "and"). We'd also probably want to deduplicate duplicate validators (store them in a set). |
I think the simplest possible interface is to support direct registration per topic: type Validator func(ctx context.Context, msg *Message) bool // this could be error for reversed semantics
func (p *PubSub) registerValidator(topic string, val Validator) I don't like the idea of having a complex validator interface that we have to query to find topic association, let's just keep it a function. |
One thing I don't like with per-topic validation, compared to per subscription validation, is that we have to make two api calls in order to have validation: first to register the validator, and then to subscribe. There is also the issue of multiple registered validators that we have with the per subscription interface; we still have to make a decision on whether to broadcast a message or not based on all the validators which suffers with the same semantics problem of per subscription validators -- do we accept a message based on a conjunction or a disjunction of validator outputs? Perhaps we should only allow a single validator per topic. |
One final point: as @Stebalien suggests, we can keep per subscription validators but make the decision to broadcast based on the disjunction of validator output. We'd have to be careful to dispatch only to subscriptions for which the validator succeeded though. |
Only with the "register a validator per topic approach". The other approach of registering global validators doesn't have this limitation (you register a validator up-front for the topic family).
If multiple validators want to validate a message, we should take the and. Note: we could also just require that all topics have a namespace prefix. I'd actually prefer this. Then, we'd register one validator per namespace. This would be consistent with the DHT.
My one worry with this approach is that peers may end up disagreeing on what messages are valid on a topic. In that case, we effectively have different topics. It also means that we can't disconnect from peers that send us many bad messages (assuming they're spamming us). We'd be able to determine if a message is valid but not if the message is definitely invalid. |
that's a big plus -- and we can ship validators for well known channels in the future.
That's what we do with the per subscription based validator (it's effectively a
It makes sense to do this for well known or ipfs-the-daemon-used channels, but I don't want to restrict userland.
Agreed, and that's a really big issue. So we can throw away the validator disjunction idea already. |
That reasoning only makes sense when registering per-topic validators. When validation is a property of the topic, I'd expect all the validators to pass. However, when validation is a property of the subscription, I wouldn't expect the subscriptions to interfere with each other.
In that case, I'd also throw away the concept of validators as a property of the subscription. |
In #55, validation is per-subscription. Unfortunately, this means:
Really, validation is a property of the topic, not the subscription. Eventually, I'd like to be able to tell pubsub to relay a topic without explicitly subscribing (#28).
In terms of implementation, we have a few choices:
2 is probably the easiest but not the cleanest. Possible interface:
The text was updated successfully, but these errors were encountered: