gateway

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package gateway wires the pure SIP stack (stack + transaction + uas) into a ready-to-run UDP UAS with logrus logging. Pure signaling — import protocol/sipmedia separately when RTP/voice is needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InviteAnswer

func InviteAnswer(req *stack.Message, localIP string, localRTPPort int, codec sdp.Codec, localTag string) (*stack.Message, *dialog.Dialog, error)

InviteAnswer builds a 200 OK INVITE response with an SDP answer and UAS To tag.

func NewTag

func NewTag() string

NewTag returns a random SIP dialog tag (RFC 3261 style).

func PickCodec

func PickCodec(offer *sdp.Info, prefer ...string) (sdp.Codec, bool)

PickCodec chooses the first codec from offer matching a preferred name list. When no preference matches, the first offered codec is returned.

func Ringing

func Ringing(req *stack.Message, localTag string) (*stack.Message, error)

Ringing builds a 180 Ringing provisional response with UAS To tag.

func StartTCPListeners

func StartTCPListeners(ctx context.Context, ep *stack.Endpoint, cfg TCPListenerConfig) error

StartTCPListeners starts background TCP/TLS accept loops until ctx is cancelled. Requests are dispatched via ep.DispatchRequest; responses use the same transaction handlers as UDP.

Types

type Endpoint

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

Endpoint is a bidirectional SIP signaling endpoint (UAS + UAC).

func NewEndpoint

func NewEndpoint(cfg EndpointConfig) *Endpoint

NewEndpoint builds a combined signaling endpoint.

func (*Endpoint) Cancel

func (e *Endpoint) Cancel(callID string) error

Cancel sends CANCEL for a ringing outbound leg.

func (*Endpoint) Close

func (e *Endpoint) Close() error

Close shuts down UDP and outbound connection pool.

func (*Endpoint) Dial

func (e *Endpoint) Dial(ctx context.Context, req outbound.DialRequest) (string, error)

Dial starts an outbound INVITE using the shared socket.

func (*Endpoint) Hangup

func (e *Endpoint) Hangup(callID string) error

Hangup sends BYE for an established outbound leg.

func (*Endpoint) LocalIP

func (e *Endpoint) LocalIP() string

LocalIP returns the SDP/signaling local IP.

func (*Endpoint) Open

func (e *Endpoint) Open() error

Open binds UDP and wires outbound send on the shared socket.

func (*Endpoint) Outbound

func (e *Endpoint) Outbound() *outbound.Manager

Outbound returns the outbound manager.

func (*Endpoint) Serve

func (e *Endpoint) Serve(ctx context.Context) error

Serve runs the UDP read loop until ctx is cancelled.

func (*Endpoint) UAS

func (e *Endpoint) UAS() *UAS

UAS returns the inbound server wrapper.

type EndpointConfig

type EndpointConfig struct {
	UASConfig
	Outbound outbound.ManagerConfig
}

EndpointConfig combines inbound UAS and outbound UAC on one UDP socket.

type TCPListenerConfig

type TCPListenerConfig struct {
	// TCPAddr is host:port for plain TCP (empty = disabled).
	TCPAddr string
	// TLSAddr is host:port for TLS (empty = disabled).
	TLSAddr string
	TLSCert string
	TLSKey  string
}

TCPListenerConfig configures optional SIP-over-TCP / TLS listeners sharing UAS handlers.

type UAS

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

UAS is a minimal inbound SIP server on UDP.

func NewUAS

func NewUAS(cfg UASConfig) *UAS

NewUAS builds a server; call Open before Serve.

func (*UAS) AttachOutbound

func (s *UAS) AttachOutbound(m *outbound.Manager)

AttachOutbound wires outbound response handling and shared Send on this UAS socket.

func (*UAS) Close

func (s *UAS) Close() error

Close shuts down the UDP socket.

func (*UAS) Endpoint

func (s *UAS) Endpoint() *stack.Endpoint

Endpoint returns the underlying stack endpoint after Open.

func (*UAS) LocalIP

func (s *UAS) LocalIP() string

LocalIP returns the configured or detected IPv4 used in SDP answers.

func (*UAS) Manager

func (s *UAS) Manager() *transaction.Manager

Manager returns the transaction manager (for advanced wiring or tests).

func (*UAS) Open

func (s *UAS) Open() error

Open binds the UDP socket and registers handlers.

func (*UAS) Send

func (s *UAS) Send(msg *stack.Message, addr *net.UDPAddr) error

Send writes a SIP message to addr on the bound UDP socket.

func (*UAS) Serve

func (s *UAS) Serve(ctx context.Context) error

Serve runs until ctx is cancelled or a fatal read error occurs.

type UASConfig

type UASConfig struct {
	Host string // listen IP, default 0.0.0.0
	Port int    // UDP port, default 5060

	// Handlers are chained through the transaction layer (retransmissions, CANCEL, ACK).
	Handlers uas.Handlers

	// LocalIP is advertised in generated SDP answers when empty gateway picks the UDP bind address.
	LocalIP string
}

UASConfig configures a UDP SIP user agent server.

Jump to

Keyboard shortcuts

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