func (l *DefaultListener) ExternalAddressHost() string {
	ip := l.ExternalAddress().IP
	if isIpv6(ip) {
		return "[" + ip.String() + "]"
	}
	return ip.String()
}
ExternalAddressHost returns the external NetAddress IP string. If an IP is
IPv6, it's wrapped in brackets ("[2001:db8:1f70::999:de8:7648:6e8]").
package p2p
import (
	"fmt"
	"net"
	"strconv"
	"strings"
	"time"
	cmn "github.com/tendermint/tendermint/libs/common"
	"github.com/tendermint/tendermint/libs/log"
	"github.com/tendermint/tendermint/p2p/upnp"
)
type Listener interface {
	Connections() <-chan net.Conn
	InternalAddress() *NetAddress
	ExternalAddress() *NetAddress
	ExternalAddressHost() string
	String() string
	Stop() error
}
type DefaultListener struct {
	cmn.BaseService
	listener    net.Listener
	intAddr     *NetAddress
	extAddr     *NetAddress
	connections chan net.Conn
}
var _ Listener = (*DefaultListener)(nil)
const (
	numBufferedConnections = 10
	defaultExternalPort    = 8770
	tryListenSeconds       = 5
)
func splitHostPort(addr string) (host string, port int) {
	host, portStr, err := net.SplitHostPort(addr)
	if err != nil {
		panic(err)
	}
	port, err = strconv.Atoi(portStr)
	if err != nil {
		panic(err)
	}
	return host, port
}
func NewDefaultListener(
	fullListenAddrString string,
	externalAddrString string,
	useUPnP bool,
	logger log.Logger) Listener {
	protocol, lAddr := cmn.ProtocolAndAddress(fullListenAddrString)
	lAddrIP, lAddrPort := splitHostPort(lAddr)
	var listener net.Listener
	var err error
	for i := 0; i < tryListenSeconds; i++ {
		listener, err = net.Listen(protocol, lAddr)
		if err == nil {
			break
		} else if i < tryListenSeconds-1 {
			time.Sleep(time.Second * 1)
		}
	}
	if err != nil {
		panic(err)
	}
	listenerIP, listenerPort := splitHostPort(listener.Addr().String())
	logger.Info("Local listener", "ip", listenerIP, "port", listenerPort)
	var intAddr *NetAddress
	intAddr, err = NewNetAddressStringWithOptionalID(lAddr)
	if err != nil {
		panic(err)
	}
	inAddrAny := lAddrIP == "" || lAddrIP == "0.0.0.0"
	var extAddr *NetAddress
	if externalAddrString != "" {
		var err error
		extAddr, err = NewNetAddressStringWithOptionalID(externalAddrString)
		if err != nil {
			panic(fmt.Sprintf("Error in ExternalAddress: %v", err))
		}
	}
	if extAddr == nil && useUPnP && inAddrAny {
		extAddr = getUPNPExternalAddress(lAddrPort, listenerPort, logger)
	}
	if extAddr == nil {
		defaultToIPv4 := inAddrAny
		extAddr = getNaiveExternalAddress(defaultToIPv4, listenerPort, false, logger)
	}
	if extAddr == nil {
		panic("Could not determine external address!")
	}
	dl := &DefaultListener{
		listener:    listener,
		intAddr:     intAddr,
		extAddr:     extAddr,
		connections: make(chan net.Conn, numBufferedConnections),
	}
	dl.BaseService = *cmn.NewBaseService(logger, "DefaultListener", dl)
	err = dl.Start()  
	if err != nil {
		logger.Error("Error starting base service", "err", err)
	}
	return dl
}
func (l *DefaultListener) OnStart() error {
	if err := l.BaseService.OnStart(); err != nil {
		return err
	}
	go l.listenRoutine()
	return nil
}
func (l *DefaultListener) OnStop() {
	l.BaseService.OnStop()
	l.listener.Close()  
}
func (l *DefaultListener) listenRoutine() {
	for {
		conn, err := l.listener.Accept()
		if !l.IsRunning() {
			break  
		}
		if err != nil {
			panic(err)
		}
		l.connections <- conn
	}
	close(l.connections)
	for range l.connections {
	}
}
func (l *DefaultListener) Connections() <-chan net.Conn {
	return l.connections
}
func (l *DefaultListener) InternalAddress() *NetAddress {
	return l.intAddr
}
func (l *DefaultListener) ExternalAddress() *NetAddress {
	return l.extAddr
}