func (t *TCPStreamLayer) Addr() net.Addr {
	if t.advertise != nil {
		return t.advertise
	}
	return t.listener.Addr()
}
Addr implements the net.Listener interface.
package raft
import (
	"errors"
	"io"
	"net"
	"time"
)
var (
	errNotAdvertisable = errors.New("local bind address is not advertisable")
	errNotTCP          = errors.New("local address is not a TCP address")
)
type TCPStreamLayer struct {
	advertise net.Addr
	listener  *net.TCPListener
}
func NewTCPTransport(
	bindAddr string,
	advertise net.Addr,
	maxPool int,
	timeout time.Duration,
	logOutput io.Writer,
) (*NetworkTransport, error) {
	list, err := net.Listen("tcp", bindAddr)
	if err != nil {
		return nil, err
	}
	stream := &TCPStreamLayer{
		advertise: advertise,
		listener:  list.(*net.TCPListener),
	}
	addr, ok := stream.Addr().(*net.TCPAddr)
	if !ok {
		list.Close()
		return nil, errNotTCP
	}
	if addr.IP.IsUnspecified() {
		list.Close()
		return nil, errNotAdvertisable
	}
	trans := NewNetworkTransport(stream, maxPool, timeout, logOutput)
	return trans, nil
}
func (t *TCPStreamLayer) Dial(address string, timeout time.Duration) (net.Conn, error) {
	return net.DialTimeout("tcp", address, timeout)
}
func (t *TCPStreamLayer) Accept() (c net.Conn, err error) {
	return t.listener.Accept()
}
func (t *TCPStreamLayer) Close() (err error) {
	return t.listener.Close()
}