Documentation
¶
Index ¶
- Variables
- func ClientRequestAddRecordRoute(c *Client, r *sip.Request) error
- func ClientRequestAddVia(c *Client, r *sip.Request) error
- func ClientRequestBuild(c *Client, r *sip.Request) error
- func ClientRequestDecreaseMaxForward(c *Client, r *sip.Request) error
- func ClientRequestIncreaseCSEQ(c *Client, req *sip.Request) error
- func ClientRequestRegisterBuild(c *Client, r *sip.Request) error
- func Init()
- type AnswerOptions
- type Client
- func (c *Client) Close() error
- func (c *Client) Do(ctx context.Context, req *sip.Request, opts ...ClientRequestOption) (*sip.Response, error)
- func (c *Client) DoDigestAuth(ctx context.Context, req *sip.Request, res *sip.Response, auth DigestAuth) (*sip.Response, error)
- func (c *Client) Hostname() string
- func (c *Client) TransactionDigestAuth(ctx context.Context, req *sip.Request, res *sip.Response, auth DigestAuth) (sip.ClientTransaction, error)
- func (c *Client) TransactionRequest(ctx context.Context, req *sip.Request, options ...ClientRequestOption) (sip.ClientTransaction, error)
- func (c *Client) WriteRequest(req *sip.Request, options ...ClientRequestOption) error
- func (c *Client) WriteRequestContext(ctx context.Context, req *sip.Request, options ...ClientRequestOption) error
- type ClientOption
- type ClientRequestOption
- type ClientTransactionRequester
- type Dialog
- func (d *Dialog) CSEQ() uint32
- func (d *Dialog) Context() context.Context
- func (d *Dialog) Init()
- func (d *Dialog) InitWithState(s sip.DialogState)
- func (d *Dialog) LoadState() sip.DialogState
- func (d *Dialog) OnState(f DialogStateFn)
- func (d *Dialog) ReadRequest(req *sip.Request, tx sip.ServerTransaction) error
- func (d *Dialog) StateRead() <-chan sip.DialogState
- type DialogClientCache
- func (c *DialogClientCache) Invite(ctx context.Context, recipient sip.Uri, body []byte, headers ...sip.Header) (*DialogClientSession, error)
- func (s *DialogClientCache) MatchRequestDialog(req *sip.Request) (*DialogClientSession, error)
- func (c *DialogClientCache) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
- func (c *DialogClientCache) WriteInvite(ctx context.Context, inviteRequest *sip.Request) (*DialogClientSession, error)
- type DialogClientSession
- func (s *DialogClientSession) Ack(ctx context.Context) error
- func (s *DialogClientSession) Bye(ctx context.Context) error
- func (s *DialogClientSession) Close() error
- func (s *DialogClientSession) Do(ctx context.Context, req *sip.Request) (*sip.Response, error)
- func (d *DialogClientSession) Invite(ctx context.Context, options ...ClientRequestOption) error
- func (s *DialogClientSession) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
- func (s *DialogClientSession) TransactionRequest(ctx context.Context, req *sip.Request) (sip.ClientTransaction, error)
- func (s *DialogClientSession) WaitAnswer(ctx context.Context, opts AnswerOptions) error
- func (s *DialogClientSession) WaitAnswerWithCancel(ctx context.Context, answer AnswerOptions, policy InviteCancelPolicy) error
- func (s *DialogClientSession) WriteAck(ctx context.Context, ack *sip.Request) error
- func (s *DialogClientSession) WriteBye(ctx context.Context, bye *sip.Request) error
- func (s *DialogClientSession) WriteRequest(req *sip.Request) error
- func (s *DialogClientSession) WriteRequestContext(ctx context.Context, req *sip.Request) error
- type DialogServerCache
- func (s *DialogServerCache) MatchDialogRequest(req *sip.Request) (*DialogServerSession, error)
- func (s *DialogServerCache) ReadAck(req *sip.Request, tx sip.ServerTransaction) error
- func (s *DialogServerCache) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
- func (s *DialogServerCache) ReadInvite(req *sip.Request, tx sip.ServerTransaction) (*DialogServerSession, error)
- type DialogServerSession
- func (s *DialogServerSession) Bye(ctx context.Context) error
- func (s *DialogServerSession) Close() error
- func (s *DialogServerSession) Do(ctx context.Context, req *sip.Request) (*sip.Response, error)
- func (s *DialogServerSession) ReadAck(req *sip.Request, tx sip.ServerTransaction) error
- func (s *DialogServerSession) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
- func (s *DialogServerSession) Respond(statusCode int, reason string, body []byte, headers ...sip.Header) error
- func (s *DialogServerSession) RespondSDP(sdp []byte) error
- func (s *DialogServerSession) TransactionRequest(ctx context.Context, req *sip.Request) (sip.ClientTransaction, error)
- func (s *DialogServerSession) WriteBye(ctx context.Context, bye *sip.Request) error
- func (s *DialogServerSession) WriteRequest(req *sip.Request) error
- func (s *DialogServerSession) WriteResponse(res *sip.Response) error
- type DialogStateFn
- type DialogUA
- func (ua *DialogUA) Invite(ctx context.Context, recipient sip.Uri, body []byte, headers ...sip.Header) (*DialogClientSession, error)
- func (c *DialogUA) ReadInvite(inviteRequest *sip.Request, tx sip.ServerTransaction) (*DialogServerSession, error)
- func (c *DialogUA) WriteInvite(ctx context.Context, inviteReq *sip.Request, options ...ClientRequestOption) (*DialogClientSession, error)
- type DigestAuth
- type ErrDialogResponse
- type InviteCancelPolicy
- type ListenReadyCtxValue
- type ListenReadyFuncCtxValue
- type RequestHandler
- type Server
- func (srv *Server) Close() error
- func (srv *Server) ListenAndServe(ctx context.Context, network string, addr string) error
- func (srv *Server) ListenAndServeTLS(ctx context.Context, network string, addr string, conf *tls.Config) error
- func (srv *Server) OnAck(handler RequestHandler)
- func (srv *Server) OnBye(handler RequestHandler)
- func (srv *Server) OnCancel(handler RequestHandler)
- func (srv *Server) OnInfo(handler RequestHandler)
- func (srv *Server) OnInvite(handler RequestHandler)
- func (srv *Server) OnMessage(handler RequestHandler)
- func (srv *Server) OnNoRoute(handler RequestHandler)
- func (srv *Server) OnNotify(handler RequestHandler)
- func (srv *Server) OnOptions(handler RequestHandler)
- func (srv *Server) OnPrack(handler RequestHandler)
- func (srv *Server) OnPublish(handler RequestHandler)
- func (srv *Server) OnRefer(handler RequestHandler)
- func (srv *Server) OnRegister(handler RequestHandler)
- func (srv *Server) OnRequest(method sip.RequestMethod, handler RequestHandler)
- func (srv *Server) OnSubscribe(handler RequestHandler)
- func (srv *Server) OnUpdate(handler RequestHandler)
- func (srv *Server) RegisteredMethods() []string
- func (srv *Server) ServeTCP(l net.Listener) error
- func (srv *Server) ServeTLS(l net.Listener) error
- func (srv *Server) ServeUDP(l net.PacketConn) error
- func (srv *Server) ServeWS(l net.Listener) error
- func (srv *Server) ServeWSS(l net.Listener) error
- func (srv *Server) TransportLayer() *sip.TransportLayer
- func (srv *Server) WriteResponse(r *sip.Response) error
- func (srv *Server) WriteResponseContext(ctx context.Context, r *sip.Response) error
- type ServerOption
- type UserAgent
- type UserAgentOption
- func WithUserAgenTLSConfig(c *tls.Config) UserAgentOption
- func WithUserAgent(ua string) UserAgentOption
- func WithUserAgentDNSResolver(r *net.Resolver) UserAgentOption
- func WithUserAgentHostname(hostname string) UserAgentOption
- func WithUserAgentParser(p *sip.Parser) UserAgentOption
- func WithUserAgentReliableWriteTimeout(timeout time.Duration) UserAgentOption
- func WithUserAgentTransactionLayerOptions(o ...sip.TransactionLayerOption) UserAgentOption
- func WithUserAgentTransportLayerOptions(o ...sip.TransportLayerOption) UserAgentOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrDialogOutsideDialog = errors.New("Call/Transaction Outside Dialog") ErrDialogDoesNotExists = errors.New("Call/Transaction Does Not Exist") ErrDialogInviteNoContact = errors.New("no Contact header") ErrDialogInvalidCseq = errors.New("invalid CSEQ number") )
var ( // Used only for testing, better way is to pass listener with Serve{Transport} ListenReadyCtxKey = "ListenReadyCtxKey" // ListenRegisteredCtxKey is fired after the listener socket has been // registered in the transport connection pool and its receive loop is // equipped, so the bound connection is reusable by the client. // ListenReadyCtxKey only proves the socket was bound and keeps its old // semantics; this key is currently emitted only for UDP and MUST be // delivered without blocking the serving goroutine. ListenRegisteredCtxKey = "ListenRegisteredCtxKey" )
var ErrInviteCancelPolicy = errors.New("invite cancel policy timeouts must be positive")
ErrInviteCancelPolicy is returned by WaitAnswerWithCancel for a policy with a non-positive timeout.
var ErrUserAgentReliableWriteTimeout = errors.New("reliable write timeout must be positive")
ErrUserAgentReliableWriteTimeout is returned by WithUserAgentReliableWriteTimeout for a non-positive timeout. There is no "0 means unlimited" contract: enabling the protection always requires a positive budget, and not passing the option leaves the legacy behavior.
var (
WaitAnswerForceCancelErr = errors.New("Context cancel forced")
)
Functions ¶
func ClientRequestAddRecordRoute ¶
ClientRequestAddRecordRoute is option for adding record route header Based on proxy setup https://www.rfc-editor.org/rfc/rfc3261#section-16
func ClientRequestAddVia ¶
ClientRequestAddVia is option for adding via header Based on proxy setup https://www.rfc-editor.org/rfc/rfc3261.html#section-16.6
func ClientRequestBuild ¶
ClientRequestBuild will build missing fields in request This is by default but can be used to combine with other ClientRequestOptions
func ClientRequestDecreaseMaxForward ¶
Based on proxy setup https://www.rfc-editor.org/rfc/rfc3261#section-16 ClientRequestDecreaseMaxForward should be used when forwarding request. It decreases max forward in case of 0 it returnes error
func ClientRequestRegisterBuild ¶
ClientRequestRegisterBuild builds correctly REGISTER request based on RFC Whenever you send REGISTER request you should pass this option https://datatracker.ietf.org/doc/html/rfc3261#section-10.2
Experimental
Types ¶
type AnswerOptions ¶
type Client ¶
type Client struct {
*UserAgent
// TxRequester allows you to use your transaction requester instead default from transaction layer
// Useful only for testing
//
// Experimental
TxRequester ClientTransactionRequester
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(ua *UserAgent, options ...ClientOption) (*Client, error)
NewClient creates client handle for user agent
func (*Client) Close ¶
Close client handle. UserAgent must be closed for full transaction and transport layer closing.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, req *sip.Request, opts ...ClientRequestOption) (*sip.Response, error)
Do request is HTTP client like Do request/response. It returns on final response. NOTE: Canceling ctx WILL not send Cancel Request which is needed for INVITE. Use dialog API for dealing with dialogs For more lower API use TransactionRequest directly
func (*Client) DoDigestAuth ¶
func (c *Client) DoDigestAuth(ctx context.Context, req *sip.Request, res *sip.Response, auth DigestAuth) (*sip.Response, error)
DoDigestAuth will apply digest authentication if initial request is chalenged by 401 or 407.
func (*Client) TransactionDigestAuth ¶
func (c *Client) TransactionDigestAuth(ctx context.Context, req *sip.Request, res *sip.Response, auth DigestAuth) (sip.ClientTransaction, error)
TransactionDigestAuth will apply digest authentication if initial request is chalenged by 401 or 407. It returns new transaction that is created for this request
func (*Client) TransactionRequest ¶
func (c *Client) TransactionRequest(ctx context.Context, req *sip.Request, options ...ClientRequestOption) (sip.ClientTransaction, error)
TransactionRequest uses transaction layer to send request and returns transaction For more correct behavior use client.Do instead which acts same like HTTP req/response
NOTE RACE: By default request will not be cloned and it will populate request with missing headers and data unless options are used In most cases you want this as you will retry with additional headers For other cases call Request.Clone() before doing transaction request
Following header fields will be added if not exist to have correct SIP request: To, From, CSeq, Call-ID, Max-Forwards, Via Passing options will override this behavior, that is, it is expected that your request is already prebuild This is mostly the case when creating proxy
func (*Client) WriteRequest ¶
func (c *Client) WriteRequest(req *sip.Request, options ...ClientRequestOption) error
WriteRequest sends request directly to transport layer Behavior is same as TransactionRequest Non-transaction ACK request should be passed like this
func (*Client) WriteRequestContext ¶ added in v1.5.0
func (c *Client) WriteRequestContext(ctx context.Context, req *sip.Request, options ...ClientRequestOption) error
WriteRequestContext is WriteRequest with a caller context. On TCP/TLS the write honors ctx: while queued it returns without touching a healthy connection, and once the write started ctx expiry unblocks it (hard-closing that exact connection) before returning.
type ClientOption ¶
func WithClientAddr ¶
func WithClientAddr(addr string) ClientOption
WithClientAddr is merge of WithClientHostname and WithClientPort addr is format <host>:<port>
func WithClientConnectionAddr ¶
func WithClientConnectionAddr(hostPort string) ClientOption
WithClientConnectionAddr forces request to send connection with this local addr. This is useful when you need to act as client first and avoid creating server handle listeners.
func WithClientHostname ¶
func WithClientHostname(hostname string) ClientOption
WithClientHost allows setting default route host or IP on Via NOTE: From header hostname is WithUserAgentHostname option on UA or modify request manually
func WithClientLogger ¶
func WithClientLogger(logger *slog.Logger) ClientOption
WithClientLogger allows customizing client logger
func WithClientNAT ¶
func WithClientNAT() ClientOption
WithClientNAT makes client aware that is behind NAT.
func WithClientPort ¶
func WithClientPort(port int) ClientOption
WithClientPort allows setting default route Via port TransportLayer.ConnectionReuse is set to false default: ephemeral port
type Dialog ¶
type Dialog struct {
ID string
// InviteRequest is set when dialog is created. It is not thread safe!
// Use it only as read only and use methods to change headers
InviteRequest *sip.Request
// InviteResponse is last response received or sent. It is not thread safe!
// Use it only as read only and do not change values
InviteResponse *sip.Response
// contains filtered or unexported fields
}
func (*Dialog) InitWithState ¶
func (d *Dialog) InitWithState(s sip.DialogState)
func (*Dialog) LoadState ¶
func (d *Dialog) LoadState() sip.DialogState
func (*Dialog) OnState ¶
func (d *Dialog) OnState(f DialogStateFn)
func (*Dialog) ReadRequest ¶
func (*Dialog) StateRead ¶
func (d *Dialog) StateRead() <-chan sip.DialogState
type DialogClientCache ¶
type DialogClientCache struct {
// contains filtered or unexported fields
}
func NewDialogClientCache ¶
func NewDialogClientCache(client *Client, contactHDR sip.ContactHeader) *DialogClientCache
NewDialogClientCache provides simple cache layer for managing UAC dialogs. It is generally recomended to build your own cache layer Contact hdr is default to be provided for correct invite. It is not used if you provided hdr as part of request, but contact hdr must be present so this makes sure correct dialog is established. In case handling different transports you should have multiple instances per transport
func (*DialogClientCache) Invite ¶
func (c *DialogClientCache) Invite(ctx context.Context, recipient sip.Uri, body []byte, headers ...sip.Header) (*DialogClientSession, error)
Invite sends INVITE request and creates early dialog session. This is actually not yet dialog (ID is empty) You need to call WaitAnswer after for establishing dialog For passing custom Invite request use WriteInvite
func (*DialogClientCache) MatchRequestDialog ¶
func (s *DialogClientCache) MatchRequestDialog(req *sip.Request) (*DialogClientSession, error)
func (*DialogClientCache) ReadBye ¶
func (c *DialogClientCache) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
func (*DialogClientCache) WriteInvite ¶
func (c *DialogClientCache) WriteInvite(ctx context.Context, inviteRequest *sip.Request) (*DialogClientSession, error)
type DialogClientSession ¶
func (*DialogClientSession) Ack ¶
func (s *DialogClientSession) Ack(ctx context.Context) error
Ack sends ack. Use WriteAck for more customizing
func (*DialogClientSession) Bye ¶
func (s *DialogClientSession) Bye(ctx context.Context) error
Bye sends bye and terminates session. Use WriteBye if you want to customize bye request
func (*DialogClientSession) Close ¶
func (s *DialogClientSession) Close() error
Close must be always called in order to cleanup some internal resources Consider that this will not send BYE or CANCEL or change dialog state
func (*DialogClientSession) Do ¶
Do sends request and waits final response using Dialog rules For more control use TransactionRequest
NOTE: It does not provide INVITE CANCEL as it could be REINVITE Use WaitAnswer when creating initial INVITE to have CANCEL sending.
func (*DialogClientSession) Invite ¶
func (d *DialogClientSession) Invite(ctx context.Context, options ...ClientRequestOption) error
Invite creates transaction and sends invite.
func (*DialogClientSession) ReadBye ¶
func (s *DialogClientSession) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
func (*DialogClientSession) TransactionRequest ¶
func (s *DialogClientSession) TransactionRequest(ctx context.Context, req *sip.Request) (sip.ClientTransaction, error)
TransactionRequest is doing subsequent client DIALOG request based on RFC after initial session (INVITE) setup https://www.rfc-editor.org/rfc/rfc3261#section-12.2.1 This ensures that you have proper request done within dialog. You should avoid setting any Dialog header (cseq, from, to, callid)
func (*DialogClientSession) WaitAnswer ¶
func (s *DialogClientSession) WaitAnswer(ctx context.Context, opts AnswerOptions) error
WaitAnswer waits for success response or returns ErrDialogResponse in case non 2xx Canceling context while waiting 2xx will send Cancel request. It will block until 1xx provisional is not received If Canceling succesfull context.Canceled error is returned Provisional responses are not counted nor bounded: UAS may send any number of them before a final response (RFC 3261 section 13.3.1.1). Once the first provisional is received, the client transaction moves to Proceeding and Timer B is stopped, hence waiting is bounded only by caller's ctx. Callers that need an overall answer deadline must provide a bounded context. Returns errors: - ErrDialogResponse in case non 2xx response - any internal in case waiting answer failed for different reasons
Cancellation here keeps the historical behavior and is only bounded by the wait for the CANCEL result. Callers that need the explicit 5s CANCEL / fixed Timer_B / 5s cleanup contract should use WaitAnswerWithCancel.
func (*DialogClientSession) WaitAnswerWithCancel ¶ added in v1.5.0
func (s *DialogClientSession) WaitAnswerWithCancel(ctx context.Context, answer AnswerOptions, policy InviteCancelPolicy) error
WaitAnswerWithCancel waits for the answer like WaitAnswer, but when ctx ends while the INVITE is still pending it runs the caller-requested protocol teardown under an explicit InviteCancelPolicy instead of the legacy unbounded wait.
The caller states "do not continue this call". The library then:
- keeps consuming the original INVITE under a fixed final-response deadline that repeated 1xx responses can not extend;
- creates at most one CANCEL after a provisional while no final response has been observed, with its own transaction, consumer and deadline;
- joins both consumers and, if the first final is a 2xx, that dialog's product cleanup. After a non-2xx final (including 487), all later forked 2xx cleanup belongs to the UA, not to this wait. Remaining protocol work is joined by UserAgent.Close.
Normal answers are unchanged: the same states, `ErrDialogResponse` for a non-2xx and the same observer callback. On cancellation the returned error still matches ctx (`context.Canceled`/`context.DeadlineExceeded`) and is joined with any CANCEL/initial-cleanup error. Later protocol failures remain owned and logged by the UA. `Close` keeps meaning local cleanup only and never sends BYE or CANCEL.
A final response can race CANCEL submission. A CANCEL 481 is not reported as a cancellation failure when the original INVITE also reached a final response during this teardown; without that evidence it remains an error. UA shutdown stops protocol admission: late 2xx rejected during Close are logged, but ACK delivery after shutdown begins is not guaranteed.
func (*DialogClientSession) WriteRequest ¶
func (s *DialogClientSession) WriteRequest(req *sip.Request) error
func (*DialogClientSession) WriteRequestContext ¶ added in v1.5.0
WriteRequestContext is WriteRequest with a caller context. It is the in-dialog entry point for ACK/BYE and any other subsequent request that must respect a real write budget; on TCP/TLS the write honors ctx.
type DialogServerCache ¶
type DialogServerCache struct {
// contains filtered or unexported fields
}
DialogServerCache serves as quick way to start building dialog server It is not optimized version and it is recomended that you build own dialog caching
func NewDialogServerCache ¶
func NewDialogServerCache(client *Client, contactHDR sip.ContactHeader) *DialogServerCache
NewDialogServerCache provides simple cache layer for managing UAS dialog Contact hdr is default that is provided for responses. Client is needed for termination dialog session In case handling different transports you should have multiple instances per transport
Using DialogUA is now better way for genereting dialogs without caching and giving you as caller whole control of dialog
func (*DialogServerCache) MatchDialogRequest ¶
func (s *DialogServerCache) MatchDialogRequest(req *sip.Request) (*DialogServerSession, error)
func (*DialogServerCache) ReadAck ¶
func (s *DialogServerCache) ReadAck(req *sip.Request, tx sip.ServerTransaction) error
ReadAck should read from your OnAck handler
func (*DialogServerCache) ReadBye ¶
func (s *DialogServerCache) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
ReadBye should read from your OnBye handler. Returns error if it fails
func (*DialogServerCache) ReadInvite ¶
func (s *DialogServerCache) ReadInvite(req *sip.Request, tx sip.ServerTransaction) (*DialogServerSession, error)
ReadInvite should read from your OnInvite handler for which it creates dialog context You need to use DialogServerSession for all further responses Do not forget to add ReadAck and ReadBye for confirming dialog and terminating
type DialogServerSession ¶
type DialogServerSession struct {
Dialog
// contains filtered or unexported fields
}
func (*DialogServerSession) Close ¶
func (s *DialogServerSession) Close() error
Close is always good to call for cleanup or terminating dialog state
func (*DialogServerSession) Do ¶
Do does request response pattern. For more control over transaction use TransactionRequest
func (*DialogServerSession) ReadAck ¶
func (s *DialogServerSession) ReadAck(req *sip.Request, tx sip.ServerTransaction) error
ReadAck changes dialog state to confiremed
func (*DialogServerSession) ReadBye ¶
func (s *DialogServerSession) ReadBye(req *sip.Request, tx sip.ServerTransaction) error
func (*DialogServerSession) Respond ¶
func (s *DialogServerSession) Respond(statusCode int, reason string, body []byte, headers ...sip.Header) error
Respond should be called for Invite request, you may want to call this multiple times like 100 Progress or 180 Ringing 2xx for creating dialog or other code in case failure
In case Cancel request received: ErrDialogCanceled is responded
func (*DialogServerSession) RespondSDP ¶
func (s *DialogServerSession) RespondSDP(sdp []byte) error
RespondSDP is just wrapper to call 200 with SDP. It is better to use this when answering as it provide correct headers
func (*DialogServerSession) TransactionRequest ¶
func (s *DialogServerSession) TransactionRequest(ctx context.Context, req *sip.Request) (sip.ClientTransaction, error)
TransactionRequest is doing client DIALOG request based on RFC https://www.rfc-editor.org/rfc/rfc3261#section-12.2.1 This ensures that you have proper request done within dialog
func (*DialogServerSession) WriteRequest ¶
func (s *DialogServerSession) WriteRequest(req *sip.Request) error
func (*DialogServerSession) WriteResponse ¶
func (s *DialogServerSession) WriteResponse(res *sip.Response) error
WriteResponse allows passing you custom response NOTE: Make sure you have built response based on dialog.InviteRequest which makes sure that dialog ID do match
type DialogStateFn ¶
type DialogStateFn func(s sip.DialogState)
type DialogUA ¶
type DialogUA struct {
// Client (required) is used to build and send subsequent request (CANCEL, BYE)
Client *Client
// ContactHDR (required) is used as default one to build request/response.
// You can pass custom on each request, but in dialog it is required to be present
ContactHDR sip.ContactHeader
// RewriteContact sends request on source IP instead Contact. Should be used when behind NAT.
RewriteContact bool
}
DialogUA defines UserAgent that will be used in controling your dialog. It needs client handle for cancelation or sending more subsequent request during dialog
func (*DialogUA) ReadInvite ¶
func (c *DialogUA) ReadInvite(inviteRequest *sip.Request, tx sip.ServerTransaction) (*DialogServerSession, error)
func (*DialogUA) WriteInvite ¶
func (c *DialogUA) WriteInvite(ctx context.Context, inviteReq *sip.Request, options ...ClientRequestOption) (*DialogClientSession, error)
type DigestAuth ¶
type ErrDialogResponse ¶
func (ErrDialogResponse) Error ¶
func (e ErrDialogResponse) Error() string
type InviteCancelPolicy ¶ added in v1.5.0
type InviteCancelPolicy struct {
// CancelTimeout bounds the CANCEL half as a whole: waiting for a provisional
// response when none was received yet, submitting the CANCEL request and
// consuming the CANCEL final response.
// VoIPGo passes 5s.
CancelTimeout time.Duration
// FinalResponseTimeout is measured once, from the moment the cancellation
// starts, and bounds how long the original INVITE is still consumed
// afterwards. Repeated 1xx responses never extend it.
// VoIPGo passes sip.Timer_B.
FinalResponseTimeout time.Duration
// CleanupTimeout bounds one dialog's initial ACK, retry and logical BYE.
// Duplicates never refresh that deadline. Later retransmissions still get
// bounded ACKs under the separate UA-owned protocol window; a new To-tag
// creates a new dialog with its own cleanup deadline.
// VoIPGo passes 5s.
CleanupTimeout time.Duration
}
InviteCancelPolicy bounds the explicit cancellation of an initial INVITE started with WaitAnswerWithCancel.
The three timeouts are independent on purpose: the CANCEL request has its own transaction and consumer, the original INVITE keeps its own fixed final-response deadline, and each late dialog has its own product cleanup budget. The separate UA-owned protocol window is never extended by them.
Every field must be positive. WaitAnswerWithCancel rejects an invalid policy instead of authorizing an unowned exit of an existing transaction; there is no zero-as-unlimited contract.
type ListenReadyCtxValue ¶
type ListenReadyCtxValue chan struct{}
type ListenReadyFuncCtxValue ¶
type RequestHandler ¶
type RequestHandler func(req *sip.Request, tx sip.ServerTransaction)
RequestHandler is a callback that will be called on the incoming request
type Server ¶
type Server struct {
*UserAgent
// contains filtered or unexported fields
}
Server is a SIP server
func NewServer ¶
func NewServer(ua *UserAgent, options ...ServerOption) (*Server, error)
NewServer creates new instance of SIP server handle. Allows creating server transaction handlers It uses User Agent transport and transaction layer
func (*Server) Close ¶
Close server handle. UserAgent must be closed for full transaction and transport layer closing.
func (*Server) ListenAndServe ¶
Serve will fire all listeners Network supported: udp, tcp, ws
func (*Server) ListenAndServeTLS ¶
func (srv *Server) ListenAndServeTLS(ctx context.Context, network string, addr string, conf *tls.Config) error
Serve will fire all listeners that are secured. Network supported: tls, wss, tcp, tcp4, tcp6, ws, ws4, ws6
func (*Server) OnAck ¶
func (srv *Server) OnAck(handler RequestHandler)
OnAck registers Ack request handler
func (*Server) OnBye ¶
func (srv *Server) OnBye(handler RequestHandler)
OnBye registers Bye request handler
func (*Server) OnCancel ¶
func (srv *Server) OnCancel(handler RequestHandler)
OnCancel registers Cancel request handler
func (*Server) OnInfo ¶
func (srv *Server) OnInfo(handler RequestHandler)
OnInfo registers Info request handler
func (*Server) OnInvite ¶
func (srv *Server) OnInvite(handler RequestHandler)
OnInvite registers Invite request handler
func (*Server) OnMessage ¶
func (srv *Server) OnMessage(handler RequestHandler)
OnMessage registers Message request handler
func (*Server) OnNoRoute ¶
func (srv *Server) OnNoRoute(handler RequestHandler)
OnNoRoute registers no route handler default is handling is responding 405 Method Not allowed This allows customizing your response for any non handled message
Example ¶
// Creating no route handler allows you to respond for non handled (non routed) requests
ua, _ := NewUA()
srv, _ := NewServer(ua)
srv.OnNoRoute(func(req *sip.Request, tx sip.ServerTransaction) {
res := sip.NewResponseFromRequest(req, 405, "Method Not Allowed", nil)
// Send response directly and let transaction terminate
if err := srv.WriteResponse(res); err != nil {
srv.log.Error("respond '405 Method Not Allowed' failed", "error", err)
}
})
func (*Server) OnNotify ¶
func (srv *Server) OnNotify(handler RequestHandler)
OnNotify registers Notify request handler
func (*Server) OnOptions ¶
func (srv *Server) OnOptions(handler RequestHandler)
OnOptions registers Options request handler
func (*Server) OnPrack ¶
func (srv *Server) OnPrack(handler RequestHandler)
OnPrack registers Prack request handler
func (*Server) OnPublish ¶
func (srv *Server) OnPublish(handler RequestHandler)
OnPublish registers Publish request handler
func (*Server) OnRefer ¶
func (srv *Server) OnRefer(handler RequestHandler)
OnRefer registers Refer request handler
func (*Server) OnRegister ¶
func (srv *Server) OnRegister(handler RequestHandler)
OnRegister registers Register request handler
func (*Server) OnRequest ¶
func (srv *Server) OnRequest(method sip.RequestMethod, handler RequestHandler)
OnRequest registers new request callback. Can be used as generic way to add handler
func (*Server) OnSubscribe ¶
func (srv *Server) OnSubscribe(handler RequestHandler)
OnSubscribe registers Subscribe request handler
func (*Server) OnUpdate ¶
func (srv *Server) OnUpdate(handler RequestHandler)
OnUpdate registers Update request handler
func (*Server) RegisteredMethods ¶
RegisteredMethods returns list of registered handlers. Can be used for constructing Allow header
func (*Server) ServeUDP ¶
func (srv *Server) ServeUDP(l net.PacketConn) error
ServeUDP starts serving request on UDP type listener.
func (*Server) TransportLayer ¶
func (srv *Server) TransportLayer() *sip.TransportLayer
Transport is function to get transport layer of server Can be used for modifying
func (*Server) WriteResponse ¶
WriteResponse will proxy message to transport layer. Use it in stateless mode
func (*Server) WriteResponseContext ¶ added in v1.5.0
WriteResponseContext is WriteResponse with a caller context. On TCP/TLS the response write honors ctx (see TransportLayer.WriteMsgContext); the response still goes to the connection selected by the original request lookup.
type ServerOption ¶
func WithServerLogger ¶
func WithServerLogger(logger *slog.Logger) ServerOption
WithServerLogger allows customizing server logger
type UserAgent ¶
type UserAgent struct {
// contains filtered or unexported fields
}
func NewUA ¶
func NewUA(options ...UserAgentOption) (*UserAgent, error)
NewUA creates User Agent User Agent will create transport and transaction layer Check options for customizing user agent
func (*UserAgent) Close ¶
Close stops admission, cancels and joins owned cleanup, then closes the transaction and transport layers. It does not guarantee ACK delivery for a late 2xx racing shutdown; rejected cleanup admission is logged by its owner.
func (*UserAgent) TransactionLayer ¶
func (ua *UserAgent) TransactionLayer() *sip.TransactionLayer
func (*UserAgent) TransportLayer ¶
func (ua *UserAgent) TransportLayer() *sip.TransportLayer
type UserAgentOption ¶
func WithUserAgenTLSConfig ¶
func WithUserAgenTLSConfig(c *tls.Config) UserAgentOption
WithUserAgenTLSConfig allows customizing default tls config.
func WithUserAgent ¶
func WithUserAgent(ua string) UserAgentOption
WithUserAgent changes user agent name Default: sipgo
func WithUserAgentDNSResolver ¶
func WithUserAgentDNSResolver(r *net.Resolver) UserAgentOption
WithUserAgentDNSResolver allows customizing default DNS resolver for transport layer
func WithUserAgentHostname ¶
func WithUserAgentHostname(hostname string) UserAgentOption
WithUserAgentHostname represents FQDN of user that can be presented in From header
func WithUserAgentParser ¶
func WithUserAgentParser(p *sip.Parser) UserAgentOption
WithUserAgentParser allows removing default behavior of parser You can define and remove default headers parser map and pass here. Only use if your benchmarks are better than default
func WithUserAgentReliableWriteTimeout ¶ added in v1.5.0
func WithUserAgentReliableWriteTimeout(timeout time.Duration) UserAgentOption
WithUserAgentReliableWriteTimeout explicitly enables a write budget for every real TCP/TLS write of this UserAgent: outbound submits, inbound (accepted) responses and the automatic ACK/retransmission writes performed by the transaction FSMs. VoIPGo passes 2s.
It is opt-in and off by default, so existing callers keep the legacy unbounded writes. Protocol timers (Timer A/B/D/H/J/M/L, retransmission windows, transaction identity) are untouched: this only bounds how long a entire reliable submit (lookup/dial/handshake/queue/write) may block. Automatic writes also retain protection enforced by the connection owner, there is no per-call budget to reset and no per-transaction deadline to clear.
A non-positive timeout is rejected instead of being silently interpreted as "unlimited".
func WithUserAgentTransactionLayerOptions ¶
func WithUserAgentTransactionLayerOptions(o ...sip.TransactionLayerOption) UserAgentOption
WithUserAgentTransactionLayerOptions allows setting options for the transaction layer
func WithUserAgentTransportLayerOptions ¶
func WithUserAgentTransportLayerOptions(o ...sip.TransportLayerOption) UserAgentOption
WithUserAgentTransportLayerOptions allows setting options for the transport layer