Move libp2pvalidator into p2pdendrite

This commit is contained in:
Hilmar Gústafsson 2020-04-13 10:45:02 +02:00
parent 906cda94d3
commit 6291732ec4
2 changed files with 21 additions and 25 deletions

View file

@ -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
}

View file

@ -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
}