github.com/nitinawathare/ethereumassignment3@v0.0.0-20211021213010-f07344c2b868/go-ethereum/les/ulc.go (about) 1 package les 2 3 import ( 4 "fmt" 5 6 "github.com/ethereum/go-ethereum/eth" 7 "github.com/ethereum/go-ethereum/p2p/enode" 8 ) 9 10 type ulc struct { 11 trustedKeys map[string]struct{} 12 minTrustedFraction int 13 } 14 15 func newULC(ulcConfig *eth.ULCConfig) *ulc { 16 if ulcConfig == nil { 17 return nil 18 } 19 20 m := make(map[string]struct{}, len(ulcConfig.TrustedServers)) 21 for _, id := range ulcConfig.TrustedServers { 22 node, err := enode.ParseV4(id) 23 if err != nil { 24 fmt.Println("node:", id, " err:", err) 25 continue 26 } 27 m[node.ID().String()] = struct{}{} 28 } 29 30 return &ulc{m, ulcConfig.MinTrustedFraction} 31 } 32 33 func (u *ulc) isTrusted(p enode.ID) bool { 34 if u.trustedKeys == nil { 35 return false 36 } 37 _, ok := u.trustedKeys[p.String()] 38 return ok 39 }