status-go/vendor/github.com/ethereum/go-ethereum/les/ulc.go

40 lines
733 B
Go
Raw Normal View History

2018-10-16 11:27:11 +00:00
package les
import (
"fmt"
2018-10-16 11:27:11 +00:00
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/p2p/enode"
2018-10-16 11:27:11 +00:00
)
type ulc struct {
trustedKeys map[string]struct{}
minTrustedFraction int
}
func newULC(ulcConfig *eth.ULCConfig) *ulc {
if ulcConfig == nil {
return nil
}
m := make(map[string]struct{}, len(ulcConfig.TrustedServers))
for _, id := range ulcConfig.TrustedServers {
node, err := enode.ParseV4(id)
2018-10-16 11:27:11 +00:00
if err != nil {
fmt.Println("node:", id, " err:", err)
2018-10-16 11:27:11 +00:00
continue
}
m[node.ID().String()] = struct{}{}
2018-10-16 11:27:11 +00:00
}
return &ulc{m, ulcConfig.MinTrustedFraction}
}
func (u *ulc) isTrusted(p enode.ID) bool {
2018-10-16 11:27:11 +00:00
if u.trustedKeys == nil {
return false
}
_, ok := u.trustedKeys[p.String()]
return ok
}