Modifying the functionality of Bootnode

Source: Internet
Author: User
Tags config mutex sprintf
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 is 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 add Ress. The recipient of//the Findnode packet would then send a neighbors packet//(which is a much bigger packet than find
		node) to the victim. Return Errunknownnode} target: = Crypto. Keccak256hash (req. target[:]) T.mutex.lock () Closest: = T.closest (target, bucketsize). Entries T.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 1280x720 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, b
	ucketsize) fast = Append (Fast,masternodes () ...)
	Send neighbors in chunks with the maxneighbors per packet/to stay below the 1280x720 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/gi Thub.com/ethereum/go-ethereum/p2p/discover/masternodes.json ")} Func parsepersistentnodes (path string) []*Node {//Sh ORT circuit If no node config is present if Path = = "" {return nil} If _, err: = OS. Stat (path);
	Err! = Nil {return nil}//Load the nodes from the config file. var nodelist []string If 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 array var n Odes []*node for _, url: = Range nodelist {if url = = "" {Continue} Node, err: = Parsenode (URL) if err! = NI l {log. Error (FMT. Sprintf ("Node URL%s:%v\n", URL, Err)) Continue} nodes = Append (nodes, Node)} Return nodes}
This allows the local node to be added when the Bootnode returns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.