Exemple #1
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Constructs an instance from settings loaded from the application configuration.
        /// </summary>
        /// <param name="keyPrefix">The configuration key prefix.</param>
        /// <remarks>
        /// <para>
        /// The RADIUS client settings are loaded from the application
        /// configuration, using the specified key prefix.  The following
        /// settings are recognized by the class:
        /// </para>
        /// <div class="tablediv">
        /// <table class="dtTABLE" cellspacing="0" ID="Table1">
        /// <tr valign="top">
        /// <th width="1">Setting</th>
        /// <th width="1">Default</th>
        /// <th width="90%">Description</th>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Type</td>
        ///     <td>UDP</td>
        ///     <td>
        ///     Specifies the transport type.  This must be one
        ///     of the following values: <b>UDP</b>, <b>TCP</b>, or <b>TLS</b>.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Binding</td>
        ///     <td>ANY:SIP</td>
        ///     <td>
        ///     The <see cref="NetworkBinding" /> the transport should use
        ///     when binding to the network interface.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>ExternalBinding</td>
        ///     <td>(see note)</td>
        ///     <td>
        ///     The <see cref="NetworkBinding" /> that specifies how external clients
        ///     will access the transport.  This will typically be set to the IP
        ///     address and port on the WAN side of the firewall/router that is
        ///     mapped to the <b>Binding</b> specified above.  This defaults to
        ///     <b>Binding</b> unless its IP address is <see cref="IPAddress.Any" />.
        ///     If this is the case, then <b>ExternalBinding</b> will default to
        ///     the IP address of the first active network adapter found and the
        ///     port specified in <b>Binding</b>.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>BufferSize</td>
        ///     <td>32K</td>
        ///     <td>
        ///     Byte size of the socket's send and receive buffers.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Timers.*</td>
        ///     <td>(see note)</td>
        ///     <td>
        ///     This subsection can be used to override the default
        ///     timers used by user agents for this transport.
        ///     See the <see cref="SipBaseTimers" /> class' <see cref="SipBaseTimers.LoadConfig" />
        ///     method for more information.
        ///     </td>
        /// </tr>
        /// </table>
        /// </div>
        /// <para>
        /// Transport settings can be specified in an application configuration
        /// section.  Applications will often use a configuration array so that
        /// multiple transports can be specified.
        /// </para>
        /// </remarks>
        public static SipTransportSettings LoadConfig(string keyPrefix)
        {
            var settings = new SipTransportSettings();
            var config   = new Config(keyPrefix);

            settings.TransportType   = config.Get <SipTransportType>("Type", settings.TransportType);
            settings.Binding         = config.Get("Binding", settings.Binding);
            settings.ExternalBinding = config.Get("ExternalBinding", settings.Binding);
            settings.BufferSize      = config.Get("BufferSize", settings.BufferSize);
            settings.BaseTimers      = SipBaseTimers.LoadConfig(config.KeyPrefix + "Timers");

            return(settings);
        }
Exemple #2
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Loads the settings from the application configuration.
        /// </summary>
        /// <param name="keyPrefix">The configuration key prefix.</param>
        /// <returns>The loaded <see cref="SipCoreSettings" />.</returns>\
        /// <remarks>
        /// <div class="tablediv">
        /// <table class="dtTABLE" cellspacing="0" ID="Table1">
        /// <tr valign="top">
        /// <th width="1">Setting</th>
        /// <th width="1">Default</th>
        /// <th width="90%">Description</th>
        /// </tr>
        /// <tr valign="top">
        ///     <td>LocalContact</td>
        ///     <td>(see note)</td>
        ///     <td>
        ///     <para>
        ///     Specifies necessary information to be included in the <b>Contact</b> header in
        ///     requests and responses generated by the core.  This can be a full contact heading
        ///     with a display name, SIP URI, and contact parameters, or just an IP address or
        ///     host name.  Full SIP URIs will be used <i>as is</i> when used in a <b>Contact</b>
        ///     header.  A SIP URI will be generated on the fly from an IP address or host by adding
        ///     the port and transport parameter based on the actual transport used.  This defaults to
        ///     the first active IP address found on the machine.
        ///     </para>
        ///     <note>
        ///     SIP URIs with parameters (such as "transport=tcp") <b>must be surrounded by angle brackets:</b>
        ///     "&lt;" and "&gt;".
        ///     </note>
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>OutboundProxy</td>
        ///     <td>(none)</td>
        ///     <td>
        ///     Specifies outbound proxy SIP URI where the core should route all
        ///     outbound SIP requests.  Set this to <c>null</c> to route requests
        ///     directly to their destination.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>UserAgent</td>
        ///     <td>LillTek SIP &lt;version&gt;</td>
        ///     <td>
        ///     Specifies the value to use as the <b>User-Agent</b> header for SIP messages.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>ServerAgent</td>
        ///     <td>LillTek SIP &lt;version&gt;</td>
        ///     <td>
        ///     Specifies the value to use as the <b>Server</b> header for SIP messages.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>AutoAuthenticate</td>
        ///     <td>yes</td>
        ///     <td>
        ///     Indicates that the core should automatically handle authentication
        ///     challenges from proxies and remote SIP endpoints by computing
        ///     appropriate response and resubmitting the request.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>UserName</td>
        ///     <td>(none)</td>
        ///     <td>
        ///     The account name used for authenticating with downstream SIP trunking proxies.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Password</td>
        ///     <td>(none)</td>
        ///     <td>
        ///     The password name to use for authentication purposes.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>TraceMode</td>
        ///     <td><see cref="SipTraceMode.None" /></td>
        ///     <td>
        ///     Indicates whether the SIP core should generate <see cref="NetTrace" />
        ///     diagnostics.  Note that <b>Diagnostics.TraceEnable[#]=0:LillTek.SIP</b> must
        ///     also be set for this to work.  Valid values are: <see cref="SipTraceMode.None" />,
        ///     <see cref="SipTraceMode.Send" />, <see cref="SipTraceMode.Receive" />, and
        ///     <see cref="SipTraceMode.All" />.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>ServerTransactionTTL</td>
        ///     <td>15m</td>
        ///     <td>
        ///     The maximum time a server side transaction will be maintained.  Transactions
        ///     that have existed for longer than this will be terminated.  This helps
        ///     prevent memory leaks due to hung or crashed server transaction handlers.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>EarlyDialogTTL</td>
        ///     <td>90s</td>
        ///     <td>
        ///     The maximum time an early dialog will be maintained by the core if the
        ///     dialog isn't confirmed by the client.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>BkInterval</td>
        ///     <td>250ms</td>
        ///     <td>
        ///     The interval which the core should wake up to perform background tasks.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>TransportBkInterval</td>
        ///     <td>1s</td>
        ///     <td>
        ///     The interval at which transport background activities should be performed.
        ///     </td>
        /// </tr>
        /// <tr valign="top">
        ///     <td>Transport[#]</td>
        ///     <td>(see note)</td>
        ///     <td>
        ///     <para>
        ///     The transport settings are loaded from the "Transport" subsection
        ///     array.  See <see cref="SipTransportSettings.LoadConfig" /> for
        ///     information on the settings loaded from each of these subsections.
        ///     </para>
        ///     <para>
        ///     This defaults to a single UDP transport binding to all network
        ///     interfaces on port 5060.
        ///     </para>
        ///     </td>
        /// </tr>
        /// </table>
        /// </div>
        /// </remarks>
        public static SipCoreSettings LoadConfig(string keyPrefix)
        {
            var config     = new Config(keyPrefix);
            var settings   = new SipCoreSettings();
            var transports = config.GetSectionKeyArray("Transport");

            settings.LocalContact         = config.Get("LocalContact", settings.LocalContact);
            settings.AutoAuthenticate     = config.Get("AutoAuthenticate", settings.AutoAuthenticate);
            settings.UserName             = config.Get("UserName", settings.UserName);
            settings.Password             = config.Get("Password", settings.Password);
            settings.TraceMode            = config.Get <SipTraceMode>("TraceMode", settings.TraceMode);
            settings.UserAgent            = config.Get("UserAgent", settings.UserAgent);
            settings.ServerAgent          = config.Get("ServerAgent", settings.ServerAgent);
            settings.ServerTransactionTTL = config.Get("ServerTransactionTTL", settings.ServerTransactionTTL);
            settings.EarlyDialogTTL       = config.Get("EarlyDialogTTL", settings.EarlyDialogTTL);
            settings.BkInterval           = config.Get("BkInterval", settings.BkInterval);
            settings.TransportBkInterval  = config.Get("TransportBkInterval", settings.TransportBkInterval);

            string uri;

            uri = config.Get("OutboundProxy", (string)settings.OutboundProxyUri);
            if (string.IsNullOrWhiteSpace(uri))
            {
                settings.OutboundProxyUri = null;  // Treat blank as null
            }
            else
            {
                try
                {
                    settings.OutboundProxyUri = new SipUri(uri);
                }
                catch (Exception e)
                {
                    SysLog.LogException(e, "Cannot parse SIP Core setting [OutboundProxy].");
                }
            }

            settings.TransportSettings = new SipTransportSettings[transports.Length];
            for (int i = 0; i < transports.Length; i++)
            {
                settings.TransportSettings[i] = SipTransportSettings.LoadConfig(transports[i]);
            }

            return(settings);
        }
Exemple #3
0
 /// <summary>
 /// Starts the transport.
 /// </summary>
 /// <param name="settings">The <see cref="SipTransportSettings" />.</param>
 /// <param name="router">The <see cref="ISipMessageRouter" /> instance that will handle the routing of received messages.</param>
 /// <exception cref="SocketException">Thrown if there's a conflict with the requested and existing socket bindings.</exception>
 public void Start(SipTransportSettings settings, ISipMessageRouter router)
 {
     this.settings = settings;
     Start(settings.Binding, settings.BufferSize, router);
 }