2018-07-25 14:48:02 +00:00
|
|
|
package verifier
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-11-14 07:03:58 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2018-07-25 14:48:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// LocalVerifier verifies nodes based on a provided local list.
|
|
|
|
type LocalVerifier struct {
|
2018-11-14 07:03:58 +00:00
|
|
|
KnownPeers map[enode.ID]struct{}
|
2018-07-25 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewLocalVerifier returns a new LocalVerifier instance.
|
2018-11-14 07:03:58 +00:00
|
|
|
func NewLocalVerifier(peers []enode.ID) *LocalVerifier {
|
|
|
|
knownPeers := make(map[enode.ID]struct{})
|
2018-07-25 14:48:02 +00:00
|
|
|
for _, peer := range peers {
|
|
|
|
knownPeers[peer] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &LocalVerifier{KnownPeers: knownPeers}
|
|
|
|
}
|
|
|
|
|
|
|
|
// VerifyNode checks if a given node is trusted using a local list.
|
2018-11-14 07:03:58 +00:00
|
|
|
func (v *LocalVerifier) VerifyNode(_ context.Context, nodeID enode.ID) bool {
|
2018-07-25 14:48:02 +00:00
|
|
|
if _, ok := v.KnownPeers[nodeID]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|