Comment multi-peer connect while code is under dev.

This commit is contained in:
Dave Collins 2013-09-17 10:58:16 -05:00
parent 92a8605b24
commit 7609ff396a

118
server.go
View file

@ -6,7 +6,7 @@ package main
import ( import (
"container/list" "container/list"
"fmt" //"fmt"
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
"github.com/conformal/btcwire" "github.com/conformal/btcwire"
"net" "net"
@ -354,73 +354,73 @@ func (s *server) peerHandler() {
} }
} }
tries := 0 //tries := 0
for outboundPeers < maxOutbound && //for outboundPeers < maxOutbound &&
peers.Len() < cfg.MaxPeers && !s.shutdown { // peers.Len() < cfg.MaxPeers && !s.shutdown {
// We bias like bitcoind does, 10 for no outgoing // // We bias like bitcoind does, 10 for no outgoing
// up to 90 (8) for the selection of new vs tried // // up to 90 (8) for the selection of new vs tried
//addresses. // //addresses.
nPeers := outboundPeers // nPeers := outboundPeers
if nPeers > 8 { // if nPeers > 8 {
nPeers = 8 // nPeers = 8
} // }
addr := s.addrManager.GetAddress("any", 10+nPeers*10) // addr := s.addrManager.GetAddress("any", 10+nPeers*10)
if addr == nil { // if addr == nil {
break // break
} // }
key := GroupKey(addr.na) // key := GroupKey(addr.na)
// Address will not be invalid, local or unroutable // // Address will not be invalid, local or unroutable
// because addrmanager rejects those on addition. // // because addrmanager rejects those on addition.
// Just check that we don't already have an address // // Just check that we don't already have an address
// in the same group so that we are not connecting // // in the same group so that we are not connecting
// to the same network segment at the expense of // // to the same network segment at the expense of
// others. bitcoind breaks out of the loop here, but // // others. bitcoind breaks out of the loop here, but
// we continue to try other addresses. // // we continue to try other addresses.
if groups[key] != 0 { // if groups[key] != 0 {
continue // continue
} // }
tries++ // tries++
// After 100 bad tries exit the loop and we'll try again // // After 100 bad tries exit the loop and we'll try again
// later. // // later.
if tries > 100 { // if tries > 100 {
break // break
} // }
// XXX if we have limited that address skip // // XXX if we have limited that address skip
// only allow recent nodes (10mins) after we failed 30 // // only allow recent nodes (10mins) after we failed 30
// times // // times
if time.Now().After(addr.lastattempt.Add(10*time.Minute)) && // if time.Now().After(addr.lastattempt.Add(10*time.Minute)) &&
tries < 30 { // tries < 30 {
continue // continue
} // }
// allow nondefault ports after 50 failed tries. // // allow nondefault ports after 50 failed tries.
if fmt.Sprintf("%d", addr.na.Port) != // if fmt.Sprintf("%d", addr.na.Port) !=
activeNetParams.peerPort && tries < 50 { // activeNetParams.peerPort && tries < 50 {
continue // continue
} // }
addrStr := NetAddressKey(addr.na) // addrStr := NetAddressKey(addr.na)
tries = 0 // tries = 0
// any failure will be due to banned peers etc. we have // // any failure will be due to banned peers etc. we have
// already checked that we have room for more peers. // // already checked that we have room for more peers.
if s.handleAddPeerMsg(peers, bannedPeers, // if s.handleAddPeerMsg(peers, bannedPeers,
newOutboundPeer(s, addrStr, false)) { // newOutboundPeer(s, addrStr, false)) {
outboundPeers++ // outboundPeers++
groups[key]++ // groups[key]++
} // }
} //}
// We we need more peers, wake up in ten seconds and try again. // We we need more peers, wake up in ten seconds and try again.
if outboundPeers < maxOutbound && peers.Len() < cfg.MaxPeers { //if outboundPeers < maxOutbound && peers.Len() < cfg.MaxPeers {
time.AfterFunc(10*time.Second, func() { // time.AfterFunc(10*time.Second, func() {
s.wakeup <- true // s.wakeup <- true
}) // })
} //}
} }
if wakeupTimer != nil { if wakeupTimer != nil {