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
addDial := func(flag connFlag, n *enode.Node) bool {
log.Trace("addDial func", n.ID())
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)
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
// 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.
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 {
if len(peers) == 0 && len(s.bootnodes) > 0 && needDynDials > 0 && now.Sub(s.start) > fallbackInterval {
bootnode := s.bootnodes[0]
s.bootnodes = append(s.bootnodes[:0], s.bootnodes[1:]...)
s.bootnodes = append(s.bootnodes, bootnode)
log.Trace("inside if", "bootnode", bootnode, "len(s.bootnodes)", len(s.bootnodes))
if addDial(dynDialedConn, bootnode) {
needDynDials--
log.Trace("inside addDial if", "needDynDials", needDynDials)
}
}
// Use random nodes from the table for half of the necessary
// dynamic dials.
//randomCandidates := needDynDials / 2
//if randomCandidates > 0 {
//n := s.ntab.ReadRandomNodes(s.randomNodes)
//for i := 0; i < randomCandidates && i < n; i++ {
//if addDial(dynDialedConn, s.randomNodes[i]) {
//needDynDials--
//}
//}
//}
randomCandidates := needDynDials / 2
if randomCandidates > 0 {
n := s.ntab.ReadRandomNodes(s.randomNodes)
for i := 0; i < randomCandidates && i < n; i++ {
if addDial(dynDialedConn, s.randomNodes[i]) {
needDynDials--
}
}
}
// Create dynamic dials from random lookup results, removing tried
// items from the result buffer.
//i := 0
//for ; i < len(s.lookupBuf) && needDynDials > 0; i++ {
//if addDial(dynDialedConn, s.lookupBuf[i]) {
//needDynDials--
//}
//}
//s.lookupBuf = s.lookupBuf[:copy(s.lookupBuf, s.lookupBuf[i:])]
////Launch a discovery lookup if more candidates are needed.
//if len(s.lookupBuf) < needDynDials && !s.lookupRunning {
//s.lookupRunning = true
//newtasks = append(newtasks, &discoverTask{})
//}
i := 0
for ; i < len(s.lookupBuf) && needDynDials > 0; i++ {
if addDial(dynDialedConn, s.lookupBuf[i]) {
needDynDials--
}
}
s.lookupBuf = s.lookupBuf[:copy(s.lookupBuf, s.lookupBuf[i:])]
// Launch a discovery lookup if more candidates are needed.
if len(s.lookupBuf) < needDynDials && !s.lookupRunning {
s.lookupRunning = true
newtasks = append(newtasks, &discoverTask{})
}
// Launch a timer to wait for the next node to expire if all
// 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 {
log.Trace("checkDial func", n.ID())
_, dialing := s.dialing[n.ID()]
switch {
case dialing: