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