p2p: revert

This commit is contained in:
Anton Evangelatov 2019-01-18 15:44:32 +01:00
parent 3551ef03fe
commit 537592a26e

View file

@ -166,7 +166,6 @@ func (s *dialstate) newTasks(nRunning int, peers map[enode.ID]*Peer, now time.Ti
var newtasks []task var newtasks []task
addDial := func(flag connFlag, n *enode.Node) bool { addDial := func(flag connFlag, n *enode.Node) bool {
log.Trace("addDial func", n.ID())
if err := s.checkDial(n, peers); err != nil { if err := s.checkDial(n, peers); err != nil {
log.Trace("Skipping dial candidate", "id", n.ID(), "addr", &net.TCPAddr{IP: n.IP(), Port: n.TCP()}, "err", err) log.Trace("Skipping dial candidate", "id", n.ID(), "addr", &net.TCPAddr{IP: n.IP(), Port: n.TCP()}, "err", err)
return false return false
@ -207,45 +206,40 @@ func (s *dialstate) newTasks(nRunning int, peers map[enode.ID]*Peer, now time.Ti
// If we don't have any peers whatsoever, try to dial a random bootnode. This // If we don't have any peers whatsoever, try to dial a random bootnode. This
// scenario is useful for the testnet (and private networks) where the discovery // scenario is useful for the testnet (and private networks) where the discovery
// table might be full of mostly bad peers, making it hard to find good ones. // table might be full of mostly bad peers, making it hard to find good ones.
log.Trace("before if", "len(s.bootnodes)", len(s.bootnodes), "needdyndials", needDynDials, "bool", now.Sub(s.start) > fallbackInterval) if len(peers) == 0 && len(s.bootnodes) > 0 && needDynDials > 0 && now.Sub(s.start) > fallbackInterval {
//if len(peers) == 0 && len(s.bootnodes) > 0 && needDynDials > 0 && now.Sub(s.start) > fallbackInterval {
if len(peers) == 0 && len(s.bootnodes) > 0 && needDynDials > 0 {
bootnode := s.bootnodes[0] bootnode := s.bootnodes[0]
s.bootnodes = append(s.bootnodes[:0], s.bootnodes[1:]...) s.bootnodes = append(s.bootnodes[:0], s.bootnodes[1:]...)
s.bootnodes = append(s.bootnodes, bootnode) s.bootnodes = append(s.bootnodes, bootnode)
log.Trace("inside if", "bootnode", bootnode, "len(s.bootnodes)", len(s.bootnodes))
if addDial(dynDialedConn, bootnode) { if addDial(dynDialedConn, bootnode) {
needDynDials-- needDynDials--
log.Trace("inside addDial if", "needDynDials", needDynDials)
} }
} }
// Use random nodes from the table for half of the necessary // Use random nodes from the table for half of the necessary
// dynamic dials. // dynamic dials.
//randomCandidates := needDynDials / 2 randomCandidates := needDynDials / 2
//if randomCandidates > 0 { if randomCandidates > 0 {
//n := s.ntab.ReadRandomNodes(s.randomNodes) n := s.ntab.ReadRandomNodes(s.randomNodes)
//for i := 0; i < randomCandidates && i < n; i++ { for i := 0; i < randomCandidates && i < n; i++ {
//if addDial(dynDialedConn, s.randomNodes[i]) { if addDial(dynDialedConn, s.randomNodes[i]) {
//needDynDials-- needDynDials--
//} }
//} }
//} }
// Create dynamic dials from random lookup results, removing tried // Create dynamic dials from random lookup results, removing tried
// items from the result buffer. // items from the result buffer.
//i := 0 i := 0
//for ; i < len(s.lookupBuf) && needDynDials > 0; i++ { for ; i < len(s.lookupBuf) && needDynDials > 0; i++ {
//if addDial(dynDialedConn, s.lookupBuf[i]) { if addDial(dynDialedConn, s.lookupBuf[i]) {
//needDynDials-- needDynDials--
//} }
//} }
//s.lookupBuf = s.lookupBuf[:copy(s.lookupBuf, s.lookupBuf[i:])] s.lookupBuf = s.lookupBuf[:copy(s.lookupBuf, s.lookupBuf[i:])]
////Launch a discovery lookup if more candidates are needed. // Launch a discovery lookup if more candidates are needed.
//if len(s.lookupBuf) < needDynDials && !s.lookupRunning { if len(s.lookupBuf) < needDynDials && !s.lookupRunning {
//s.lookupRunning = true s.lookupRunning = true
//newtasks = append(newtasks, &discoverTask{}) newtasks = append(newtasks, &discoverTask{})
//} }
// Launch a timer to wait for the next node to expire if all // Launch a timer to wait for the next node to expire if all
// candidates have been tried and no task is currently active. // candidates have been tried and no task is currently active.
@ -267,7 +261,6 @@ var (
) )
func (s *dialstate) checkDial(n *enode.Node, peers map[enode.ID]*Peer) error { func (s *dialstate) checkDial(n *enode.Node, peers map[enode.ID]*Peer) error {
log.Trace("checkDial func", n.ID())
_, dialing := s.dialing[n.ID()] _, dialing := s.dialing[n.ID()]
switch { switch {
case dialing: case dialing: