Move initial DNS seeding to own func.

This commit is contained in:
Dave Collins 2013-10-07 17:38:45 -05:00
parent 4b728df738
commit c03f2b757b

View file

@ -211,29 +211,13 @@ func (s *server) listenHandler(listener net.Listener) {
log.Tracef("[SRVR] Listener handler done for %s", listener.Addr())
}
// peerHandler is used to handle peer operations such as adding and removing
// peers to and from the server, banning peers, and broadcasting messages to
// peers. It must be run a a goroutine.
func (s *server) peerHandler() {
// Start the address manager and block manager, both of which are needed
// by peers. This is done here since their lifecycle is closely tied
// to this handler and rather than adding more channels to sychronize
// things, it's easier and slightly faster to simply start and stop them
// in this handler.
s.addrManager.Start()
s.blockManager.Start()
log.Tracef("[SRVR] Starting peer handler")
peers := list.New()
bannedPeers := make(map[string]time.Time)
outboundPeers := 0
maxOutbound := defaultMaxOutbound
if cfg.MaxPeers < maxOutbound {
maxOutbound = cfg.MaxPeers
// seedFromDNS uses DNS seeding to populate the address manager with peers.
func (s *server) seedFromDNS() {
// Nothing to do if DNS seeding is disabled.
if cfg.DisableDNSSeed {
return
}
// Do initial DNS seeding to populate address manager.
if !cfg.DisableDNSSeed {
proxy := ""
if cfg.Proxy != "" && cfg.UseTor {
proxy = cfg.Proxy
@ -268,6 +252,30 @@ func (s *server) peerHandler() {
// XXX peers like bitcoind does?
}
// peerHandler is used to handle peer operations such as adding and removing
// peers to and from the server, banning peers, and broadcasting messages to
// peers. It must be run a a goroutine.
func (s *server) peerHandler() {
// Start the address manager and block manager, both of which are needed
// by peers. This is done here since their lifecycle is closely tied
// to this handler and rather than adding more channels to sychronize
// things, it's easier and slightly faster to simply start and stop them
// in this handler.
s.addrManager.Start()
s.blockManager.Start()
log.Tracef("[SRVR] Starting peer handler")
peers := list.New()
bannedPeers := make(map[string]time.Time)
outboundPeers := 0
maxOutbound := defaultMaxOutbound
if cfg.MaxPeers < maxOutbound {
maxOutbound = cfg.MaxPeers
}
// Add peers discovered through DNS to the address manager.
s.seedFromDNS()
// Start up persistent peers.
permanentPeers := cfg.ConnectPeers
if len(permanentPeers) == 0 {