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()) log.Tracef("[SRVR] Listener handler done for %s", listener.Addr())
} }
// peerHandler is used to handle peer operations such as adding and removing // seedFromDNS uses DNS seeding to populate the address manager with peers.
// peers to and from the server, banning peers, and broadcasting messages to func (s *server) seedFromDNS() {
// peers. It must be run a a goroutine. // Nothing to do if DNS seeding is disabled.
func (s *server) peerHandler() { if cfg.DisableDNSSeed {
// Start the address manager and block manager, both of which are needed return
// 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
} }
// Do initial DNS seeding to populate address manager.
if !cfg.DisableDNSSeed {
proxy := "" proxy := ""
if cfg.Proxy != "" && cfg.UseTor { if cfg.Proxy != "" && cfg.UseTor {
proxy = cfg.Proxy proxy = cfg.Proxy
@ -266,8 +250,32 @@ func (s *server) peerHandler() {
} }
// XXX if this is empty do we want to use hardcoded // XXX if this is empty do we want to use hardcoded
// XXX peers like bitcoind does? // 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. // Start up persistent peers.
permanentPeers := cfg.ConnectPeers permanentPeers := cfg.ConnectPeers
if len(permanentPeers) == 0 { if len(permanentPeers) == 0 {