func NewLayer(
	ip net.IP,
	dnsResolver *net.Resolver,
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Layer {
	tpl := &layer{
		protocols:   newProtocolStore(),
		listenPorts: make(map[string][]sip.Port),
		ip:          ip,
		dnsResolver: dnsResolver,
		msgMapper:   msgMapper,
		msgs:     make(chan sip.Message),
		errs:     make(chan error),
		pmsgs:    make(chan sip.Message),
		perrs:    make(chan error),
		canceled: make(chan struct{}),
		done:     make(chan struct{}),
	}
	tpl.log = logger.
		WithPrefix("transport.Layer").
		WithFields(map[string]interface{}{
			"transport_layer_ptr": fmt.Sprintf("%p", tpl),
		})
	go tpl.serveProtocols()
	return tpl
}
NewLayer creates transport layer.
- ip - host IP
- dnsAddr - DNS server address, default is 127.0.0.1:53
package transport
import (
	"context"
	"errors"
	"fmt"
	"math/rand"
	"net"
	"strings"
	"sync"
	"time"
	"github.com/ghettovoice/gosip/log"
	"github.com/ghettovoice/gosip/sip"
)
func init() {
	rand.Seed(time.Now().UnixNano())
}
type Layer interface {
	Cancel()
	Done() <-chan struct{}
	Messages() <-chan sip.Message
	Errors() <-chan error
	Listen(network string, addr string, options ...ListenOption) error
	Send(msg sip.Message) error
	String() string
	IsReliable(network string) bool
	IsStreamed(network string) bool
}
var protocolFactory ProtocolFactory = func(
	network string,
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) (Protocol, error) {
	switch strings.ToLower(network) {
	case "udp":
		return NewUdpProtocol(output, errs, cancel, msgMapper, logger), nil
	case "tcp":
		return NewTcpProtocol(output, errs, cancel, msgMapper, logger), nil
	case "tls":
		return NewTlsProtocol(output, errs, cancel, msgMapper, logger), nil
	case "ws":
		return NewWsProtocol(output, errs, cancel, msgMapper, logger), nil
	case "wss":
		return NewWssProtocol(output, errs, cancel, msgMapper, logger), nil
	default:
		return nil, UnsupportedProtocolError(fmt.Sprintf("protocol %s is not supported", network))
	}
}
func SetProtocolFactory(factory ProtocolFactory) {
	protocolFactory = factory
}
func GetProtocolFactory() ProtocolFactory {
	return protocolFactory
}
type layer struct {
	protocols   *protocolStore
	listenPorts map[string][]sip.Port
	ip          net.IP
	dnsResolver *net.Resolver
	msgMapper   sip.MessageMapper
	msgs     chan sip.Message
	errs     chan error
	pmsgs    chan sip.Message
	perrs    chan error
	canceled chan struct{}
	done     chan struct{}
	wg         sync.WaitGroup
	cancelOnce sync.Once
	log log.Logger
}