/// <summary> /// Raises <b>SessionCompleted</b> event. /// </summary> /// <param name="session">Session what completed processing.</param> /// <param name="exception">Exception happened or null if relay completed successfully.</param> internal protected virtual void OnSessionCompleted(Relay_Session session, Exception exception) { if (this.SessionCompleted != null) { this.SessionCompleted(new Relay_SessionCompletedEventArgs(session, exception)); } }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Relay session what completed processing.</param> /// <param name="exception">Exception what happened or null if relay completed successfully.</param> /// <exception cref="ArgumentNullException">Is raised when <b>session</b> is null.</exception> public Relay_SessionCompletedEventArgs(Relay_Session session,Exception exception) { if(session == null){ throw new ArgumentNullException("session"); } m_pSession = session; m_pException = exception; }
/// <summary> /// Default constructor. /// </summary> /// <param name="session">Relay session what completed processing.</param> /// <param name="exception">Exception what happened or null if relay completed successfully.</param> /// <exception cref="ArgumentNullException">Is raised when <b>session</b> is null.</exception> public Relay_SessionCompletedEventArgs(Relay_Session session, Exception exception) { if (session == null) { throw new ArgumentNullException("session"); } m_pSession = session; m_pException = exception; }
/// <summary> /// Raises <b>SessionCompleted</b> event. /// </summary> /// <param name="session">Session what completed processing.</param> /// <param name="exception">Exception happened or null if relay completed successfully.</param> internal protected virtual void OnSessionCompleted(Relay_Session session,Exception exception) { if(this.SessionCompleted != null){ this.SessionCompleted(new Relay_SessionCompletedEventArgs(session,exception)); } }
/// <summary> /// Processes relay queue. /// </summary> private void Run() { while(m_IsRunning){ try{ // Bind info has changed, create new local end points. if(m_HasBindingsChanged){ m_pLocalEndPointIPv4.Clear(); m_pLocalEndPointIPv6.Clear(); foreach(IPBindInfo binding in m_pBindings){ if(binding.IP == IPAddress.Any){ foreach(IPAddress ip in System.Net.Dns.GetHostAddresses("")){ if(ip.AddressFamily == AddressFamily.InterNetwork){ IPBindInfo b = new IPBindInfo(binding.HostName,binding.Protocol,ip,25); if(!m_pLocalEndPointIPv4.Contains(b)){ m_pLocalEndPointIPv4.Add(b); } } } } else if(binding.IP == IPAddress.IPv6Any){ foreach(IPAddress ip in System.Net.Dns.GetHostAddresses("")){ if(ip.AddressFamily == AddressFamily.InterNetworkV6){ IPBindInfo b = new IPBindInfo(binding.HostName,binding.Protocol,ip,25); if(!m_pLocalEndPointIPv6.Contains(b)){ m_pLocalEndPointIPv6.Add(b); } } } } else{ IPBindInfo b = new IPBindInfo(binding.HostName,binding.Protocol,binding.IP,25); if(binding.IP.AddressFamily == AddressFamily.InterNetwork){ if(!m_pLocalEndPointIPv4.Contains(b)){ m_pLocalEndPointIPv4.Add(b); } } else{ if(!m_pLocalEndPointIPv6.Contains(b)){ m_pLocalEndPointIPv6.Add(b); } } } } m_HasBindingsChanged = false; } // There are no local end points specified. if(m_pLocalEndPointIPv4.Count == 0 && m_pLocalEndPointIPv6.Count == 0){ Thread.Sleep(10); } // Maximum allowed relay sessions exceeded, skip adding new ones. else if(m_MaxConnections != 0 && m_pSessions.Count >= m_MaxConnections){ Thread.Sleep(10); } else{ Relay_QueueItem item = null; // Get next queued message from highest possible priority queue. foreach(Relay_Queue queue in m_pQueues){ item = queue.DequeueMessage(); // There is queued message. if(item != null){ break; } // No messages in this queue, see next lower priority queue. } // There are no messages in any queue. if(item == null){ Thread.Sleep(10); } // Create new session for queued relay item. else{ if(m_RelayMode == Relay_Mode.Dns){ Relay_Session session = new Relay_Session(this,item); m_pSessions.Add(session); ThreadPool.QueueUserWorkItem(new WaitCallback(session.Start)); } else if(m_RelayMode == Relay_Mode.SmartHost){ // Get smart hosts in balance mode order. Relay_SmartHost[] smartHosts = null; if(m_SmartHostsBalanceMode == BalanceMode.FailOver){ smartHosts = m_pSmartHosts.ToArray(); } else{ smartHosts = m_pSmartHosts.ToCurrentOrderArray(); } Relay_Session session = new Relay_Session(this,item,smartHosts); m_pSessions.Add(session); ThreadPool.QueueUserWorkItem(new WaitCallback(session.Start)); } } } } catch(Exception x){ OnError(x); } } }
/// <summary> /// Processes relay queue. /// </summary> private void Run() { while (m_IsRunning) { try{ // Bind info has changed, create new local end points. if (m_HasBindingsChanged) { m_pLocalEndPointIPv4.Clear(); m_pLocalEndPointIPv6.Clear(); foreach (IPBindInfo binding in m_pBindings) { if (binding.IP == IPAddress.Any) { foreach (IPAddress ip in System.Net.Dns.GetHostAddresses("")) { if (ip.AddressFamily == AddressFamily.InterNetwork) { IPBindInfo b = new IPBindInfo(binding.HostName, binding.Protocol, ip, 25); if (!m_pLocalEndPointIPv4.Contains(b)) { m_pLocalEndPointIPv4.Add(b); } } } } else if (binding.IP == IPAddress.IPv6Any) { foreach (IPAddress ip in System.Net.Dns.GetHostAddresses("")) { if (ip.AddressFamily == AddressFamily.InterNetworkV6) { IPBindInfo b = new IPBindInfo(binding.HostName, binding.Protocol, ip, 25); if (!m_pLocalEndPointIPv6.Contains(b)) { m_pLocalEndPointIPv6.Add(b); } } } } else { IPBindInfo b = new IPBindInfo(binding.HostName, binding.Protocol, binding.IP, 25); if (binding.IP.AddressFamily == AddressFamily.InterNetwork) { if (!m_pLocalEndPointIPv4.Contains(b)) { m_pLocalEndPointIPv4.Add(b); } } else { if (!m_pLocalEndPointIPv6.Contains(b)) { m_pLocalEndPointIPv6.Add(b); } } } } m_HasBindingsChanged = false; } // There are no local end points specified. if (m_pLocalEndPointIPv4.Count == 0 && m_pLocalEndPointIPv6.Count == 0) { Thread.Sleep(10); } // Maximum allowed relay sessions exceeded, skip adding new ones. else if (m_MaxConnections != 0 && m_pSessions.Count >= m_MaxConnections) { Thread.Sleep(10); } else { Relay_QueueItem item = null; // Get next queued message from highest possible priority queue. foreach (Relay_Queue queue in m_pQueues) { item = queue.DequeueMessage(); // There is queued message. if (item != null) { break; } // No messages in this queue, see next lower priority queue. } // There are no messages in any queue. if (item == null) { Thread.Sleep(10); } // Create new session for queued relay item. else { if (m_RelayMode == Relay_Mode.Dns) { Relay_Session session = new Relay_Session(this, item); m_pSessions.Add(session); ThreadPool.QueueUserWorkItem(new WaitCallback(session.Start)); } else if (m_RelayMode == Relay_Mode.SmartHost) { // Get smart hosts in balance mode order. Relay_SmartHost[] smartHosts = null; if (m_SmartHostsBalanceMode == BalanceMode.FailOver) { smartHosts = m_pSmartHosts.ToArray(); } else { smartHosts = m_pSmartHosts.ToCurrentOrderArray(); } Relay_Session session = new Relay_Session(this, item, smartHosts); m_pSessions.Add(session); ThreadPool.QueueUserWorkItem(new WaitCallback(session.Start)); } } } } catch (Exception x) { OnError(x); } } }