Documentation
¶
Overview ¶
transport package implements SIP transport layer.
Index ¶
- Constants
- func NewWsListener(listener net.Listener, network string, log log.Logger) *wsListener
- func SetProtocolFactory(factory ProtocolFactory)
- func WithLogger(logger log.Logger) interface{ ... }
- func WithMessageMapper(mapper sip.MessageMapper) interface{ ... }
- type Connection
- type ConnectionError
- type ConnectionHandler
- type ConnectionHandlerError
- func (err *ConnectionHandlerError) Canceled() bool
- func (err *ConnectionHandlerError) EOF() bool
- func (err *ConnectionHandlerError) Error() string
- func (err *ConnectionHandlerError) Expired() bool
- func (err *ConnectionHandlerError) Network() bool
- func (err *ConnectionHandlerError) Temporary() bool
- func (err *ConnectionHandlerError) Timeout() bool
- func (err *ConnectionHandlerError) Unwrap() error
- type ConnectionKey
- type ConnectionPool
- type Error
- type ExpireError
- type Layer
- type LayerOption
- type LayerOptions
- type ListenOption
- type ListenOptions
- type ListenerHandler
- type ListenerHandlerError
- func (err *ListenerHandlerError) Canceled() bool
- func (err *ListenerHandlerError) Error() string
- func (err *ListenerHandlerError) Expired() bool
- func (err *ListenerHandlerError) Network() bool
- func (err *ListenerHandlerError) Temporary() bool
- func (err *ListenerHandlerError) Timeout() bool
- func (err *ListenerHandlerError) Unwrap() error
- type ListenerKey
- type ListenerPool
- type Options
- type PoolError
- type Protocol
- func NewTcpProtocol(output chan<- sip.Message, errs chan<- error, cancel <-chan struct{}, ...) Protocol
- func NewTlsProtocol(output chan<- sip.Message, errs chan<- error, cancel <-chan struct{}, ...) Protocol
- func NewUdpProtocol(output chan<- sip.Message, errs chan<- error, cancel <-chan struct{}, ...) Protocol
- func NewWsProtocol(output chan<- sip.Message, errs chan<- error, cancel <-chan struct{}, ...) Protocol
- func NewWssProtocol(output chan<- sip.Message, errs chan<- error, cancel <-chan struct{}, ...) Protocol
- type ProtocolError
- type ProtocolFactory
- type ProtocolOption
- type ProtocolOptions
- type TLSConfig
- type Target
- type UnsupportedProtocolError
Constants ¶
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 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 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.
type LayerOption ¶
type LayerOption interface {
ApplyLayer(opts *LayerOptions)
}
func WithDNSResolver ¶
func WithDNSResolver(resolver *net.Resolver) LayerOption
type LayerOptions ¶
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 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 NewTlsProtocol ¶
func NewUdpProtocol ¶
func NewWsProtocol ¶
func NewWssProtocol ¶
type ProtocolError ¶
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 ¶
TLSConfig for TLS and WSS only
func (TLSConfig) ApplyListen ¶
func (c TLSConfig) ApplyListen(opts *ListenOptions)
type Target ¶
Target endpoint
func FillTargetHostAndPort ¶
Fills endpoint target with default values.
func NewTargetFromAddr ¶
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