Пример #1
0
        void IdentHashLookup_RouterInfoReceived(I2PRouterInfo ri)
        {
            LookupDestination lud = null;

            lock ( QueuedMessages )
            {
                if (QueuedMessages.TryGetValue(ri.Identity.IdentHash, out lud))
                {
                    Logging.LogTransport("UnknownRouterQueue: IdentHashLookup_RouterInfoReceived: Destination " +
                                         ri.Identity.IdentHash.Id32Short + " found. Sending.");

                    QueuedMessages.Remove(ri.Identity.IdentHash);
                }
            }

            if (lud != null)
            {
                try
                {
                    foreach (var msg in lud.Messages)
                    {
                        TransportProvider.Send(ri.Identity.IdentHash, msg);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Log("UnknownRouterQueue", ex);
                }
            }
        }
Пример #2
0
 public static void Start()
 {
     if (Inst != null)
     {
         return;
     }
     Inst = new TransportProvider();
 }
Пример #3
0
        private void Run()
        {
            try
            {
                var ntcphost = new NTCPHost();

                ntcphost.ConnectionCreated += new Action <ITransport>(ntcphost_ConnectionCreated);
                SsuHost.ConnectionCreated  += new Action <ITransport>(SsuHost_ConnectionCreated);

                while (!Terminated)
                {
                    try
                    {
                        Thread.Sleep(1000);

                        var known = CurrentlyUnknownRouters.FindKnown();
                        foreach (var found in known)
                        {
                            foreach (var msg in found.Messages)
                            {
                                Logging.LogTransport("TransportProvider: Destination " + found.Destination.Id32Short + " found. Sending data.");
                                TransportProvider.Send(found.Destination, msg);
                            }
                        }

                        ActiveConnectionLog.Log(() => string.Format("TransportProvider: Running: {0}. Established: {1}.",
                                                                    RunningTransports.Count,
                                                                    EstablishedTransports.Count));

                        DropOldExceptions.Do(delegate
                        {
                            lock ( AddressesWithExceptions )
                            {
                                var remove = AddressesWithExceptions.Where(eh =>
                                                                           eh.Value.Generated.DeltaToNow.ToMinutes >= ExeptionHistoryLifetimeMinutes).Select(eh => eh.Key).ToArray();
                                foreach (var one in remove)
                                {
                                    AddressesWithExceptions.Remove(one);
                                }
                            }
                        });
                    }
                    catch (ThreadAbortException ex)
                    {
                        Logging.Log(ex);
                    }
                    catch (Exception ex)
                    {
                        Logging.Log(ex);
                    }
                }
            }
            finally
            {
                Terminated = true;
            }
        }