Documentation
¶
Index ¶
- Constants
- Variables
- func IsReliable(network string) bool
- func NetworkToLower(network string) string
- type Addr
- type Connection
- type ConnectionPool
- type Layer
- func (l *Layer) ClientRequestConnection(ctx context.Context, req *sip.Request) (c Connection, err error)
- func (l *Layer) Close() error
- func (l *Layer) GetConnection(network, addr string) (Connection, error)
- func (l *Layer) GetListenPort(network string) int
- func (l *Layer) OnMessage(h sip.MessageHandler)
- func (l *Layer) ServeTCP(c net.Listener) error
- func (l *Layer) ServeTLS(c net.Listener) error
- func (l *Layer) ServeUDP(c net.PacketConn) error
- func (l *Layer) ServeWS(c net.Listener) error
- func (l *Layer) ServeWSS(c net.Listener) error
- func (l *Layer) WriteMsg(msg sip.Message) error
- func (l *Layer) WriteMsgTo(msg sip.Message, addr string, network string) error
- type TCPConnection
- type TCPTransport
- func (t *TCPTransport) Close() error
- func (t *TCPTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
- func (t *TCPTransport) GetConnection(addr string) (Connection, error)
- func (t *TCPTransport) Network() string
- func (t *TCPTransport) Serve(l net.Listener, handler sip.MessageHandler) error
- func (t *TCPTransport) String() string
- type TLSTransport
- type Transport
- type UDPConnection
- func (c *UDPConnection) Close() error
- func (c *UDPConnection) LocalAddr() net.Addr
- func (c *UDPConnection) Read(b []byte) (n int, err error)
- func (c *UDPConnection) ReadFrom(b []byte) (n int, addr net.Addr, err error)
- func (c *UDPConnection) Ref(i int) int
- func (c *UDPConnection) TryClose() (int, error)
- func (c *UDPConnection) Write(b []byte) (n int, err error)
- func (c *UDPConnection) WriteMsg(msg sip.Message) error
- func (c *UDPConnection) WriteTo(b []byte, addr net.Addr) (n int, err error)
- type UDPTransport
- func (t *UDPTransport) Close() error
- func (t *UDPTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
- func (t *UDPTransport) GetConnection(addr string) (Connection, error)
- func (t *UDPTransport) Network() string
- func (t *UDPTransport) ResolveAddr(addr string) (net.Addr, error)
- func (t *UDPTransport) Serve(conn net.PacketConn, handler sip.MessageHandler) error
- func (t *UDPTransport) String() string
- type WSConnection
- type WSSTransport
- type WSTransport
- func (t *WSTransport) Close() error
- func (t *WSTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
- func (t *WSTransport) GetConnection(addr string) (Connection, error)
- func (t *WSTransport) Network() string
- func (t *WSTransport) ResolveAddr(addr string) (net.Addr, error)
- func (t *WSTransport) Serve(l net.Listener, handler sip.MessageHandler) error
- func (t *WSTransport) String() string
Constants ¶
const ( // Transport for different sip messages. GO uses lowercase, but for message parsing, we should // use this constants for setting message Transport TransportUDP = "UDP" TransportTCP = "TCP" TransportTLS = "TLS" TransportWS = "WS" TransportWSS = "WSS" // TransportFixedLengthMessage sets message size limit for parsing and avoids stream parsing TransportFixedLengthMessage uint16 = 0 )
Variables ¶
var ( SIPDebug bool // IdleConnection will keep connections idle even after transaction terminate // -1 - single response or request will close // 0 - close connection immediatelly after transaction terminate // 1 - keep connection idle after transaction termination IdleConnection int = 1 )
var ( // UDPReadWorkers defines how many listeners will work // Best performance is achieved with low value, to remove high concurency UDPReadWorkers int = 1 UDPMTUSize = 1500 ErrUDPMTUCongestion = errors.New("size of packet larger than MTU") )
var (
ErrNetworkNotSuported = errors.New("protocol not supported")
)
var ( // WebSocketProtocols is used in setting websocket header // By default clients must accept protocol sip WebSocketProtocols = []string{"sip"} )
Functions ¶
func IsReliable ¶
func NetworkToLower ¶
NetworkToLower is faster function converting UDP, TCP to udp, tcp
Types ¶
type Connection ¶
type Connection interface {
// LocalAddr used for connection
LocalAddr() net.Addr
// WriteMsg marshals message and sends to socket
WriteMsg(msg sip.Message) error
// Reference of connection can be increased/decreased to prevent closing to earlyss
Ref(i int) int
// Close decreases reference and if ref = 0 closes connection. Returns last ref. If 0 then it is closed
TryClose() (int, error)
Close() error
}
type ConnectionPool ¶
type ConnectionPool struct {
// TODO consider sync.Map way with atomic checks to reduce mutex contention
sync.RWMutex
// contains filtered or unexported fields
}
func NewConnectionPool ¶
func NewConnectionPool() ConnectionPool
func (*ConnectionPool) Add ¶
func (p *ConnectionPool) Add(a string, c Connection)
func (*ConnectionPool) Clear ¶ added in v0.13.0
func (p *ConnectionPool) Clear()
Clear will clear all connection from pool and close them
func (*ConnectionPool) CloseAndDelete ¶ added in v0.12.1
func (p *ConnectionPool) CloseAndDelete(c Connection, addr string)
CloseAndDelete closes connection and deletes from pool
func (*ConnectionPool) Get ¶
func (p *ConnectionPool) Get(a string) (c Connection)
Getting connection pool increases reference Make sure you TryClose after finish
func (*ConnectionPool) Size ¶ added in v0.10.0
func (p *ConnectionPool) Size() int
type Layer ¶
type Layer struct {
// ConnectionReuse will force connection reuse when passing request
ConnectionReuse bool
// contains filtered or unexported fields
}
Layer implementation.
func NewLayer ¶
NewLayer creates transport layer. dns Resolver sip parser tls config - can be nil to use default tls
func (*Layer) ClientRequestConnection ¶
func (l *Layer) ClientRequestConnection(ctx context.Context, req *sip.Request) (c Connection, err error)
ClientRequestConnection is based on https://www.rfc-editor.org/rfc/rfc3261#section-18.1.1 It is wrapper for getting and creating connection
In case req destination is DNS resolved, destination will be cached or in other words SetDestination will be called
func (*Layer) GetConnection ¶
func (l *Layer) GetConnection(network, addr string) (Connection, error)
GetConnection gets existing or creates new connection based on addr
func (*Layer) GetListenPort ¶ added in v0.13.0
func (*Layer) OnMessage ¶
func (l *Layer) OnMessage(h sip.MessageHandler)
OnMessage is main function which will be called on any new message by transport layer
func (*Layer) ServeUDP ¶
func (l *Layer) ServeUDP(c net.PacketConn) error
ServeUDP will listen on udp connection
type TCPConnection ¶
func (*TCPConnection) Close ¶
func (c *TCPConnection) Close() error
func (*TCPConnection) Ref ¶
func (c *TCPConnection) Ref(i int) int
func (*TCPConnection) TryClose ¶ added in v0.7.0
func (c *TCPConnection) TryClose() (int, error)
type TCPTransport ¶
type TCPTransport struct {
// contains filtered or unexported fields
}
TCP transport implementation
func NewTCPTransport ¶
func NewTCPTransport(par *sip.Parser) *TCPTransport
func (*TCPTransport) Close ¶
func (t *TCPTransport) Close() error
func (*TCPTransport) CreateConnection ¶
func (t *TCPTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
func (*TCPTransport) GetConnection ¶
func (t *TCPTransport) GetConnection(addr string) (Connection, error)
func (*TCPTransport) Network ¶
func (t *TCPTransport) Network() string
func (*TCPTransport) Serve ¶
func (t *TCPTransport) Serve(l net.Listener, handler sip.MessageHandler) error
Serve is direct way to provide conn on which this worker will listen
func (*TCPTransport) String ¶
func (t *TCPTransport) String() string
type TLSTransport ¶ added in v0.7.0
type TLSTransport struct {
*TCPTransport
// contains filtered or unexported fields
}
TLS transport implementation
func NewTLSTransport ¶ added in v0.7.0
func NewTLSTransport(par *sip.Parser, dialTLSConf *tls.Config) *TLSTransport
NewTLSTransport needs dialTLSConf for creating connections when dialing
func (*TLSTransport) CreateConnection ¶ added in v0.7.0
func (t *TLSTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
CreateConnection creates TLS connection for TCP transport
func (*TLSTransport) String ¶ added in v0.7.0
func (t *TLSTransport) String() string
type Transport ¶
type Transport interface {
Network() string
// GetConnection returns connection from transport
// addr must be resolved to IP:port
GetConnection(addr string) (Connection, error)
CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
String() string
Close() error
}
Protocol implements network specific features.
type UDPConnection ¶
type UDPConnection struct {
// mutual exclusive for now
// TODO Refactor
PacketConn net.PacketConn
PacketAddr string // For faster matching
Conn net.Conn
// contains filtered or unexported fields
}
func (*UDPConnection) Close ¶
func (c *UDPConnection) Close() error
func (*UDPConnection) LocalAddr ¶ added in v0.12.1
func (c *UDPConnection) LocalAddr() net.Addr
func (*UDPConnection) Read ¶ added in v0.10.0
func (c *UDPConnection) Read(b []byte) (n int, err error)
func (*UDPConnection) Ref ¶
func (c *UDPConnection) Ref(i int) int
func (*UDPConnection) TryClose ¶ added in v0.7.0
func (c *UDPConnection) TryClose() (int, error)
type UDPTransport ¶
type UDPTransport struct {
// contains filtered or unexported fields
}
UDP transport implementation
func NewUDPTransport ¶
func NewUDPTransport(par *sip.Parser) *UDPTransport
func (*UDPTransport) Close ¶
func (t *UDPTransport) Close() error
func (*UDPTransport) CreateConnection ¶
func (t *UDPTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
CreateConnection will create new connection
func (*UDPTransport) GetConnection ¶
func (t *UDPTransport) GetConnection(addr string) (Connection, error)
GetConnection will return same listener connection
func (*UDPTransport) Network ¶
func (t *UDPTransport) Network() string
func (*UDPTransport) ResolveAddr ¶
func (t *UDPTransport) ResolveAddr(addr string) (net.Addr, error)
func (*UDPTransport) Serve ¶
func (t *UDPTransport) Serve(conn net.PacketConn, handler sip.MessageHandler) error
ServeConn is direct way to provide conn on which this worker will listen UDPReadWorkers are used to create more workers
func (*UDPTransport) String ¶
func (t *UDPTransport) String() string
type WSConnection ¶
func (*WSConnection) Close ¶
func (c *WSConnection) Close() error
func (*WSConnection) Ref ¶
func (c *WSConnection) Ref(i int) int
func (*WSConnection) TryClose ¶ added in v0.7.0
func (c *WSConnection) TryClose() (int, error)
type WSSTransport ¶ added in v0.12.0
type WSSTransport struct {
*WSTransport
}
TLS transport implementation
func NewWSSTransport ¶ added in v0.12.0
func NewWSSTransport(par *sip.Parser, dialTLSConf *tls.Config) *WSSTransport
NewWSSTransport needs dialTLSConf for creating connections when dialing
func (*WSSTransport) CreateConnection ¶ added in v0.12.0
func (t *WSSTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
CreateConnection creates WSS connection for TCP transport TODO Make this consisten with TCP
func (*WSSTransport) String ¶ added in v0.12.0
func (t *WSSTransport) String() string
type WSTransport ¶
type WSTransport struct {
// contains filtered or unexported fields
}
WS transport implementation
func NewWSTransport ¶
func NewWSTransport(par *sip.Parser) *WSTransport
func (*WSTransport) Close ¶
func (t *WSTransport) Close() error
func (*WSTransport) CreateConnection ¶
func (t *WSTransport) CreateConnection(ctx context.Context, laddr Addr, raddr Addr, handler sip.MessageHandler) (Connection, error)
func (*WSTransport) GetConnection ¶
func (t *WSTransport) GetConnection(addr string) (Connection, error)
func (*WSTransport) Network ¶
func (t *WSTransport) Network() string
func (*WSTransport) ResolveAddr ¶
func (t *WSTransport) ResolveAddr(addr string) (net.Addr, error)
func (*WSTransport) Serve ¶
func (t *WSTransport) Serve(l net.Listener, handler sip.MessageHandler) error
Serve is direct way to provide conn on which this worker will listen
func (*WSTransport) String ¶
func (t *WSTransport) String() string