transport

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
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"
)

Variables

View Source
var (
	// UDPReadWorkers defines how many listeners will work
	// Best performance is achieved with low value, to remove high concurency
	UDPReadWorkers int = 1

	UDPbufferSize uint16 = 65535
)
View Source
var (
	ErrNetworkExists = errors.New("network is already served")
)
View Source
var (
	SIPDebug bool
)

Functions

func IsReliable

func IsReliable(network string) bool

func IsStreamed

func IsStreamed(network string) bool

func NetworkToLower

func NetworkToLower(network string) string

NetworkToLower is faster function converting UDP, TCP to udp, tcp

Types

type Conn

type Conn struct {
	net.Conn
}

func (*Conn) Ref

func (c *Conn) Ref(i int)

func (*Conn) String

func (c *Conn) String() string

func (*Conn) WriteMsg

func (c *Conn) WriteMsg(msg sip.Message) error

func (*Conn) WriteMsgTo

func (c *Conn) WriteMsgTo(msg sip.Message, raddr string) error

type Connection

type Connection interface {
	// 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)
	// Close decreases reference and if ref = 0 closes connection
	Close() error
}

type ConnectionPool

type ConnectionPool struct {
	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) Del

func (p *ConnectionPool) Del(a string)

func (*ConnectionPool) Get

func (p *ConnectionPool) Get(a string) (c Connection)

type Layer

type Layer struct {
	ConnectionReuse bool
	// contains filtered or unexported fields
}

Layer implementation.

func NewLayer

func NewLayer(
	dnsResolver *net.Resolver,
) *Layer

NewLayer creates transport layer. hostAddr - address of host dns Resolver

func (*Layer) ClientRequestConnection

func (l *Layer) ClientRequestConnection(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

func (*Layer) Close

func (l *Layer) Close() error

func (*Layer) CreateConnection

func (l *Layer) CreateConnection(network, addr string) (Connection, error)

func (*Layer) GetConnection

func (l *Layer) GetConnection(network, addr string) (Connection, error)

GetConnection gets existing or creates new connection based on addr

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) Serve

func (l *Layer) Serve(ctx context.Context, network string, addr string) error

Serve on any network. This function will block

func (*Layer) ServeTCP

func (l *Layer) ServeTCP(c net.Listener) error

ServeTCP will listen on tcp connection

func (*Layer) ServeUDP

func (l *Layer) ServeUDP(c net.PacketConn) error

ServeUDP will listen on udp connection

func (*Layer) ServeWS

func (l *Layer) ServeWS(c net.Listener) error

ServeWS will listen on ws connection

func (*Layer) WriteMsg

func (l *Layer) WriteMsg(msg sip.Message) error

func (*Layer) WriteMsgTo

func (l *Layer) WriteMsgTo(msg sip.Message, addr string, network string) error

type TCPConnection

type TCPConnection struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*TCPConnection) Close

func (c *TCPConnection) Close() error

func (*TCPConnection) Read

func (c *TCPConnection) Read(b []byte) (n int, err error)

func (*TCPConnection) Ref

func (c *TCPConnection) Ref(i int)

func (*TCPConnection) Write

func (c *TCPConnection) Write(b []byte) (n int, err error)

func (*TCPConnection) WriteMsg

func (c *TCPConnection) WriteMsg(msg sip.Message) error

type TCPPool

type TCPPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewTCPPool

func NewTCPPool() TCPPool

func (*TCPPool) Add

func (p *TCPPool) Add(a string, c *net.TCPConn)

func (*TCPPool) Del

func (p *TCPPool) Del(a string)

func (*TCPPool) Get

func (p *TCPPool) Get(a string) (c *net.TCPConn)

type TCPTransport

type TCPTransport struct {
	// contains filtered or unexported fields
}

TCP transport implementation

func NewTCPTransport

func NewTCPTransport(addr string, par parser.SIPParser) *TCPTransport

func (*TCPTransport) Accept

func (t *TCPTransport) Accept() error

func (*TCPTransport) Addr

func (t *TCPTransport) Addr() string

func (*TCPTransport) Close

func (t *TCPTransport) Close() error

func (*TCPTransport) CreateConnection

func (t *TCPTransport) CreateConnection(addr string) (Connection, error)

func (*TCPTransport) GetConnection

func (t *TCPTransport) GetConnection(addr string) (Connection, error)

func (*TCPTransport) Network

func (t *TCPTransport) Network() string

func (*TCPTransport) ResolveAddr

func (t *TCPTransport) ResolveAddr(addr string) (net.Addr, error)

func (*TCPTransport) Serve

func (t *TCPTransport) Serve(handler sip.MessageHandler) error

TODO This is more generic way to provide listener and it is blocking

func (*TCPTransport) ServeConn

func (t *TCPTransport) ServeConn(l net.Listener, 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 (*TCPTransport) String

func (t *TCPTransport) String() string

type Transport

type Transport interface {
	Addr() string
	Network() string
	Serve(handler sip.MessageHandler) error
	ResolveAddr(addr string) (net.Addr, error)
	GetConnection(addr string) (Connection, error)
	CreateConnection(addr string) (Connection, error)
	String() string
	Close() error
}

Protocol implements network specific features.

type UDPConnection

type UDPConnection struct {
	net.PacketConn
}

func (*UDPConnection) Close

func (c *UDPConnection) Close() error

func (*UDPConnection) Ref

func (c *UDPConnection) Ref(i int)

func (*UDPConnection) WriteMsg

func (c *UDPConnection) WriteMsg(msg sip.Message) error

type UDPTransport

type UDPTransport struct {
	// contains filtered or unexported fields
}

UDP transport implementation

func NewUDPTransport

func NewUDPTransport(addr string, par parser.SIPParser) *UDPTransport

func (*UDPTransport) Addr

func (t *UDPTransport) Addr() string

func (*UDPTransport) Close

func (t *UDPTransport) Close() error

func (*UDPTransport) CreateConnection

func (t *UDPTransport) CreateConnection(addr string) (Connection, error)

CreateConnection will return same listener 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(handler sip.MessageHandler) error

TODO This is more generic way to provide listener and it is blocking

func (*UDPTransport) ServeConn

func (t *UDPTransport) ServeConn(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

type WSConnection struct {
	net.Conn
	// contains filtered or unexported fields
}

func (*WSConnection) Close

func (c *WSConnection) Close() error

func (*WSConnection) Read

func (c *WSConnection) Read(b []byte) (n int, err error)

func (*WSConnection) Ref

func (c *WSConnection) Ref(i int)

func (*WSConnection) Write

func (c *WSConnection) Write(b []byte) (n int, err error)

func (*WSConnection) WriteMsg

func (c *WSConnection) WriteMsg(msg sip.Message) error

type WSTransport

type WSTransport struct {
	// contains filtered or unexported fields
}

WS transport implementation

func NewWSTransport

func NewWSTransport(addr string, par parser.SIPParser) *WSTransport

func (*WSTransport) Accept

func (t *WSTransport) Accept() error

func (*WSTransport) Addr

func (t *WSTransport) Addr() string

func (*WSTransport) Close

func (t *WSTransport) Close() error

func (*WSTransport) CreateConnection

func (t *WSTransport) CreateConnection(addr string) (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(handler sip.MessageHandler) error

This is more generic way to provide listener and it is blocking

func (*WSTransport) ServeConn

func (t *WSTransport) ServeConn(l net.Listener, 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 (*WSTransport) String

func (t *WSTransport) String() string

Jump to

Keyboard shortcuts

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