Ejemplo n.º 1
0
 /// <summary>
 /// Raises the <see cref="E:ORConnectionChanged" /> event.
 /// </summary>
 /// <param name="e">The <see cref="ORConnectionEventArgs"/> instance containing the event data.</param>
 internal void OnORConnectionChanged(ORConnectionEventArgs e)
 {
     if (orConnectionChangedHandlers != null)
     {
         orConnectionChangedHandlers(client, e);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when an OR connection changes within the tor service.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="ORConnectionEventArgs"/> instance containing the event data.</param>
        private void OnORConnectionChanged(object sender, ORConnectionEventArgs e)
        {
            if (e.Connection == null)
            {
                return;
            }

            lock (synchronizeORConnections)
            {
                ORConnection existing;

                if (e.Connection.ID != 0)
                {
                    existing = orConnections.Where(o => o.ID == e.Connection.ID).FirstOrDefault();
                }
                else
                {
                    existing = orConnections.Where(o => o.Target.Equals(e.Connection.Target, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
                }

                if (existing == null)
                {
                    if (Status.MaximumRecords <= orConnections.Count)
                    {
                        ORConnection removal = orConnections.Where(o => o.Status == ORStatus.Closed || o.Status == ORStatus.Failed).FirstOrDefault();

                        if (removal == null)
                        {
                            return;
                        }

                        orConnections.Remove(removal);
                    }

                    existing = e.Connection;
                    orConnections.Add(existing);
                }
                else
                {
                    existing.CircuitCount = e.Connection.CircuitCount;
                    existing.ID           = e.Connection.ID;
                    existing.Reason       = e.Connection.Reason;
                    existing.Status       = e.Connection.Status;
                    existing.Target       = e.Connection.Target;
                }
            }

            if (ORConnectionsChanged != null)
            {
                ORConnectionsChanged(client, EventArgs.Empty);
            }
        }