code: func (s *ChainService) handleAddPeerMsg(state *peerState, sp *ServerPeer) bool {
  	if sp == nil {
  		return false
  	}
  
  	// Ignore new peers if we're shutting down.
  	if atomic.LoadInt32(&s.shutdown) != 0 {
  		log.Infof("New peer %s ignored - server is shutting down", sp)
  		sp.Disconnect()
  		return false
  	}
  
  	// Disconnect banned peers.
  	if s.isBanned(sp.Addr(), state) {
  		sp.Disconnect()
  		return false
  	}
  
  	// TODO: Check for max peers from a single IP.
  
  	// Limit max number of total peers.
  	if state.Count() >= MaxPeers {
  		log.Infof("Max peers reached [%d] - disconnecting peer %s",
  			MaxPeers, sp)
  		sp.Disconnect()
  		// TODO: how to handle permanent peers here?
  		// they should be rescheduled.
  		return false
  	}
  
  	// Add the new peer and start it.
  	log.Debugf("New peer %s", sp)
  	state.outboundGroups[addrmgr.GroupKey(sp.NA())]++
  	if sp.persistent {
  		state.persistentPeers[sp.ID()] = sp
  	} else {
  		state.outboundPeers[sp.ID()] = sp
  	}
  
  	// Close firstPeerConnect channel so blockManager will be notified.
  	if s.firstPeerConnect != nil {
  		close(s.firstPeerConnect)
  		s.firstPeerConnect = nil
  	}
  
  	return true
  }
docs: // handleAddPeerMsg deals with adding new peers.  It is invoked from the
  // peerHandler goroutine.