Class SIPTransport
Inheritance
Implements
Inherited Members
Namespace: SIPSorcery.SIP
Assembly: SIPSorcery.dll
Syntax
public class SIPTransport : IDisposable
Constructors
| Improve this Doc View SourceSIPTransport()
Creates a SIP transport class with default DNS resolver and SIP transaction engine.
Declaration
public SIPTransport()
SIPTransport(Boolean)
Declaration
public SIPTransport(bool stateless)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | stateless |
SIPTransport(Boolean, Encoding, Encoding)
Allows the transport layer to be created to operate in a stateless mode.
Declaration
public SIPTransport(bool stateless, Encoding sipEncoding, Encoding sipBodyEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | stateless | If true the transport layer will NOT queue incoming messages and will NOT use a transaction engine. |
System.Text.Encoding | sipEncoding | |
System.Text.Encoding | sipBodyEncoding |
SIPTransport(Encoding, Encoding)
Declaration
public SIPTransport(Encoding sipEncoding, Encoding sipBodyEncoding)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Encoding | sipEncoding | |
System.Text.Encoding | sipBodyEncoding |
Fields
| Improve this Doc View SourceBlackholeAddress
Declaration
public static IPAddress BlackholeAddress
Field Value
Type | Description |
---|---|
System.Net.IPAddress |
ContactHost
If set this host name (or IP address) will be set whenever the transport layer is asked to do a substitution on the Contact URI. The substitution is requested by a request or response setting the Contact URI host to IPAddress.Any ("0.0.0.0") or IPAddress.IPV6.Any ("::0").
var sipRequest = GetRequest(
method,
uri,
new SIPToHeader(
null,
new SIPURI(uri.User, uri.Host, null, uri.Scheme, SIPProtocolsEnum.udp),
null),
SIPFromHeader.GetDefaultSIPFromHeader(uri.Scheme));
// Set the Contact header to a default value that lets the transport layer know to update it
// when the sending socket is selected.
sipRequest.Header.Contact = new List<SIPContactHeader>() { SIPContactHeader.GetDefaultSIPContactHeader() };
Declaration
public string ContactHost
Field Value
Type | Description |
---|---|
System.String |
CustomiseRequestHeader
Optional callback function that can be set to customise the headers on an outbound SIP request. The callback is called BEFORE applying ContactHost which means do not set both if the callback is intended to set the Contact URI. Parameters:
- SIPEndPoint: The local SIP end point the request will be sent from.
- SIPEndPoint: The remote SIP end point the request has been resolved to.
- SIPRequest: The SIP request being sent. Returns: If the result is non-null it will be used to replace the current SIP Header instance on the SIP Request. If null the original header will be left in place.
Declaration
public Func<SIPEndPoint, SIPEndPoint, SIPRequest, SIPHeader> CustomiseRequestHeader
Field Value
Type | Description |
---|---|
System.Func<SIPEndPoint, SIPEndPoint, SIPRequest, SIPHeader> |
CustomiseResponseHeader
Optional function that can be set to customise the headers on an outbound SIP request. The callback is called BEFORE applying ContactHost which means do not set both if the callback is intended to set the Contact URI. Parameters:
- SIPEndPoint: The local SIP end point the request will be sent from.
- SIPEndPoint: The remote SIP end point the request has been resolved to.
- SIPRequest: The SIP request being sent. Returns: If the result is non-null it will be used to replace the current SIP Header instance on the SIP Request. If null the original header will be left in place.
Declaration
public Func<SIPEndPoint, SIPEndPoint, SIPResponse, SIPHeader> CustomiseResponseHeader
Field Value
Type | Description |
---|---|
System.Func<SIPEndPoint, SIPEndPoint, SIPResponse, SIPHeader> |
PreferIPv6NameResolution
Set to true to prefer IPv6 lookups of hostnames. By default IPv4 lookups will be performed.
Declaration
public bool PreferIPv6NameResolution
Field Value
Type | Description |
---|---|
System.Boolean |
ResolveSIPUriCallbackAsync
Default call to do DNS lookups for SIP URI's. In normal circumstances this property does not need to be set manually and care needs to be taken if it is. Can be replaced for custom scenarios and unit testing.
Declaration
public ResolveSIPUriDelegateAsync ResolveSIPUriCallbackAsync
Field Value
Type | Description |
---|---|
ResolveSIPUriDelegateAsync |
ResolveSIPUriFromCacheCallback
Default call to do DNS lookups for SIP URI's from cache and avoid a time consuming full DNS lookup. In normal circumstances this property does not need to be set manually and care needs to be taken if it is. Can be replaced for custom scenarios and unit testing.
Declaration
public ResolveSIPUriFromCacheDelegate ResolveSIPUriFromCacheCallback
Field Value
Type | Description |
---|---|
ResolveSIPUriFromCacheDelegate |
Properties
| Improve this Doc View SourceCanCreateMissingChannels
If true allows this class to attempt to create a new SIP channel if a required protocol is missing. Set to false to prevent new channels being created on demand. Note that when listening SIP end points are required they will always need to be created manually.
Declaration
public bool CanCreateMissingChannels { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
DisableRetransmitSending
Warning: Do not set this property unless there is a specific problem with a remote SIP User Agent accepting SIP retransmits. The effect of setting this property is to only send each request and response for a transaction once, i.e. retransmits timers firing will not cause additional sending of the requests or responses to be put on the wire. SIP transaction processing will still occur as normal with the exception of not sending the retransmitted messages. It's also only likely to be useful for cases where reliable transports, such as TCP and TLS, are being used, since they are the ones where retransmits have been observed to be misidentified.
Declaration
public bool DisableRetransmitSending { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Remarks
For additional context see https://lists.cs.columbia.edu/pipermail/sip-implementors/2013-January/028817.html and https://github.com/sipsorcery/sipsorcery/issues/370#issuecomment-739495726.
MaxInMessageQueueCount
The maximum number of SIP message receiving queues, if this number is exceeded, new messages will be discarded directly Default:5000,Unlimited:0
Declaration
public int MaxInMessageQueueCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
MaxPendingTransactionsCount
Warning: Do not set this property unless you explicitly require a very high number of in-flight SIP transactions. The default limit is high and increasing it is likely to have a significant impact on CPU and memory performance.
Declaration
public static int MaxPendingTransactionsCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAddSIPChannel(SIPChannel)
Adds an additional SIP Channel to the transport layer.
Declaration
public void AddSIPChannel(SIPChannel sipChannel)
Parameters
Type | Name | Description |
---|---|---|
SIPChannel | sipChannel |
AddSIPChannel(List<SIPChannel>)
Adds additional SIP Channels to the transport layer.
Declaration
public void AddSIPChannel(List<SIPChannel> sipChannels)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<SIPChannel> | sipChannels |
CreateChannel(SIPProtocolsEnum, AddressFamily, Int32)
Creates an on demand SIP channel suitable for outbound connections.
Declaration
public SIPChannel CreateChannel(SIPProtocolsEnum protocol, AddressFamily addressFamily, int port = 0)
Parameters
Type | Name | Description |
---|---|---|
SIPProtocolsEnum | protocol | The transport protocol of the SIP channel to create. |
System.Net.Sockets.AddressFamily | addressFamily | Whether the channel should be created for IPv4 or IPv6. |
System.Int32 | port | Optional. If specified channels that open a listener will attempt to use this port. |
Returns
Type | Description |
---|---|
SIPChannel | A SIP channel if it was possible to create or null if not. |
Dispose()
Declaration
public void Dispose()
EnableTraceLogs()
Helper method to enable logging of SIP request, responses and retransmits.
Declaration
public void EnableTraceLogs()
GetSIPChannels()
Gets a list of this transport's SIP channels.
Declaration
public List<SIPChannel> GetSIPChannels()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<SIPChannel> | A list of SIP channels. |
PreProcessRouteInfo(SIPRequest)
This function performs processing on a request to handle any actions that need to be taken based on the Route header.
Declaration
public void PreProcessRouteInfo(SIPRequest sipRequest)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | sipRequest |
Remarks
The main sections in the RFC3261 dealing with Route header processing are sections 12.2.1.1 for request processing and 16.4 for proxy processing. The steps to process requests for Route headers are:
- If route set is empty no further action is required, forward to destination resolved from request URI,
- If the request URI is identified as a value that was previously set as a Route by this SIP agent it means the previous hop was a strict router. Replace the request URI with the last Route header and go to next step,
- If the top most route header was set by this SIP agent then remove it and go to next step,
- If the top most route set does contain the lr parameter then forward to the destination resolved by it,
- If the top most route header does NOT contain the lr parameter is must be popped and inserted as the request URI and the original request URI must be added to the end of the route set, forward to destination resolved from request URI,
ReceiveMessage(SIPChannel, SIPEndPoint, SIPEndPoint, Byte[])
Event handler for messages received on all SIP channels assigned to this transport. There are two distinct modes of operation for processing messages depending on whether the queue incoming variable is set. If it is then new messages get added to a queue and are processed on a separate thread. If not then the message is processed on the same thread that received the message. Generally only applications that do minimal processing, such as a stateless SIP Proxy, should do without the queueing. The biggest blocking risk is DNS. If the message is processed on the SIP channel thread and results in a DNS lookup then new receives could be blocked for up to 10s.
Declaration
public Task ReceiveMessage(SIPChannel sipChannel, SIPEndPoint localEndPoint, SIPEndPoint remoteEndPoint, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
SIPChannel | sipChannel | The SIP channel that received the message. |
SIPEndPoint | localEndPoint | The local end point the message was received on. |
SIPEndPoint | remoteEndPoint | The remote end point the message came from. |
System.Byte[] | buffer | A buffer containing the received message. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
RemoveSIPChannel(SIPChannel)
Removes a single SIP channel from the transport layer.
Declaration
public void RemoveSIPChannel(SIPChannel sipChannel)
Parameters
Type | Name | Description |
---|---|---|
SIPChannel | sipChannel | The SIP channel to remove. |
ResolveSIPUriAsync(SIPURI)
Public wrapper for the SIP DNS lookup call being used by this SIP transport.
Declaration
public Task<SIPEndPoint> ResolveSIPUriAsync(SIPURI uri)
Parameters
Type | Name | Description |
---|---|---|
SIPURI | uri | The SIP URI to resolve. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<SIPEndPoint> | If successful a SIP end point for the SIP URI. For failures SIPEndPoint.Empty. |
SendRawAsync(SIPEndPoint, SIPEndPoint, Byte[])
Allows raw bytes to be sent from one of the SIPTransport sockets. This should not be used for SIP payloads and instead is provided to allow other types of payloads to be multiplexed on the SIP socket. Examples are sending NAT keep-alives and STUN responses where it's useful to use the same socket as the SIP packets.
Declaration
public Task<SocketError> SendRawAsync(SIPEndPoint localSIPEndPoint, SIPEndPoint dstEndPoint, byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | localSIPEndPoint | The local SIP end point to do the send from. Must match the local end point of one of the SIP transports channels. |
SIPEndPoint | dstEndPoint | The destination end point to send the buffer to. |
System.Byte[] | buffer | The data buffer to send. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> |
SendRequestAsync(SIPEndPoint, SIPRequest)
Sends a SIP request asynchronously. This method will attempt to find the most appropriate local SIP channel in this SIP transport to send the request on.
Declaration
public Task<SocketError> SendRequestAsync(SIPEndPoint dstEndPoint, SIPRequest sipRequest)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | dstEndPoint | The destination end point to send the request to. |
SIPRequest | sipRequest | The SIP request to send. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> |
SendRequestAsync(SIPRequest, Boolean)
This send method does NOT wait if a DNS lookup is required. Instead it relies on the SIP retransmit logic to avoid to re-attempt the send at pre-defined intervals. This type of send is suitable for requests that are part of a transaction or for SIP Proxy servers that are relying on the remote SIP agent to retransmit requests.
Declaration
public async Task<SocketError> SendRequestAsync(SIPRequest sipRequest, bool waitForDns = false)
Parameters
Type | Name | Description |
---|---|---|
SIPRequest | sipRequest | The SIP request to send. |
System.Boolean | waitForDns | If true the request will wait for any required DNS lookup to complete. This can potentially take many seconds. If false the DNS lookup will be queued and the send will need to be called again. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> | Will return InPorgress for a DNS cache miss. HostNotFound for a cache hit on a failure response. Otherwise the result of the send attempt. |
SendResponseAsync(SIPEndPoint, SIPResponse)
Asynchronously forwards a SIP response to the specified destination.
Declaration
public Task<SocketError> SendResponseAsync(SIPEndPoint dstEndPoint, SIPResponse sipResponse)
Parameters
Type | Name | Description |
---|---|---|
SIPEndPoint | dstEndPoint | The destination end point to send the response to. |
SIPResponse | sipResponse | The SIP response to send. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> |
SendResponseAsync(SIPResponse, Boolean)
Forwards a SIP response. There are two main cases for a SIP response to be forwarded:
- First case is when we have processed a request and are returning a response. In this case the response should be sent back on exactly the same socket the request came on.
- Second case is when we are acting as a Proxy and the response is on it's way back from the agent that processed the request. In this case it's highly likely the response needs to be forwarded to a different end point then the one it came from and it's also possible it will need to use a completely different channel to send on compared to the one it arrived on.
Forwarding logic:
- If the channel hints are set then an attempt will be made to use them to find an appropriate channel to send the response on. If the hinted channel can't be found or it is found but is the wrong protocol then move onto the next step,
- The information in the Top Via header will be used to find the best channel to forward the response on. This is a special send method that relies on the SIP transaction retransmit logic to avoid blocking when a DNS request is required. This type of send is suitable for responses that are part of a transaction or for SIP Proxy servers that are relying on the remote SIP agent to retransmit requests.
Declaration
public async Task<SocketError> SendResponseAsync(SIPResponse sipResponse, bool waitForDns = false)
Parameters
Type | Name | Description |
---|---|---|
SIPResponse | sipResponse | The SIP response to send. |
System.Boolean | waitForDns | If true the request will wait for any required DNS lookup to complete. This can potentially take many seconds. If false the DNS lookup will be queued and the send will need to be called again. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Net.Sockets.SocketError> | Will return InPorgress for a DNS cache miss. HostNotFound for a cache hit on a failure response. Otherwise the result of the send attempt. |
Shutdown()
Shuts down the SIP transport layer by closing all SIP channels and stopping long running tasks.
Declaration
public void Shutdown()
Events
| Improve this Doc View SourceSIPBadRequestInTraceEvent
Declaration
public event SIPTransportSIPBadMessageDelegate SIPBadRequestInTraceEvent
Event Type
Type | Description |
---|---|
SIPTransportSIPBadMessageDelegate |
SIPBadResponseInTraceEvent
Declaration
public event SIPTransportSIPBadMessageDelegate SIPBadResponseInTraceEvent
Event Type
Type | Description |
---|---|
SIPTransportSIPBadMessageDelegate |
SIPRequestInTraceEvent
Declaration
public event SIPTransportRequestTraceDelegate SIPRequestInTraceEvent
Event Type
Type | Description |
---|---|
SIPTransportRequestTraceDelegate |
SIPRequestOutTraceEvent
Declaration
public event SIPTransportRequestTraceDelegate SIPRequestOutTraceEvent
Event Type
Type | Description |
---|---|
SIPTransportRequestTraceDelegate |
SIPRequestRetransmitTraceEvent
Declaration
public event SIPTransactionRequestRetransmitDelegate SIPRequestRetransmitTraceEvent
Event Type
Type | Description |
---|---|
SIPTransactionRequestRetransmitDelegate |
SIPResponseInTraceEvent
Declaration
public event SIPTransportResponseTraceDelegate SIPResponseInTraceEvent
Event Type
Type | Description |
---|---|
SIPTransportResponseTraceDelegate |
SIPResponseOutTraceEvent
Declaration
public event SIPTransportResponseTraceDelegate SIPResponseOutTraceEvent
Event Type
Type | Description |
---|---|
SIPTransportResponseTraceDelegate |
SIPResponseRetransmitTraceEvent
Declaration
public event SIPTransactionResponseRetransmitDelegate SIPResponseRetransmitTraceEvent
Event Type
Type | Description |
---|---|
SIPTransactionResponseRetransmitDelegate |
SIPTransportRequestReceived
Declaration
public event SIPTransportRequestAsyncDelegate SIPTransportRequestReceived
Event Type
Type | Description |
---|---|
SIPTransportRequestAsyncDelegate |
SIPTransportResponseReceived
Declaration
public event SIPTransportResponseAsyncDelegate SIPTransportResponseReceived
Event Type
Type | Description |
---|---|
SIPTransportResponseAsyncDelegate |
STUNRequestReceived
Declaration
public event STUNRequestReceivedDelegate STUNRequestReceived
Event Type
Type | Description |
---|---|
STUNRequestReceivedDelegate |