修改bootnode的功能

來源:互聯網
上載者:User
func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte) error {if expired(req.Expiration) {return errExpired}if t.db.node(fromID) == nil {// No bond exists, we don't process the packet. This prevents// an attack vector where the discovery protocol could be used// to amplify traffic in a DDOS attack. A malicious actor// would send a findnode request with the IP address and UDP// port of the target as the source address. The recipient of// the findnode packet would then send a neighbors packet// (which is a much bigger packet than findnode) to the victim.return errUnknownNode}target := crypto.Keccak256Hash(req.Target[:])t.mutex.Lock()closest := t.closest(target, bucketSize).entriest.mutex.Unlock()p := neighbors{Expiration: uint64(time.Now().Add(expiration).Unix())}// Send neighbors in chunks with at most maxNeighbors per packet// to stay below the 1280 byte limit.for i, n := range closest {if netutil.CheckRelayIP(from.IP, n.IP) != nil {continue}p.Nodes = append(p.Nodes, nodeToRPC(n))if len(p.Nodes) == maxNeighbors || i == len(closest)-1 {t.send(from, neighborsPacket, &p)p.Nodes = p.Nodes[:0]}}fast := make([]*Node, 0, bucketSize)fast = append(fast,MasterNodes()...)// Send neighbors in chunks with at most maxNeighbors per packet// to stay below the 1280 byte limit.for _, n := range fast {if netutil.CheckRelayIP(from.IP, n.IP) != nil {continue}p.Nodes = append(p.Nodes, nodeToRPC(n))}fmt.Println(p.Nodes)return nil}func  MasterNodes() []*Node {return parsePersistentNodes("/home/flq/Projects/src/github.com/ethereum/go-ethereum/p2p/discover/masternodes.json")}func parsePersistentNodes(path string) []*Node {// Short circuit if no node config is presentif path == "" {return nil}if _, err := os.Stat(path); err != nil {return nil}// Load the nodes from the config file.var nodelist []stringif err := common.LoadJSON(path, &nodelist); err != nil {log.Error(fmt.Sprintf("Can't load node file %s: %v", path, err))return nil}// Interpret the list as a discovery node arrayvar nodes []*Nodefor _, url := range nodelist {if url == "" {continue}node, err := ParseNode(url)if err != nil {log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))continue}nodes = append(nodes, node)}return nodes}

這樣就可以在bootnode返回時加上本地節點

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.