mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Move libp2pvalidator into p2pdendrite
This commit is contained in:
parent
906cda94d3
commit
6291732ec4
|
|
@ -1,24 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-core/peerstore"
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
)
|
||||
|
||||
type LibP2PValidator struct {
|
||||
KeyBook pstore.KeyBook
|
||||
}
|
||||
|
||||
func (v LibP2PValidator) Validate(key string, value []byte) error {
|
||||
ns, _, err := record.SplitKey(key)
|
||||
if err != nil || ns != "matrix" {
|
||||
return errors.New("not Matrix path")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v LibP2PValidator) Select(k string, vals [][]byte) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
@ -18,6 +18,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"errors"
|
||||
|
||||
pstore "github.com/libp2p/go-libp2p-core/peerstore"
|
||||
record "github.com/libp2p/go-libp2p-record"
|
||||
"github.com/matrix-org/dendrite/common/basecomponent"
|
||||
|
||||
"github.com/libp2p/go-libp2p"
|
||||
|
|
@ -71,7 +75,7 @@ func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
libp2pdht.Validator = LibP2PValidator{}
|
||||
libp2pdht.Validator = libP2PValidator{}
|
||||
r = libp2pdht
|
||||
return
|
||||
}),
|
||||
|
|
@ -104,3 +108,19 @@ func NewP2PDendrite(cfg *config.Dendrite, componentName string) *P2PDendrite {
|
|||
LibP2PPubsub: libp2ppubsub,
|
||||
}
|
||||
}
|
||||
|
||||
type libP2PValidator struct {
|
||||
KeyBook pstore.KeyBook
|
||||
}
|
||||
|
||||
func (v libP2PValidator) Validate(key string, value []byte) error {
|
||||
ns, _, err := record.SplitKey(key)
|
||||
if err != nil || ns != "matrix" {
|
||||
return errors.New("not Matrix path")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v libP2PValidator) Select(k string, vals [][]byte) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue