From 6291732ec417cd8809917c6232e031a8e79d03eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hilmar=20G=C3=BAstafsson?= Date: Mon, 13 Apr 2020 10:45:02 +0200 Subject: [PATCH] Move libp2pvalidator into p2pdendrite --- cmd/dendrite-p2p-demo/libp2p.go | 24 ------------------------ cmd/dendrite-p2p-demo/p2pdendrite.go | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 25 deletions(-) delete mode 100644 cmd/dendrite-p2p-demo/libp2p.go diff --git a/cmd/dendrite-p2p-demo/libp2p.go b/cmd/dendrite-p2p-demo/libp2p.go deleted file mode 100644 index 77af754b9..000000000 --- a/cmd/dendrite-p2p-demo/libp2p.go +++ /dev/null @@ -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 -} diff --git a/cmd/dendrite-p2p-demo/p2pdendrite.go b/cmd/dendrite-p2p-demo/p2pdendrite.go index 314b0c4b7..a9db3b39c 100644 --- a/cmd/dendrite-p2p-demo/p2pdendrite.go +++ b/cmd/dendrite-p2p-demo/p2pdendrite.go @@ -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 +}