gateway

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gateway wires stack + transaction + uas (+ optional outbound) into a runnable SIP server.

UDP UAS (gateway.UAS)

Open()
  → stack.NewEndpoint (async handlers, OnSIPResponse → outbound + transaction)
  → uas.Handlers.AttachWithTransaction (INVITE/BYE/CANCEL/ACK + server tx)
Serve(ctx)
  → read loop: parse → dispatch → send response → OnResponseSent → BeginInviteServer

Bidirectional endpoint (gateway.Endpoint)

Same UDP socket for inbound UAS and outbound UAC:

ep := gateway.NewEndpoint(gateway.EndpointConfig{...})
ep.Open()   // UAS listen + outbound.BindSender(sharedSender)
ep.Dial()   // outbound INVITE; responses hit OnSIPResponse → outbound.HandleSIPResponse

TCP/TLS (gateway.StartTCPListeners)

Accepts connections, reads stack.ReadMessage frames, calls ep.DispatchRequest, writes responses on the TCP conn, then ep.NotifyResponseDelivered (same OnResponseSent hooks as UDP).

SDP helpers (invite.go)

  • Ringing / InviteAnswer — build 180/200 with dialog tags, SDP answer, and Contact on the actual signaling port (UAS.SIPPort())
  • PickCodec — choose codec from offer

Pure signaling only; attach protocol/sipmedia/session for RTP/voice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InviteAnswer

func InviteAnswer(req *stack.Message, localIP string, localSIPPort, 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. localSIPPort is the signaling Contact port (defaults to 5060 when <= 0).

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 SignalingShell added in v1.4.3

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

SignalingShell is the shared UDP signaling core used by gateway.UAS and VoiceServer SIPServer: one stack.Endpoint + transaction.Manager without pre-registered uas.Handlers (callers register their own methods).

func NewSignalingShell added in v1.4.3

func NewSignalingShell(cfg SignalingShellConfig) *SignalingShell

NewSignalingShell builds the endpoint (handlers can be registered before Open).

func (*SignalingShell) Close added in v1.4.3

func (s *SignalingShell) Close() error

Close shuts down the UDP socket.

func (*SignalingShell) Endpoint added in v1.4.3

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

Endpoint returns the stack endpoint after Open.

func (*SignalingShell) ListenAddr added in v1.4.3

func (s *SignalingShell) ListenAddr() net.Addr

ListenAddr returns the bound UDP address.

func (*SignalingShell) LocalIP added in v1.4.3

func (s *SignalingShell) LocalIP() string

LocalIP returns the configured or detected signaling IP.

func (*SignalingShell) Open added in v1.4.3

func (s *SignalingShell) Open() error

Open binds the UDP socket.

func (*SignalingShell) SIPPort added in v1.4.3

func (s *SignalingShell) SIPPort() int

SIPPort returns the configured or bound signaling port.

func (*SignalingShell) Send added in v1.4.3

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

Send writes on the bound UDP socket.

func (*SignalingShell) Serve added in v1.4.3

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

Serve runs the UDP read loop until ctx is cancelled.

func (*SignalingShell) TxManager added in v1.4.3

func (s *SignalingShell) TxManager() *transaction.Manager

TxManager returns the transaction manager.

type SignalingShellConfig added in v1.4.3

type SignalingShellConfig struct {
	UASConfig
	Hooks stack.EndpointConfig
}

SignalingShellConfig wires listen addresses and stack.Endpoint callbacks. Host/Port/LocalIP come from UASConfig; other EndpointConfig fields (OnSIPResponse, OnEvent, OnMessageSent, …) are copied from Hooks.

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) SIPPort added in v1.4.3

func (s *UAS) SIPPort() int

SIPPort returns the configured or bound UDP signaling port.

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