/// <summary> /// Initialises the SIP transport layer. /// </summary> private void InitialiseSIP() { // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); if (m_sipSocketsNode != null) { // Set up the SIP channels based on the app.config file. List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipSocketsNode); m_sipTransport.AddSIPChannel(sipChannels); } else { // Use default options to set up a SIP channel. int port = FreePort.FindNextAvailableUDPPort(_defaultSIPUdpPort); var sipChannel = new SIPUDPChannel(new IPEndPoint(_defaultLocalAddress, port)); m_sipTransport.AddSIPChannel(sipChannel); } // Wire up the transport layer so incoming SIP requests have somewhere to go. m_sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; // Log all SIP packets received to a log file. m_sipTransport.SIPRequestInTraceEvent += (localSIPEndPoint, endPoint, sipRequest) => { _sipTraceLogger.Debug("Request Received : " + localSIPEndPoint + "<-" + endPoint + "\r\n" + sipRequest.ToString()); }; m_sipTransport.SIPRequestOutTraceEvent += (localSIPEndPoint, endPoint, sipRequest) => { _sipTraceLogger.Debug("Request Sent: " + localSIPEndPoint + "->" + endPoint + "\r\n" + sipRequest.ToString()); }; m_sipTransport.SIPResponseInTraceEvent += (localSIPEndPoint, endPoint, sipResponse) => { _sipTraceLogger.Debug("Response Received: " + localSIPEndPoint + "<-" + endPoint + "\r\n" + sipResponse.ToString()); }; m_sipTransport.SIPResponseOutTraceEvent += (localSIPEndPoint, endPoint, sipResponse) => { _sipTraceLogger.Debug("Response Sent: " + localSIPEndPoint + "->" + endPoint + "\r\n" + sipResponse.ToString()); }; }
/// <summary> /// Initialises the SIP transport layer. /// </summary> public async Task InitialiseSIP() { if (_isInitialised == false) { await Task.Run(() => { _isInitialised = true; // Configure the SIP transport layer. SIPTransport = new SIPTransport(); bool sipChannelAdded = false; if (m_sipSocketsNode != null) { // Set up the SIP channels based on the app.config file. List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipSocketsNode); if (sipChannels?.Count > 0) { SIPTransport.AddSIPChannel(sipChannels); sipChannelAdded = true; } } if (sipChannelAdded == false) { // Use default options to set up a SIP channel. SIPUDPChannel udpChannel = null; try { udpChannel = new SIPUDPChannel(new IPEndPoint(IPAddress.Any, SIP_DEFAULT_PORT)); } catch (SocketException bindExcp) { logger.LogWarning($"Socket exception attempting to bind UDP channel to port {SIP_DEFAULT_PORT}, will use random port. {bindExcp.Message}."); udpChannel = new SIPUDPChannel(new IPEndPoint(IPAddress.Any, 0)); } var tcpChannel = new SIPTCPChannel(new IPEndPoint(IPAddress.Any, udpChannel.Port)); SIPTransport.AddSIPChannel(new List <SIPChannel> { udpChannel, tcpChannel }); } }); // Wire up the transport layer so incoming SIP requests have somewhere to go. SIPTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; // Log all SIP packets received to a log file. SIPTransport.SIPRequestInTraceEvent += SIPRequestInTraceEvent; SIPTransport.SIPRequestOutTraceEvent += SIPRequestOutTraceEvent; SIPTransport.SIPResponseInTraceEvent += SIPResponseInTraceEvent; SIPTransport.SIPResponseOutTraceEvent += SIPResponseOutTraceEvent; } }
/// <summary> /// Initialises the SIP transport layer. /// </summary> public async Task InitialiseSIP() { if (_isIntialised == false) { await Task.Run(() => { _isIntialised = true; if (String.IsNullOrEmpty(m_DnsServer) == false) { // Use a custom DNS server. m_DnsServer = m_DnsServer.Contains(":") ? m_DnsServer : m_DnsServer + ":53"; DNSManager.SetDNSServers(new List <IPEndPoint> { IPSocket.ParseSocketString(m_DnsServer) }); } // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); bool sipChannelAdded = false; if (m_sipSocketsNode != null) { // Set up the SIP channels based on the app.config file. List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipSocketsNode); if (sipChannels?.Count > 0) { m_sipTransport.AddSIPChannel(sipChannels); sipChannelAdded = true; } } if (sipChannelAdded == false) { // Use default options to set up a SIP channel. int port = FreePort.FindNextAvailableUDPPort(_defaultSIPUdpPort); var sipChannel = new SIPUDPChannel(new IPEndPoint(_defaultLocalAddress, port)); m_sipTransport.AddSIPChannel(sipChannel); } }); // Wire up the transport layer so incoming SIP requests have somewhere to go. m_sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; // Log all SIP packets received to a log file. m_sipTransport.SIPRequestInTraceEvent += (localSIPEndPoint, endPoint, sipRequest) => { _sipTraceLogger.Debug("Request Received : " + localSIPEndPoint + "<-" + endPoint + "\r\n" + sipRequest.ToString()); }; m_sipTransport.SIPRequestOutTraceEvent += (localSIPEndPoint, endPoint, sipRequest) => { _sipTraceLogger.Debug("Request Sent: " + localSIPEndPoint + "->" + endPoint + "\r\n" + sipRequest.ToString()); }; m_sipTransport.SIPResponseInTraceEvent += (localSIPEndPoint, endPoint, sipResponse) => { _sipTraceLogger.Debug("Response Received: " + localSIPEndPoint + "<-" + endPoint + "\r\n" + sipResponse.ToString()); }; m_sipTransport.SIPResponseOutTraceEvent += (localSIPEndPoint, endPoint, sipResponse) => { _sipTraceLogger.Debug("Response Sent: " + localSIPEndPoint + "->" + endPoint + "\r\n" + sipResponse.ToString()); }; } }
public async Task IncomingCallNoSdpUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); transport.AddSIPChannel(new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0))); SIPUserAgent userAgent = new SIPUserAgent(transport, null); string inviteReqStr = "INVITE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF + "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691" + m_CRLF + "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF + "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF + "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF + "CSeq: 3532 INVITE" + m_CRLF + "Contact: <sip:[email protected]:60163;ob>" + m_CRLF + "Max-Forwards: 70" + m_CRLF + "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF + "Supported: replaces, 100rel, timer, norefersub" + m_CRLF + "Content-Length: 0" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "Session-Expires: 1800" + m_CRLF + m_CRLF; SIPEndPoint dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 0)); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessageBuffer); var uas = userAgent.AcceptCall(inviteReq); await userAgent.Answer(uas, CreateMockVoIPMediaEndPoint()); // The call attempt should timeout while waiting for the ACK request with the SDP answer. Assert.False(userAgent.IsCallActive); }
private void Initialize() { logger.Debug("SIP Registrar daemon starting..."); // Pre-flight checks. if (m_sipRegistrarSocketsNode == null || m_sipRegistrarSocketsNode.ChildNodes.Count == 0) { throw new ApplicationException("The SIP Registrar cannot start without at least one socket specified to listen on, please check config file."); } // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false); m_sipTransport.PerformanceMonitorPrefix = SIPSorceryPerformanceMonitor.REGISTRAR_PREFIX; List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipRegistrarSocketsNode); m_sipTransport.AddSIPChannel(sipChannels); SIPUserAgentConfigurationManager userAgentConfigManager = new SIPUserAgentConfigurationManager(m_userAgentsConfigNode); if (m_userAgentsConfigNode == null) { logger.Warn("The UserAgent config's node was missing."); } m_registrarCore = new SipMessageCore(m_sipTransport, GetSIPAccount_External, GetCanonicalDomain_External, true, false, userAgentConfigManager, SIPAuthenticateRequest_External, m_switchboardUserAgentPrefix, _deviceList); }
public void RegisterStartWithCustomHeaderTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); MockSIPChannel channel = new MockSIPChannel(new IPEndPoint(IPAddress.Any, 0)); transport.AddSIPChannel(channel); SIPRegistrationUserAgent userAgent = new SIPRegistrationUserAgent( transport, null, new SIPURI("alice", "192.168.11.50", null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp), "alice", "password123", null, "192.168.11.50", new SIPURI(SIPSchemesEnum.sip, IPAddress.Any, 0), 120, null, new[] { "My-Header: value" }); userAgent.Start(); channel.SIPMessageSent.WaitOne(5000); Assert.Contains("My-Header: value", channel.LastSIPMessageSent); userAgent.Stop(); }
static void Main() { Console.WriteLine("SIPSorcery Getting Started Demo"); var sipTransport = new SIPTransport(); var sipChannel = new SIPUDPChannel(IPAddress.Loopback, 5060); sipTransport.AddSIPChannel(sipChannel); sipTransport.SIPTransportRequestReceived += (SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) => { Console.WriteLine($"Request received {localSIPEndPoint.ToString()}<-{remoteEndPoint.ToString()}: {sipRequest.StatusLine}"); if (sipRequest.Method == SIPMethodsEnum.OPTIONS) { SIPResponse optionsResponse = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null); sipTransport.SendResponse(optionsResponse); } }; Console.Write("press any key to exit..."); Console.Read(); sipTransport.Shutdown(); }
static void Main() { Console.WriteLine("SIPSorcery Getting Started Demo"); Log = AddConsoleLogger(); _waveFile = new WaveFileWriter("output.mp3", _waveFormat); _sipTransport = new SIPTransport(); _sipTransport.AddSIPChannel(new SIPUDPChannel(new IPEndPoint(IPAddress.Any, SIP_LISTEN_PORT))); var userAgent = new SIPUserAgent(_sipTransport, null, true); userAgent.ServerCallCancelled += (uas) => Log.LogDebug("Incoming call cancelled by remote party."); userAgent.OnCallHungup += (dialog) => _waveFile?.Close(); userAgent.OnIncomingCall += async(ua, req) => { WindowsAudioEndPoint winAudioEP = new WindowsAudioEndPoint(new AudioEncoder()); VoIPMediaSession voipMediaSession = new VoIPMediaSession(winAudioEP.ToMediaEndPoints()); voipMediaSession.AcceptRtpFromAny = true; voipMediaSession.OnRtpPacketReceived += OnRtpPacketReceived; var uas = userAgent.AcceptCall(req); await userAgent.Answer(uas, voipMediaSession); }; Console.WriteLine("press any key to exit..."); Console.Read(); // Clean up. _sipTransport.Shutdown(); }
static void Main(string[] args) { try { if (args == null || args.Count() == 0) { Console.WriteLine(USAGE_STRING); } else { bool validArgs = ParseArgs(args); if (validArgs) { Console.WriteLine("XMPP Test Console:"); m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); SIPUDPChannel udpChannel = new SIPUDPChannel(new IPEndPoint(m_ipAddress, m_port)); m_sipTransport.AddSIPChannel(udpChannel); m_sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; Console.WriteLine("Waiting for SIP INVITE..."); ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(); } } } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); } }
public void B2BInviteTransactionStatefulProxyTest() { SIPTransactionEngine transactionEngine1 = new SIPTransactionEngine(); SIPTransport sipTransport1 = new SIPTransport(SIPDNSManager.Resolve, transactionEngine1, true, false); IPEndPoint sipTransport1EndPoint = new IPEndPoint(IPAddress.Loopback, 3000); sipTransport1.AddSIPChannel(new SIPUDPChannel(sipTransport1EndPoint)); SIPAppServerCore statefulProxyCore1 = new SIPAppServerCore(sipTransport1, null, statefulProxyCore1_StatefulProxyLogEvent, null, null, null); SIPTransactionEngine transactionEngine2 = new SIPTransactionEngine(); SIPTransport sipTransport2 = new SIPTransport(SIPDNSManager.Resolve, transactionEngine2, true, false); IPEndPoint sipTransport2EndPoint = new IPEndPoint(IPAddress.Loopback, 3001); sipTransport2.AddSIPChannel(new SIPUDPChannel(sipTransport2EndPoint)); SIPAppServerCore statefulProxyCore2 = new SIPAppServerCore(sipTransport2, statefulProxyCore2_GetCanonicalDomain, statefulProxyCore2_StatefulProxyLogEvent, null, null, null); sipTransport1.SIPRequestOutTraceEvent += sipTransport1_SIPRequestOutTraceEvent; sipTransport1.SIPResponseInTraceEvent += sipTransport1_SIPResponseInTraceEvent; sipTransport2.SIPRequestInTraceEvent += sipTransport2_SIPRequestInTraceEvent; sipTransport2.SIPResponseOutTraceEvent += sipTransport2_SIPResponseOutTraceEvent; SIPRequest inviteRequest = GetInviteRequest(sipTransport1EndPoint, null, sipTransport2EndPoint); UACInviteTransaction uacInvite = sipTransport1.CreateUACTransaction(inviteRequest, new SIPEndPoint(SIPProtocolsEnum.udp, sipTransport2EndPoint), new SIPEndPoint(SIPProtocolsEnum.udp, sipTransport1EndPoint), null); uacInvite.SendInviteRequest(new SIPEndPoint(SIPProtocolsEnum.udp, sipTransport2EndPoint), inviteRequest); Thread.Sleep(200); // Check the NUnit Console.Out to make sure there are SIP requests and responses being displayed. sipTransport1.Shutdown(); sipTransport2.Shutdown(); }
public async Task CancelCallUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport aliceTransport = new SIPTransport(); aliceTransport.AddSIPChannel(new SIPUDPChannel(IPAddress.Loopback, 0)); var alice = new SIPUserAgent(aliceTransport, null, true); SIPServerUserAgent uas = null; // Auto accept but NOT answering. alice.OnIncomingCall += (ua, req) => uas = ua.AcceptCall(req); SIPTransport bobTransport = new SIPTransport(); bobTransport.AddSIPChannel(new SIPUDPChannel(IPAddress.Loopback, 0)); var bob = new SIPUserAgent(bobTransport, null, true); var callTask = bob.Call(alice.ContactURI.ToString(), null, null, CreateMediaSession()); await Task.Delay(500); Assert.True(bob.IsRinging); Assert.NotNull(uas); Assert.False(uas.IsCancelled); bob.Cancel(); await Task.Delay(500); Assert.False(alice.IsCallActive); Assert.False(bob.IsCallActive); Assert.True(uas.IsCancelled); }
void ISipPresenceService.Configure(IDataService dataService, Action <DataConfig, Exception> callback) { _dataService = dataService; _dataService.GetData((cfg, error) => { if (error != null) { callback?.Invoke(null, error); return; } ListenIp = cfg.ListenIp; ListenPort = cfg.ListenPort; SipHelper.IsUserOpen = (s) => { foreach (var user in cfg.LastUsers) { if (s.ResourceURI.ToString().Contains(user.Id)) { return(SIPEventPresenceStateEnum.open); } } return(SIPEventPresenceStateEnum.closed); }; var sipChannel = new SIPUDPChannel(new IPEndPoint(IPAddress.Parse(ListenIp), ListenPort)); _sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); _sipTransport.AddSIPChannel(sipChannel); _sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; _sipTransport.SIPTransportResponseReceived += SIPTransportResponseReceived; m_sip_notifier = new SipPresenceSubscriptionManager(_sipTransport); m_sip_notifier.InternalEvent += (e, m) => { switch (e) { case SipPresenceSubscriptionManager.SipNotifierEvents.Error: _logger.Error(m); break; case SipPresenceSubscriptionManager.SipNotifierEvents.Info: _logger.Info(m); break; case SipPresenceSubscriptionManager.SipNotifierEvents.Notify: break; case SipPresenceSubscriptionManager.SipNotifierEvents.Subscribe: case SipPresenceSubscriptionManager.SipNotifierEvents.Unsubscribe: SubscribeReceived?.Invoke(m); break; } }; callback?.Invoke(cfg, null); }); }
private static Dictionary <string, SIPAccountBinding> _sipRegistrations = new Dictionary <string, SIPAccountBinding>(); // [SIP Username, Binding], tracks SIP clients that have registered with the server. static void Main() { try { Console.WriteLine("SIPSorcery SIP Proxy Demo"); AddConsoleLogger(); // Configure the SIP transport layer. _sipTransport = new SIPTransport(); // Use default options to set up a SIP channel. var sipChannel = new SIPUDPChannel(new IPEndPoint(IPAddress.Any, _listenPort)); _sipTransport.AddSIPChannel(sipChannel); // Wire up the transport layer so SIP requests and responses have somewhere to go. _sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; _sipTransport.SIPTransportResponseReceived += SIPTransportResponseReceived; // If you want to see ALL the nitty gritty SIP traffic wire up the events below. //_sipTransport.SIPBadRequestInTraceEvent += SIPBadRequestInTraceEvent; //_sipTransport.SIPBadResponseInTraceEvent += SIPBadResponseInTraceEvent; _sipTransport.SIPRequestInTraceEvent += SIPRequestInTraceEvent; //_sipTransport.SIPRequestOutTraceEvent += SIPRequestOutTraceEvent; //_sipTransport.SIPResponseInTraceEvent += SIPResponseInTraceEvent; _sipTransport.SIPResponseOutTraceEvent += SIPResponseOutTraceEvent; ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(); } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } }
static void Main() { Console.WriteLine("SIPSorcery Blind Transfer Demo: Transferor"); Console.WriteLine("Start the Transferee and Target programs."); Console.WriteLine("Press c to place call to Transferee."); Console.WriteLine("Press t to initiate the transfer."); Console.WriteLine("Press 'q' or ctrl-c to exit."); AddConsoleLogger(); // Set up a default SIP transport. _sipTransport = new SIPTransport(); _sipTransport.AddSIPChannel(new SIPUDPChannel(new IPEndPoint(IPAddress.Any, SIP_LISTEN_PORT))); EnableTraceLogs(_sipTransport); CancellationTokenSource exitCts = new CancellationTokenSource(); Task.Run(() => OnKeyPress(exitCts)); exitCts.Token.WaitHandle.WaitOne(); #region Cleanup. Log.LogInformation("Exiting..."); if (_sipTransport != null) { Log.LogInformation("Shutting down SIP transport..."); _sipTransport.Shutdown(); } #endregion }
public void Init() { var port = FreePort.FindNextAvailableUDPPort(15090); transport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); publicIPAddress = STUNClient.GetPublicIPAddress("stun.ekiga.net"); localIPEndPoint = IpAddressLookup.QueryRoutingInterface(asterisk, port); var endpoint = new IPEndPoint(localIPEndPoint.Address, port); var channel = new SIPUDPChannel(endpoint); transport.AddSIPChannel(channel); transport.SIPTransportRequestReceived += Transport_SIPTransportRequestReceived; //var registration = new SIPRegistrationUserAgent( // transport, // null, // new SIPEndPoint(SIPProtocolsEnum.udp, publicIPAddress, port), // new SIPURI("1003", asterisk, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp), // "1003", // passwords[0], // null, // asterisk, // new SIPURI(SIPSchemesEnum.sip, new SIPEndPoint(SIPProtocolsEnum.udp, publicIPAddress, port)), // 180, // null, // null, // (e) => { logger.Debug($"{ prefix } SIPRegistrationUserAgent; { e.Message }"); } // ); //registration.RegistrationSuccessful += Registration_RegistrationSuccessful; //registration.RegistrationFailed += Registration_RegistrationFailed; //registration.Start(); }
public void Start() { try { logger.Debug("SIP Registrar daemon starting..."); // Configure the SIP transport layer. Transport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false); Transport.PerformanceMonitorPrefix = SIPSorceryPerformanceMonitor.REGISTRAR_PREFIX; Transport.MsgEncode = _account.MsgEncode; List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(_account.LocalIP, _account.LocalPort, _account.MsgProtocol); Transport.AddSIPChannel(sipChannels); Transport.SIPTransportRequestReceived += AddMessageRequest; Transport.SIPTransportResponseReceived += AddMessageResponse; m_registrarCore = new RegistrarCore(Transport, true, true, SIPRequestAuthenticator.AuthenticateSIPRequest); m_registrarCore.Auth = _account.Authentication; m_registrarCore.Start(1); Console.ForegroundColor = ConsoleColor.Green; logger.Debug("SIP Registrar successfully started."); Console.ForegroundColor = ConsoleColor.White; } catch (Exception excp) { logger.Error("Exception SIPRegistrarDaemon Start. " + excp.Message); } }
/// <summary> /// Initialises a SIP transport to act as a server in single request/response exchange. /// </summary> /// <param name="testServerChannel">The server SIP channel to test.</param> /// <param name="cts">Cancellation token to tell the server when to shutdown.</param> private void RunServer(SIPChannel testServerChannel, CancellationTokenSource cts) { logger.LogDebug($"Starting server task for {testServerChannel.SIPChannelEndPoint.ToString()}."); var serverSIPTransport = new SIPTransport(); try { serverSIPTransport.AddSIPChannel(testServerChannel); logger.LogDebug(serverSIPTransport.GetDefaultSIPEndPoint().ToString()); serverSIPTransport.SIPTransportRequestReceived += (SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) => { logger.LogDebug($"Request received {localSIPEndPoint.ToString()}<-{remoteEndPoint.ToString()}: {sipRequest.StatusLine}"); if (sipRequest.Method == SIPMethodsEnum.OPTIONS) { SIPResponse optionsResponse = SIPTransport.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null); serverSIPTransport.SendResponse(optionsResponse); } }; cts.Token.WaitHandle.WaitOne(); //WaitHandle.WaitAny(new[] { cts.Token.WaitHandle }); } finally { logger.LogDebug($"Server task for completed for {testServerChannel.SIPChannelEndPoint.ToString()}."); serverSIPTransport.Shutdown(); } }
public void Start() { try { logger.Debug("SIP Registrar daemon starting..."); // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false); m_sipTransport.PerformanceMonitorPrefix = SIPSorceryPerformanceMonitor.REGISTRAR_PREFIX; List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(_accounts); //List<SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(account.LocalIP, account.LocalPort); m_sipTransport.AddSIPChannel(sipChannels); MessageBase = new MessageBase(SIPAuthenticateRequest_External, m_sipTransport, SIPConstants.SIP_SERVER_STRING); //MessageCore.Initialize(SIPAuthenticateRequest_External, _platformList,_account); MessageBase.Initialize(SIPAuthenticateRequest_External, _accounts); m_sipTransport.SIPTransportRequestReceived += MessageBase.AddMessageRequest; m_sipTransport.SIPTransportResponseReceived += MessageBase.AddMessageResponse; Console.ForegroundColor = ConsoleColor.Green; logger.Debug("SIP Registrar successfully started."); Console.ForegroundColor = ConsoleColor.White; } catch (Exception excp) { logger.Error("Exception SIPRegistrarDaemon Start. " + excp.Message); } }
/// <summary> /// Initialises a SIP transport to act as the client in a single request/response exchange. /// </summary> /// <param name="testClientChannel">The client SIP channel to test.</param> /// <param name="serverUri">The URI of the server end point to test the client against.</param> /// <param name="tcs">The task completion source that this method will set if it receives the expected response.</param> private async Task RunClient(SIPChannel testClientChannel, SIPURI serverUri, TaskCompletionSource <bool> tcs, CancellationTokenSource cts, ManualResetEventSlim serverReadyEvent) { logger.LogDebug($"RunClient Starting client task for {testClientChannel.ListeningSIPEndPoint}."); var clientSIPTransport = new SIPTransport(); try { clientSIPTransport.AddSIPChannel(testClientChannel); logger.LogDebug($"RunClient test channel created on {testClientChannel.ListeningSIPEndPoint}."); clientSIPTransport.SIPTransportResponseReceived += (SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponse sipResponse) => { logger.LogDebug($"Expected response received {localSIPEndPoint}<-{remoteEndPoint}: {sipResponse.ShortDescription}"); if (sipResponse.Status == SIPResponseStatusCodesEnum.Ok) { // Got the expected response, set the signal. if (!tcs.TrySetResult(true)) { logger.LogWarning($"RunClient on test channel {testClientChannel.ListeningSIPEndPoint} FAILED to set result on CompletionSource."); } } return(Task.FromResult(0)); }; clientSIPTransport.SIPRequestOutTraceEvent += (SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) => { logger.LogDebug($"CLIENT REQUEST OUT {localSIPEndPoint}->{remoteEndPoint}"); logger.LogDebug(sipRequest.ToString()); }; clientSIPTransport.SIPResponseInTraceEvent += (SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPResponse sipResponse) => { logger.LogDebug($"CLIENT RESPONSE IN {localSIPEndPoint}<-{remoteEndPoint}"); logger.LogDebug(sipResponse.ToString()); }; var optionsRequest = SIPRequest.GetRequest(SIPMethodsEnum.OPTIONS, serverUri); logger.LogDebug($"RunClient waiting for server to get ready on {serverUri.CanonicalAddress}."); serverReadyEvent.Wait(cts.Token); await clientSIPTransport.SendRequestAsync(optionsRequest); await tcs.Task; } catch (Exception excp) { logger.LogError($"Exception RunClient. {excp.Message}"); } finally { logger.LogDebug($"Client task completed for {testClientChannel.ListeningSIPEndPoint}."); clientSIPTransport.Shutdown(); logger.LogDebug($"Client task SIP transport shutdown."); } }
public void B2BOptionsStatefulProxyTest() { SIPTransactionEngine transactionEngine1 = new SIPTransactionEngine(); SIPTransport sipTransport1 = new SIPTransport(SIPDNSManager.Resolve, transactionEngine1, true, false); sipTransport1.AddSIPChannel(new SIPUDPChannel(new IPEndPoint(IPAddress.Loopback, 3000))); SIPAppServerCore appServerCore1 = new SIPAppServerCore(sipTransport1, null, statefulProxyCore1_StatefulProxyLogEvent, null, null, null); SIPTransactionEngine transactionEngine2 = new SIPTransactionEngine(); SIPTransport sipTransport2 = new SIPTransport(SIPDNSManager.Resolve, transactionEngine2, true, false); sipTransport2.AddSIPChannel(new SIPUDPChannel(new IPEndPoint(IPAddress.Loopback, 3001))); SIPAppServerCore appServerCore2 = new SIPAppServerCore(sipTransport2, null, statefulProxyCore2_StatefulProxyLogEvent, null, null, null); sipTransport1.SIPRequestOutTraceEvent += sipTransport1_SIPRequestOutTraceEvent; sipTransport1.SIPResponseInTraceEvent += sipTransport1_SIPResponseInTraceEvent; sipTransport2.SIPRequestInTraceEvent += sipTransport2_SIPRequestInTraceEvent; SIPRequest optionsRequest = GetOptionsRequest(SIPURI.ParseSIPURI("sip:127.0.0.1:3001"), 1, sipTransport1.GetDefaultTransportContact(SIPProtocolsEnum.udp).SocketEndPoint); sipTransport1.SendRequest(optionsRequest); Thread.Sleep(200); // Check the NUnit Console.Out to make sure there are SIP requests and responses being displayed. sipTransport1.Shutdown(); sipTransport2.Shutdown(); }
static void Main(string[] args) { try { // Configure the SIP transport layer. _sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); // Use default options to set up a SIP channel. var localIP = LocalIPConfig.GetDefaultIPv4Address(); // Set this manually if needed. int port = FreePort.FindNextAvailableUDPPort(_defaultSIPUdpPort); var sipChannel = new SIPUDPChannel(new IPEndPoint(localIP, port)); _sipTransport.AddSIPChannel(sipChannel); SIPCallDescriptor callDescriptor = new SIPCallDescriptor("test", null, "sip:[email protected]", "sip:[email protected]", null, null, null, null, SIPCallDirection.Out, null, null, null); SIPNonInviteClientUserAgent notifyUac = new SIPNonInviteClientUserAgent(_sipTransport, null, callDescriptor, null, null, (monitorEvent) => { Console.WriteLine("Debug: " + monitorEvent.Message); }); notifyUac.ResponseReceived += (resp) => { Console.WriteLine(resp.ToString()); }; notifyUac.SendRequest(SIPMethodsEnum.NOTIFY); ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(); } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } finally { Console.WriteLine("Press any key to exit..."); Console.ReadLine(); } }
static async Task Main() { Console.WriteLine("SIPSorcery Load Test Server:"); Console.WriteLine("Press 'd' to send a random DTMF tone to the newest call."); Console.WriteLine("Press 'h' to hangup the oldest call."); Console.WriteLine("Press 'H' to hangup all calls."); Console.WriteLine("Press 'l' to list current calls."); Console.WriteLine("Press 'q' to quit."); AddConsoleLogger(); // Set up a default SIP transport. _sipTransport = new SIPTransport(); _sipTransport.AddSIPChannel(new SIPUDPChannel(new IPEndPoint(IPAddress.Any, SIP_LISTEN_PORT))); EnableTraceLogs(_sipTransport, false); _sipTransport.SIPTransportRequestReceived += OnRequest; CancellationTokenSource exitCts = new CancellationTokenSource(); await Task.Run(() => OnKeyPress(exitCts.Token)); Log.LogInformation("Exiting..."); if (_sipTransport != null) { Log.LogInformation("Shutting down SIP transport..."); _sipTransport.Shutdown(); } }
public void Start() { try { logger.Debug("RTCC Daemon starting..."); // Pre-flight checks. if (m_rtccSIPSocketsNode == null || m_rtccSIPSocketsNode.ChildNodes.Count == 0) { throw new ApplicationException("The RTCC server cannot start without a SIP socket, please check config file."); } // Send events from this process to the monitoring socket. if (m_monitorLoopbackPort != 0) { // Events will be sent by the monitor channel to the loopback interface and this port. m_monitorEventWriter = new SIPMonitorEventWriter(m_monitorLoopbackPort); logger.Debug("Monitor channel initialised for 127.0.0.1:" + m_monitorLoopbackPort + "."); } // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false); List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_rtccSIPSocketsNode); m_sipTransport.AddSIPChannel(sipChannels); if (m_cdrDataLayer != null) { SIPCDR.CDRCreated += m_cdrDataLayer.Add; SIPCDR.CDRAnswered += m_cdrDataLayer.Update; SIPCDR.CDRHungup += m_cdrDataLayer.Update; SIPCDR.CDRUpdated += m_cdrDataLayer.Update; } m_sipDialogueManager = new SIPDialogueManager( m_sipTransport, m_outboundProxy, FireSIPMonitorEvent, m_sipSorceryPersistor.SIPDialoguePersistor, m_sipSorceryPersistor.SIPCDRPersistor, SIPRequestAuthenticator.AuthenticateSIPRequest, m_sipSorceryPersistor.SIPAccountsPersistor.Get, m_sipSorceryPersistor.SIPDomainManager.GetDomain); m_rtccCore = new RTCCCore( FireSIPMonitorEvent, m_sipDialogueManager, m_sipSorceryPersistor.SIPDialoguePersistor); m_rtccCore.Start(); m_rateUpdater = new RateBulkUpdater(FireSIPMonitorEvent); m_rateUpdater.Start(); logger.Debug("RTCC Daemon successfully started."); } catch (Exception excp) { logger.Error("Exception RTCCDaemon Start. " + excp.Message); } }
private static Dictionary <string, SIPRegistrarBinding> _sipRegistrations = new Dictionary <string, SIPRegistrarBinding>(); // [SIP Username, Contact Address], tracks SIP clients that have registered with the server. static void Main(string[] args) { try { // Configure the SIP transport layer. _sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine()); if (_sipSocketsNode != null) { // Set up the SIP channels based on the app.config file. List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(_sipSocketsNode); _sipTransport.AddSIPChannel(sipChannels); } else { // Use default options to set up a SIP channel. int port = FreePort.FindNextAvailableUDPPort(_defaultSIPUdpPort); var sipChannel = new SIPUDPChannel(new IPEndPoint(_defaultLocalAddress, port)); _sipTransport.AddSIPChannel(sipChannel); } // Wire up the transport layer so SIP requests and responses have somewhere to go. _sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; _sipTransport.SIPTransportResponseReceived += SIPTransportResponseReceived; // If you want to see ALL the nitty gritty SIP traffic wire up the events below. //_sipTransport.SIPBadRequestInTraceEvent += SIPBadRequestInTraceEvent; //_sipTransport.SIPBadResponseInTraceEvent += SIPBadResponseInTraceEvent; //_sipTransport.SIPRequestInTraceEvent += SIPRequestInTraceEvent; //_sipTransport.SIPRequestOutTraceEvent += SIPRequestOutTraceEvent; //_sipTransport.SIPResponseInTraceEvent += SIPResponseInTraceEvent; //_sipTransport.SIPResponseOutTraceEvent += SIPResponseOutTraceEvent; ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(); } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } finally { Console.WriteLine("Press any key to exit..."); Console.ReadLine(); } }
private static Dictionary <string, SIPAccountBinding> _sipRegistrations = new Dictionary <string, SIPAccountBinding>(); // [SIP Username, Binding], tracks SIP clients that have registered with the server. static void Main() { try { Console.WriteLine("SIPSorcery SIP Proxy Demo"); logger = SIPSorcery.Sys.Log.Logger; // Configure the SIP transport layer. _sipTransport = new SIPTransport(); if (_sipSocketsNode != null) { // Set up the SIP channels based on the app.config file. List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(_sipSocketsNode); _sipTransport.AddSIPChannel(sipChannels); } else { // Use default options to set up a SIP channel. var sipChannel = new SIPUDPChannel(new IPEndPoint(_defaultLocalAddress, _defaultSIPUdpPort)); _sipTransport.AddSIPChannel(sipChannel); } // Wire up the transport layer so SIP requests and responses have somewhere to go. _sipTransport.SIPTransportRequestReceived += SIPTransportRequestReceived; _sipTransport.SIPTransportResponseReceived += SIPTransportResponseReceived; // If you want to see ALL the nitty gritty SIP traffic wire up the events below. //_sipTransport.SIPBadRequestInTraceEvent += SIPBadRequestInTraceEvent; //_sipTransport.SIPBadResponseInTraceEvent += SIPBadResponseInTraceEvent; _sipTransport.SIPRequestInTraceEvent += SIPRequestInTraceEvent; //_sipTransport.SIPRequestOutTraceEvent += SIPRequestOutTraceEvent; //_sipTransport.SIPResponseInTraceEvent += SIPResponseInTraceEvent; _sipTransport.SIPResponseOutTraceEvent += SIPResponseOutTraceEvent; ManualResetEvent mre = new ManualResetEvent(false); mre.WaitOne(); } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp); } }
static void Main() { Console.WriteLine("SIPSorcery sip.js Demo"); Log = AddConsoleLogger(); var sipTransport = new SIPTransport(); EnableTraceLogs(sipTransport); var sipChannel = new SIPWebSocketChannel(IPAddress.Loopback, 8081); sipTransport.AddSIPChannel(sipChannel); var userAgent = new SIPUserAgent(sipTransport, null, true); userAgent.OnIncomingCall += async(ua, req) => { Log.LogDebug($"Auto-answering incoming call from {req.Header.From}."); var uas = userAgent.AcceptCall(req); var peerConnection = new RTCPeerConnection(null); peerConnection.onconnectionstatechange += (state) => { Log.LogDebug($"Peer connection state change to {state}."); if (state == RTCPeerConnectionState.failed) { peerConnection.Close("ice disconnection"); } else if (state == RTCPeerConnectionState.connected) { peerConnection.OnRtpPacketReceived += OnRtpPacketReceived; } else if (state == RTCPeerConnectionState.closed) { peerConnection.OnRtpPacketReceived -= OnRtpPacketReceived; } }; MediaStreamTrack audioTrack = new MediaStreamTrack(new List <AudioFormat> { new AudioFormat(SDPWellKnownMediaFormatsEnum.PCMU) }, MediaStreamStatusEnum.SendRecv); peerConnection.addTrack(audioTrack); //MediaStreamTrack videoTrack = new MediaStreamTrack("1", SDPMediaTypesEnum.video, false, new List<SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.VP8) }, MediaStreamStatusEnum.Inactive); //peerConnection.addTrack(videoTrack); var answerResult = await userAgent.Answer(uas, peerConnection); }; Console.Write("press any key to exit..."); Console.Read(); sipTransport.Shutdown(); }
public async Task UacTxCheckRemoteSocketProxyReceivedUnitTestUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPEndPoint dummyEP = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 5060)); string inviteReqStr = @"INVITE sip:[email protected]:12014 SIP/2.0 Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27 To: <sip:[email protected]:12014> From: <sip:[email protected]>;tag=2062917371 Call-ID: 8ae45c15425040179a4285d774ccbaf6 CSeq: 1 INVITE Contact: <sip:127.0.0.1:1234> Max-Forwards: 70 User-Agent: unittest Content-Length: 5 Content-Type: application/sdp dummy"; var sipReqBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummyEP, dummyEP); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipReqBuffer); string okRespStr = @"SIP/2.0 200 OK Via: SIP/2.0/UDP 127.0.0.1:1234;branch=z9hG4bK5f37455955ca433a902f8fea0ce2dc27;rport=12013 To: <sip:[email protected]:12014> From: <sip:[email protected]>;tag=2062917371 Call-ID: 8ae45c15425040179a4285d774ccbaf6 Contact: <sip:127.0.0.1:1234> CSeq: 1 INVITE Content-Length: 5 Content-Type: application/sdp Proxy-ReceivedFrom: udp:192.168.0.50:5080 dummy"; var sipRespBuffer = SIPMessageBuffer.ParseSIPMessage(okRespStr, dummyEP, dummyEP); SIPResponse okResponse = SIPResponse.ParseSIPResponse(sipRespBuffer); SIPTransport transport = new SIPTransport(); transport.AddSIPChannel(new MockSIPChannel(dummyEP.GetIPEndPoint())); UACInviteTransaction uacTx = new UACInviteTransaction(transport, inviteReq, null); await uacTx.GotResponse(dummyEP, dummyEP, okResponse); var dialogue = new SIPDialogue(uacTx); Assert.NotNull(dialogue); Assert.Equal(SIPURI.ParseSIPURI("sip:127.0.0.1:1234"), dialogue.RemoteTarget); Assert.Equal(SIPEndPoint.ParseSIPEndPoint("udp:192.168.0.50:5080"), dialogue.RemoteSIPEndPoint); logger.LogDebug("---------------------------------------------------"); }
public async Task BlindTransferCancelUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); SIPTransport transport = new SIPTransport(); transport.AddSIPChannel(new MockSIPChannel(new System.Net.IPEndPoint(IPAddress.Any, 0))); SIPUserAgent userAgent = new SIPUserAgent(transport, null); string inviteReqStr = "INVITE sip:192.168.11.50:5060 SIP/2.0" + m_CRLF + "Via: SIP/2.0/UDP 192.168.11.50:60163;rport;branch=z9hG4bKPj869f70960bdd4204b1352eaf242a3691" + m_CRLF + "To: <sip:[email protected]>;tag=ZUJSXRRGXQ" + m_CRLF + "From: <sip:[email protected]>;tag=4a60ce364b774258873ff199e5e39938" + m_CRLF + "Call-ID: 17324d6df8744d978008c8997bfd208d" + m_CRLF + "CSeq: 3532 INVITE" + m_CRLF + "Contact: <sip:[email protected]:60163;ob>" + m_CRLF + "Max-Forwards: 70" + m_CRLF + "User-Agent: MicroSIP/3.19.22" + m_CRLF + "Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS" + m_CRLF + "Supported: replaces, 100rel, timer, norefersub" + m_CRLF + "Content-Length: 343" + m_CRLF + "Content-Type: application/sdp" + m_CRLF + "Session-Expires: 1800" + m_CRLF + "Min-SE: 90" + m_CRLF + "" + m_CRLF + "v=0" + m_CRLF + "o=- 3785527268 3785527269 IN IP4 192.168.11.50" + m_CRLF + "s=pjmedia" + m_CRLF + "t=0 0" + m_CRLF + "m=audio 4032 RTP/AVP 0 101" + m_CRLF + "c=IN IP4 192.168.11.50" + m_CRLF + "a=rtpmap:0 PCMU/8000" + m_CRLF + "a=rtpmap:101 telephone-event/8000" + m_CRLF + "a=fmtp:101 0-16" + m_CRLF + "a=sendrecv"; SIPEndPoint dummySipEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0)); SIPMessageBuffer sipMessageBuffer = SIPMessageBuffer.ParseSIPMessage(inviteReqStr, dummySipEndPoint, dummySipEndPoint); SIPRequest inviteReq = SIPRequest.ParseSIPRequest(sipMessageBuffer); UASInviteTransaction uasTx = new UASInviteTransaction(transport, inviteReq, null); SIPServerUserAgent mockUas = new SIPServerUserAgent(transport, null, null, null, SIPCallDirection.In, null, null, null, uasTx); await userAgent.Answer(mockUas, CreateMediaSession()); CancellationTokenSource cts = new CancellationTokenSource(); var blindTransferTask = userAgent.BlindTransfer(SIPURI.ParseSIPURIRelaxed("127.0.0.1"), TimeSpan.FromSeconds(2), cts.Token); cts.Cancel(); Assert.False(await blindTransferTask); //await Assert.ThrowsAnyAsync<TaskCanceledException>(async () => { bool result = ; }); }
public async void WebSocketLoopbackLargeSendReceiveTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); var serverChannel = new SIPWebSocketChannel(IPAddress.Loopback, 9001); var clientChannel = new SIPClientWebSocketChannel(); var sipTransport = new SIPTransport(); sipTransport.AddSIPChannel(new List <SIPChannel> { serverChannel, clientChannel }); ManualResetEvent gotResponseMre = new ManualResetEvent(false); SIPRequest receivedRequest = null; SIPResponse receivedResponse = null; sipTransport.SIPTransportRequestReceived += (localSIPEndPoint, remoteEndPoint, sipRequest) => { receivedRequest = sipRequest; SIPResponse optionsResponse = SIPResponse.GetResponse(sipRequest, SIPResponseStatusCodesEnum.Ok, null); optionsResponse.Header.UnknownHeaders.Add($"X-Response-Random:{Crypto.GetRandomString(1000)}"); optionsResponse.Header.UnknownHeaders.Add("X-Response-Final: TheEnd"); return(sipTransport.SendResponseAsync(optionsResponse)); }; sipTransport.SIPTransportResponseReceived += (localSIPEndPoint, remoteEndPoint, sipResponse) => { receivedResponse = sipResponse; gotResponseMre.Set(); return(Task.CompletedTask); }; var serverUri = serverChannel.GetContactURI(SIPSchemesEnum.sip, clientChannel.ListeningSIPEndPoint); var optionsRequest = SIPRequest.GetRequest(SIPMethodsEnum.OPTIONS, serverUri); optionsRequest.Header.UnknownHeaders.Add($"X-Request-Random:{Crypto.GetRandomString(1000)}"); optionsRequest.Header.UnknownHeaders.Add("X-Request-Final: TheEnd"); await sipTransport.SendRequestAsync(optionsRequest); gotResponseMre.WaitOne(TRANSPORT_TEST_TIMEOUT, false); Assert.NotNull(receivedRequest); Assert.NotNull(receivedResponse); //rj2: confirm that we have received the whole SIP-Message by checking for the last x-header (issue #175, websocket fragmented send/receive) Assert.Contains("X-Request-Final: TheEnd", receivedRequest.Header.UnknownHeaders); Assert.Contains("X-Response-Final: TheEnd", receivedResponse.Header.UnknownHeaders); sipTransport.Shutdown(); logger.LogDebug("Test complete."); }
public void Start() { try { logger.Debug("SIP Notifier Daemon starting..."); // Pre-flight checks. if (m_sipNotifierSocketsNode == null || m_sipNotifierSocketsNode.ChildNodes.Count == 0) { throw new ApplicationException("The SIP Notifier cannot start without at least one socket specified to listen on, please check config file."); } // Send events from this process to the monitoring socket. if (m_monitorLoopbackPort != 0) { // Events will be sent by the monitor channel to the loopback interface and this port. m_monitorEventWriter = new SIPMonitorEventWriter(m_monitorLoopbackPort); logger.Debug("Monitor channel initialised for 127.0.0.1:" + m_monitorLoopbackPort + "."); } // Configure the SIP transport layer. m_sipTransport = new SIPTransport(SIPDNSManager.ResolveSIPService, new SIPTransactionEngine(), false); List <SIPChannel> sipChannels = SIPTransportConfig.ParseSIPChannelsNode(m_sipNotifierSocketsNode); m_sipTransport.AddSIPChannel(sipChannels); m_notifierCore = new NotifierCore( FireSIPMonitorEvent, m_sipTransport, GetCustomer_External, GetDialogues_External, GetDialogue_External, GetCanonicalDomain_External, m_sipAssetPersistor, GetBindingsCount_External, SIPAuthenticateRequest_External, m_outboundProxy, m_publisher); m_notifyManager = new SIPNotifyManager( m_sipTransport, m_outboundProxy, FireSIPMonitorEvent, m_sipAssetPersistor.Get, GetSIPRegistrarBindings_External, GetCanonicalDomain_External); m_sipTransport.SIPTransportRequestReceived += GotRequest; logger.Debug("SIP Notifier Daemon successfully started."); } catch (Exception excp) { logger.Error("Exception SIPNotifierDaemon Start. " + excp.Message); } }