Skip to content

Commit

Permalink
Merge pull request #150 from libp2p/fix/pubsub-validators
Browse files Browse the repository at this point in the history
pubsub: specify validator functions
  • Loading branch information
vyzo authored Feb 26, 2019
2 parents ec04297 + dfbc18c commit 15038be
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pubsub/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ For signing purposes, the `signature` and `key` fields are used:
The signature is computed over the marshalled message protobuf _excluding_ the key field.
The protobuf blob is prefixed by the string `libp2p-pubsub:` before signing.

When signature validation fails for a signed message, the implementation must
drop the message and omit propagation. Locally, it may treat this event in whichever
manner it wishes (e.g. logging).

## The Topic Descriptor

The topic descriptor message is used to define various options and parameters
Expand Down Expand Up @@ -226,3 +230,18 @@ Web Of Trust publishing. Messages are encrypted with some certificate or
certificate chain shared amongst trusted peers. (Spec writer's note: this is the
least clearly defined option and my description here may be wildly incorrect,
needs checking).

## Topic Validation

Implementations MUST support attaching _validators_ to topics.

_Validators_ have access to the `Message` and can apply any logic to determine its validity.
When propagating a message for a topic, implementations will invoke all validators attached
to that topic, and will only continue propagation if, and only if all, validations pass.

In its simplest form, a _validator_ is a function with signature `(peer.ID, *Message) => bool`,
where the return value is `true` if validation passes, and `false` otherwise.

Local handling of failed validation is left up to the implementation (e.g. logging).

Implementations MAY allow dynamically adding and removing _validators_ at runtime.

0 comments on commit 15038be

Please sign in to comment.