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
}
NewDefaultListener creates a new DefaultListener on lAddr, optionally trying
to determine external address using UPnP.
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
}