transport

package
v0.0.0-...-2406947 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2022 License: Apache-2.0 Imports: 21 Imported by: 4

Documentation

Overview

transport package implements SIP transport layer.

Index

Constants

View Source
const (
	MTU = sip.MTU

	DefaultHost     = sip.DefaultHost
	DefaultProtocol = sip.DefaultProtocol

	DefaultUdpPort = sip.DefaultUdpPort
	DefaultTcpPort = sip.DefaultTcpPort
	DefaultTlsPort = sip.DefaultTlsPort
	DefaultWsPort  = sip.DefaultWsPort
	DefaultWssPort = sip.DefaultWssPort
)

Variables

This section is empty.

Functions

func NewWsListener

func NewWsListener(listener net.Listener, network string, log log.Logger) *wsListener

func SetProtocolFactory

func SetProtocolFactory(factory ProtocolFactory)

SetProtocolFactory replaces default protocol factory

func WithLogger

func WithLogger(logger log.Logger) interface {
	LayerOption
	ProtocolOption
}

func WithMessageMapper

func WithMessageMapper(mapper sip.MessageMapper) interface {
	LayerOption
	ProtocolOption
}

Types

type Connection

type Connection interface {
	net.Conn

	Key() ConnectionKey
	Network() string
	Streamed() bool
	String() string
	ReadFrom(buf []byte) (num int, raddr net.Addr, err error)
	WriteTo(buf []byte, raddr net.Addr) (num int, err error)
}

Wrapper around net.Conn.

func NewConnection

func NewConnection(baseConn net.Conn, key ConnectionKey, network string, logger log.Logger) Connection

type ConnectionError

type ConnectionError struct {
	Err     error
	Op      string
	Net     string
	Source  string
	Dest    string
	ConnPtr string
}

Connection level error.

func (*ConnectionError) Error

func (err *ConnectionError) Error() string

func (*ConnectionError) Network

func (err *ConnectionError) Network() bool

func (*ConnectionError) Temporary

func (err *ConnectionError) Temporary() bool

func (*ConnectionError) Timeout

func (err *ConnectionError) Timeout() bool

func (*ConnectionError) Unwrap

func (err *ConnectionError) Unwrap() error

type ConnectionHandler

type ConnectionHandler interface {
	Cancel()
	Done() <-chan struct{}
	String() string
	Key() ConnectionKey
	Connection() Connection
	// Expiry returns connection expiry time.
	Expiry() time.Time
	Expired() bool
	// Update updates connection expiry time.
	// TODO put later to allow runtime update
	// Update(conn Connection, ttl time.Duration)
	// Manage runs connection serving.
	Serve()
}

ConnectionHandler serves associated connection, i.e. parses incoming data, manages expiry time & etc.

func NewConnectionHandler

func NewConnectionHandler(
	conn Connection,
	ttl time.Duration,
	output chan<- sip.Message,
	errs chan<- error,
	msgMapper sip.MessageMapper,
	logger log.Logger,
) ConnectionHandler

type ConnectionHandlerError

type ConnectionHandlerError struct {
	Err        error
	Key        ConnectionKey
	HandlerPtr string
	Net        string
	LAddr      string
	RAddr      string
}

func (*ConnectionHandlerError) Canceled

func (err *ConnectionHandlerError) Canceled() bool

func (*ConnectionHandlerError) EOF

func (err *ConnectionHandlerError) EOF() bool

func (*ConnectionHandlerError) Error

func (err *ConnectionHandlerError) Error() string

func (*ConnectionHandlerError) Expired

func (err *ConnectionHandlerError) Expired() bool

func (*ConnectionHandlerError) Network

func (err *ConnectionHandlerError) Network() bool

func (*ConnectionHandlerError) Temporary

func (err *ConnectionHandlerError) Temporary() bool

func (*ConnectionHandlerError) Timeout

func (err *ConnectionHandlerError) Timeout() bool

func (*ConnectionHandlerError) Unwrap

func (err *ConnectionHandlerError) Unwrap() error

type ConnectionKey

type ConnectionKey string

func (ConnectionKey) String

func (key ConnectionKey) String() string

type ConnectionPool

type ConnectionPool interface {
	Done() <-chan struct{}
	String() string
	Put(connection Connection, ttl time.Duration) error
	Get(key ConnectionKey) (Connection, error)
	All() []Connection
	Drop(key ConnectionKey) error
	DropAll() error
	Length() int
}

ConnectionPool used for active connection management.

func NewConnectionPool

func NewConnectionPool(
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) ConnectionPool

type Error

type Error interface {
	net.Error
	// Network indicates network level errors
	Network() bool
}

Transport error

type ExpireError

type ExpireError string

func (ExpireError) Canceled

func (err ExpireError) Canceled() bool

func (ExpireError) Error

func (err ExpireError) Error() string

func (ExpireError) Expired

func (err ExpireError) Expired() bool

func (ExpireError) Network

func (err ExpireError) Network() bool

func (ExpireError) Temporary

func (err ExpireError) Temporary() bool

func (ExpireError) Timeout

func (err ExpireError) Timeout() bool

type Layer

type Layer interface {
	Cancel()
	Done() <-chan struct{}
	Messages() <-chan sip.Message
	Errors() <-chan error
	// Listen starts listening on `addr` for each registered protocol.
	Listen(network string, addr string, options ...ListenOption) error
	// Send sends message on suitable protocol.
	Send(msg sip.Message) error
	String() string
	IsReliable(network string) bool
	IsStreamed(network string) bool
}

Layer is responsible for the actual transmission of messages - RFC 3261 - 18.

func NewLayer

func NewLayer(
	ip net.IP,
	dnsResolver *net.Resolver,
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Layer

NewLayer creates transport layer. - ip - host IP - dnsAddr - DNS server address, default is 127.0.0.1:53

type LayerOption

type LayerOption interface {
	ApplyLayer(opts *LayerOptions)
}

func WithDNSResolver

func WithDNSResolver(resolver *net.Resolver) LayerOption

type LayerOptions

type LayerOptions struct {
	Options
	DNSResolver *net.Resolver
}

type ListenOption

type ListenOption interface {
	ApplyListen(opts *ListenOptions)
}

Listen method options

type ListenOptions

type ListenOptions struct {
	TLSConfig TLSConfig
}

type ListenerHandler

type ListenerHandler interface {
	log.Loggable

	Cancel()
	Done() <-chan struct{}
	String() string
	Key() ListenerKey
	Listener() net.Listener
	Serve()
}

func NewListenerHandler

func NewListenerHandler(
	key ListenerKey,
	listener net.Listener,
	output chan<- Connection,
	errs chan<- error,
	logger log.Logger,
) ListenerHandler

type ListenerHandlerError

type ListenerHandlerError struct {
	Err        error
	Key        ListenerKey
	HandlerPtr string
	Net        string
	Addr       string
}

func (*ListenerHandlerError) Canceled

func (err *ListenerHandlerError) Canceled() bool

func (*ListenerHandlerError) Error

func (err *ListenerHandlerError) Error() string

func (*ListenerHandlerError) Expired

func (err *ListenerHandlerError) Expired() bool

func (*ListenerHandlerError) Network

func (err *ListenerHandlerError) Network() bool

func (*ListenerHandlerError) Temporary

func (err *ListenerHandlerError) Temporary() bool

func (*ListenerHandlerError) Timeout

func (err *ListenerHandlerError) Timeout() bool

func (*ListenerHandlerError) Unwrap

func (err *ListenerHandlerError) Unwrap() error

type ListenerKey

type ListenerKey string

func (ListenerKey) String

func (key ListenerKey) String() string

type ListenerPool

type ListenerPool interface {
	log.Loggable

	Done() <-chan struct{}
	String() string
	Put(key ListenerKey, listener net.Listener) error
	Get(key ListenerKey) (net.Listener, error)
	All() []net.Listener
	Drop(key ListenerKey) error
	DropAll() error
	Length() int
}

func NewListenerPool

func NewListenerPool(
	output chan<- Connection,
	errs chan<- error,
	cancel <-chan struct{},
	logger log.Logger,
) ListenerPool

type Options

type Options struct {
	MessageMapper sip.MessageMapper
	Logger        log.Logger
}

TODO migrate other factories to functional arguments

type PoolError

type PoolError struct {
	Err  error
	Op   string
	Pool string
}

func (*PoolError) Error

func (err *PoolError) Error() string

func (*PoolError) Network

func (err *PoolError) Network() bool

func (*PoolError) Temporary

func (err *PoolError) Temporary() bool

func (*PoolError) Timeout

func (err *PoolError) Timeout() bool

func (*PoolError) Unwrap

func (err *PoolError) Unwrap() error

type Protocol

type Protocol interface {
	Done() <-chan struct{}
	Network() string
	Reliable() bool
	Streamed() bool
	Listen(target *Target, options ...ListenOption) error
	Send(target *Target, msg sip.Message) error
	String() string
}

Protocol implements network specific features.

func NewTcpProtocol

func NewTcpProtocol(
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Protocol

func NewTlsProtocol

func NewTlsProtocol(
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Protocol

func NewUdpProtocol

func NewUdpProtocol(
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Protocol

func NewWsProtocol

func NewWsProtocol(
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Protocol

func NewWssProtocol

func NewWssProtocol(
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) Protocol

type ProtocolError

type ProtocolError struct {
	Err      error
	Op       string
	ProtoPtr string
}

Net Protocol level error

func (*ProtocolError) Error

func (err *ProtocolError) Error() string

func (*ProtocolError) Network

func (err *ProtocolError) Network() bool

func (*ProtocolError) Temporary

func (err *ProtocolError) Temporary() bool

func (*ProtocolError) Timeout

func (err *ProtocolError) Timeout() bool

func (*ProtocolError) Unwrap

func (err *ProtocolError) Unwrap() error

type ProtocolFactory

type ProtocolFactory func(
	network string,
	output chan<- sip.Message,
	errs chan<- error,
	cancel <-chan struct{},
	msgMapper sip.MessageMapper,
	logger log.Logger,
) (Protocol, error)

func GetProtocolFactory

func GetProtocolFactory() ProtocolFactory

GetProtocolFactory returns default protocol factory

type ProtocolOption

type ProtocolOption interface {
	ApplyProtocol(opts *ProtocolOptions)
}

type ProtocolOptions

type ProtocolOptions struct {
	Options
}

type TLSConfig

type TLSConfig struct {
	Domain string
	Cert   string
	Key    string
	Pass   string
}

TLSConfig for TLS and WSS only

func (TLSConfig) ApplyListen

func (c TLSConfig) ApplyListen(opts *ListenOptions)

type Target

type Target struct {
	Host string
	Port *sip.Port
}

Target endpoint

func FillTargetHostAndPort

func FillTargetHostAndPort(network string, target *Target) *Target

Fills endpoint target with default values.

func NewTarget

func NewTarget(host string, port int) *Target

func NewTargetFromAddr

func NewTargetFromAddr(addr string) (*Target, error)

func (*Target) Addr

func (trg *Target) Addr() string

func (*Target) String

func (trg *Target) String() string

type UnsupportedProtocolError

type UnsupportedProtocolError string

func (UnsupportedProtocolError) Error

func (err UnsupportedProtocolError) Error() string

func (UnsupportedProtocolError) Network

func (err UnsupportedProtocolError) Network() bool

func (UnsupportedProtocolError) Temporary

func (err UnsupportedProtocolError) Temporary() bool

func (UnsupportedProtocolError) Timeout

func (err UnsupportedProtocolError) Timeout() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL