forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ulc.go
39 lines (32 loc) · 733 Bytes
/
ulc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package les
import (
"fmt"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/p2p/enode"
)
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)
if err != nil {
fmt.Println("node:", id, " err:", err)
continue
}
m[node.ID().String()] = struct{}{}
}
return &ulc{m, ulcConfig.MinTrustedFraction}
}
func (u *ulc) isTrusted(p enode.ID) bool {
if u.trustedKeys == nil {
return false
}
_, ok := u.trustedKeys[p.String()]
return ok
}