| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.DHT.Validator
Description
Record validation for the Kademlia DHT.
Per specs/kad-dht (Entry validation), records must be validated on two occasions: values retrieved in a GET_VALUE query and values received in a PUT_VALUE query before storing them locally.
Record keys have the form namespacepath; validation dispatches on
the namespace, mirroring go-libp2p's record.NamespacedValidator.
The built-in pk validator binds the key to the value: the path
must be the multihash (Peer ID) of the serialized public key carried
in the value.
Synopsis
- data Validator = Validator {
- valValidate :: ByteString -> ByteString -> Either String ()
- valSelect :: ByteString -> [ByteString] -> Either String Int
- namespacedValidator :: Map ByteString Validator -> Validator
- pkValidator :: Validator
- defaultValidator :: Validator
- splitRecordKey :: ByteString -> Either String (ByteString, ByteString)
Validator interface
Validator interface for record validation.
valValidate checks that a value is well-formed for its key and
returns an error for records that must not be stored or served.
valSelect picks the index of the best value among conflicting
candidates for the same key (used for GET_VALUE conflict resolution).
Constructors
| Validator | |
Fields
| |
Built-in validators
namespacedValidator :: Map ByteString Validator -> Validator Source #
Dispatch validation by key namespace. Keys without a registered namespace are rejected, matching go-libp2p's namespaced validator ("invalid record keytype").
pkValidator :: Validator Source #
Validator for the pk namespace: the value must be a serialized
PublicKey protobuf whose derived Peer ID equals the multihash in the
key path. Public keys never conflict, so valSelect keeps the first
candidate (go-libp2p's record.PublicKeyValidator does the same).
defaultValidator :: Validator Source #
The default validator set: pk records only. Additional
namespaces can be registered by building a custom
namespacedValidator and storing it in the DHT node.
Key helpers
splitRecordKey :: ByteString -> Either String (ByteString, ByteString) Source #
Split a record key of the form namespacepath into
(namespace, path). The path is raw bytes (for pk it is a binary
multihash), so only the two leading separators are interpreted.