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 ¶
- func InviteAnswer(req *stack.Message, localIP string, localSIPPort, localRTPPort int, ...) (*stack.Message, *dialog.Dialog, error)
- func NewTag() string
- func PickCodec(offer *sdp.Info, prefer ...string) (sdp.Codec, bool)
- func Ringing(req *stack.Message, localTag string) (*stack.Message, error)
- func StartTCPListeners(ctx context.Context, ep *stack.Endpoint, cfg TCPListenerConfig) error
- type Endpoint
- func (e *Endpoint) Cancel(callID string) error
- func (e *Endpoint) Close() error
- func (e *Endpoint) Dial(ctx context.Context, req outbound.DialRequest) (string, error)
- func (e *Endpoint) Hangup(callID string) error
- func (e *Endpoint) LocalIP() string
- func (e *Endpoint) Open() error
- func (e *Endpoint) Outbound() *outbound.Manager
- func (e *Endpoint) Serve(ctx context.Context) error
- func (e *Endpoint) UAS() *UAS
- type EndpointConfig
- type SignalingShell
- func (s *SignalingShell) Close() error
- func (s *SignalingShell) Endpoint() *stack.Endpoint
- func (s *SignalingShell) ListenAddr() net.Addr
- func (s *SignalingShell) LocalIP() string
- func (s *SignalingShell) Open() error
- func (s *SignalingShell) SIPPort() int
- func (s *SignalingShell) Send(msg *stack.Message, addr *net.UDPAddr) error
- func (s *SignalingShell) Serve(ctx context.Context) error
- func (s *SignalingShell) TxManager() *transaction.Manager
- type SignalingShellConfig
- type TCPListenerConfig
- type UAS
- func (s *UAS) AttachOutbound(m *outbound.Manager)
- func (s *UAS) Close() error
- func (s *UAS) Endpoint() *stack.Endpoint
- func (s *UAS) LocalIP() string
- func (s *UAS) Manager() *transaction.Manager
- func (s *UAS) Open() error
- func (s *UAS) SIPPort() int
- func (s *UAS) Send(msg *stack.Message, addr *net.UDPAddr) error
- func (s *UAS) Serve(ctx context.Context) error
- type UASConfig
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 PickCodec ¶
PickCodec chooses the first codec from offer matching a preferred name list. When no preference matches, the first offered codec is returned.
func StartTCPListeners ¶
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.
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) 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 (*UAS) AttachOutbound ¶
AttachOutbound wires outbound response handling and shared Send on this UAS socket.
func (*UAS) Manager ¶
func (s *UAS) Manager() *transaction.Manager
Manager returns the transaction manager (for advanced wiring or tests).
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.