Exemplo n.º 1
0
        void DestinationMessageReceived(I2NPMessage msg)
        {
#if LOG_ALL_TUNNEL_TRANSFER
            DebugUtils.LogDebug("ClientDestination: DestinationMessageReceived: " + msg.ToString());
#endif
            if (msg.MessageType == I2NPMessage.MessageTypes.Data && DataReceived != null)
            {
                var dmsg = (DataMessage)msg.Header16.Message;
                DataReceived(dmsg.Payload);
            }

            if (msg.MessageType == I2NPMessage.MessageTypes.DatabaseStore)
            {
                var dbsmsg = (DatabaseStoreMessage)msg.Header16.Message;
                if (dbsmsg.LeaseSet != null)
                {
                    Destinations.RemoteLeaseSetUpdated(dbsmsg.LeaseSet);
                }
            }
        }
Exemplo n.º 2
0
        private static bool Send(I2PIdentHash dest, I2NPMessage data, int reclvl)
        {
            ITransport transp = null;

            try
            {
                if (dest == RouterContext.Inst.MyRouterIdentity.IdentHash)
                {
                    Logging.LogTransport("TransportProvider: Loopback " + data.ToString());
                    TransportProvider.Inst.DistributeIncomingMessage(null, data.Header16);
                    return(true);
                }

                if (TransportProvider.Inst.CurrentlyUnknownRouters.Contains(dest))
                {
                    TransportProvider.Inst.CurrentlyUnknownRouters.Add(dest, data);
                    return(true);
                }

                transp = TransportProvider.Inst.GetEstablishedTransport(dest, false);
                if (transp != null)
                {
                    transp.Send(data);
                    return(true);
                }

                if (NetDb.Inst.Contains(dest))
                {
                    transp = TransportProvider.Inst.GetTransport(dest);
                    if (transp == null)
                    {
                        throw new ArgumentException("Unable to contact " + dest.ToString());
                    }
                    transp.Send(data);
                }
                else
                {
                    if (TransportProvider.Inst.CurrentlyUnresolvableRouters.Contains(dest))
                    {
                        throw new ArgumentException("Unable to resolve " + dest.ToString());
                    }

                    TransportProvider.Inst.CurrentlyUnknownRouters.Add(dest, data);
                }
            }
            catch (FailedToConnectException ex)
            {
                if (transp != null)
                {
                    TransportProvider.Inst.Remove(transp);
                }

                if (dest != null && NetDb.Inst != null)
                {
                    NetDb.Inst.Statistics.FailedToConnect(dest);
                }
                Logging.LogTransport("TransportProvider.Send: " + (transp == null ? "<>" : transp.DebugId) +
                                     " Exception " + ex.GetType().ToString() + ", " + ex.Message);

                throw;
            }
            catch (EndOfStreamEncounteredException ex)
            {
                TransportProvider.Inst.Remove(transp);

                Logging.LogTransport("TransportProvider.Send: Connection " + (transp == null ? "<>" : transp.DebugId) +
                                     " closed exception: " + ex.GetType().ToString() + ", " + ex.Message);

                if (reclvl > 1 || !Send(dest, data, reclvl + 1))
                {
                    Logging.LogTransport("TransportProvider.Send: Recconnection failed to " + dest.Id32Short + ", reclvl: " + reclvl.ToString() + ".");
                    throw;
                }
            }
            catch (RouterUnresolvableException ex)
            {
                if (dest != null)
                {
                    NetDb.Inst.Statistics.DestinationInformationFaulty(dest);
                }
                Logging.LogTransport("TransportProvider.Send: Unresolvable router: " + ex.Message);

                throw;
            }
            catch (Exception ex)
            {
                if (transp != null)
                {
                    TransportProvider.Inst.Remove(transp);
                }

                if (dest != null)
                {
                    NetDb.Inst.Statistics.DestinationInformationFaulty(dest);
                }
                Logging.LogTransport("TransportProvider.Send: Exception " + ex.GetType().ToString() + ", " + ex.Message);

                throw;
            }
            return(true);
        }