Exemplo n.º 1
0
        static void TunnelProvider_I2NPMessageReceived(II2NPHeader msg)
        {
            switch (msg.MessageType)
            {
            case I2NPMessage.MessageTypes.DatabaseStore:
                var ds = (DatabaseStoreMessage)msg.Message;
#if LOG_ALL_TUNNEL_TRANSFER
                Logging.Log($"Router: DatabaseStore : {ds.Key.Id32Short}");
#endif
                HandleDatabaseStore(ds);
                break;

            case I2NPMessage.MessageTypes.DatabaseSearchReply:
                var dsr = (DatabaseSearchReplyMessage)msg.Message;
#if LOG_ALL_TUNNEL_TRANSFER
                Logging.Log($"Router: DatabaseSearchReply: {dsr}");
#endif
                NetDb.Inst.AddDatabaseSearchReply(dsr);
                break;

            case I2NPMessage.MessageTypes.DeliveryStatus:
#if LOG_ALL_TUNNEL_TRANSFER || LOG_ALL_LEASE_MGMT
                Logging.LogDebug($"Router: DeliveryStatus: {msg.Message}");
#endif

                var dsmsg = (DeliveryStatusMessage)msg.Message;
                DeliveryStatusReceived?.Invoke(dsmsg);
                break;

            case I2NPMessage.MessageTypes.Garlic:
#if LOG_ALL_TUNNEL_TRANSFER
                Logging.LogDebug($"Router: Garlic: {msg.Message}");
#endif
                HandleGarlic((GarlicMessage)msg.Message);
                break;

            default:
                Logging.LogDebug($"TunnelProvider_I2NPMessageReceived: Unhandled message ({msg.Message})");
                break;
            }
        }
Exemplo n.º 2
0
        private bool HandleTunnelMessage(I2NPMessage msg)
        {
#if LOG_ALL_TUNNEL_TRANSFER
            Logging.LogDebug($"{this} HandleReceiveQueue: {msg.MessageType}");
#endif

            switch (msg.MessageType)
            {
            case I2NPMessage.MessageTypes.TunnelBuildReply:
            case I2NPMessage.MessageTypes.TunnelData:
                throw new NotImplementedException($"Should not happen {TunnelDebugTrace}");

            case I2NPMessage.MessageTypes.VariableTunnelBuildReply:
                ThreadPool.QueueUserWorkItem(cb =>
                {
                    TunnelProvider.Inst.HandleTunnelBuildReply((VariableTunnelBuildReplyMessage)msg);
                });
                return(true);

            case I2NPMessage.MessageTypes.DeliveryStatus:
#if LOG_ALL_TUNNEL_TRANSFER
                Logging.LogDebug($"{this}: DeliveryStatus: {msg.Message}");
#endif

                ThreadPool.QueueUserWorkItem(cb =>
                {
                    lock ( DeliveryStatusReceivedLock )
                    {
                        DeliveryStatusReceived?.Invoke((DeliveryStatusMessage)msg);
                    }
                });
                break;

            case I2NPMessage.MessageTypes.DatabaseStore:
                var ds = (DatabaseStoreMessage)msg;
                ThreadPool.QueueUserWorkItem(cb =>
                {
                    Router.HandleDatabaseStore(ds);
                });
                break;

            case I2NPMessage.MessageTypes.DatabaseSearchReply:
                var dsr = (DatabaseSearchReplyMessage)msg;
                ThreadPool.QueueUserWorkItem(cb =>
                {
                    NetDb.Inst.AddDatabaseSearchReply(dsr);
                });
                break;

            case I2NPMessage.MessageTypes.Garlic:
                var garlic = (GarlicMessage)msg;

#if LOG_ALL_TUNNEL_TRANSFER || LOG_ALL_LEASE_MGMT
                Logging.Log($"{this}: Garlic received");
#endif

                ThreadPool.QueueUserWorkItem(cb =>
                {
                    lock ( GarlicMessageReceivedLock )
                    {
                        GarlicMessageReceived?.Invoke(garlic);
                    }
                });
                break;

            default:
                Logging.LogWarning($"{this}: HandleReceiveQueue: Dropped {msg}");
                break;
            }

            return(true);
        }
Exemplo n.º 3
0
        private bool HandleReceiveQueue()
        {
            II2NPHeader msg = null;
            List <TunnelDataMessage> tdmsgs = null;

            lock ( ReceiveQueue )
            {
                if (ReceiveQueue.Count == 0)
                {
                    return(true);
                }

                if (ReceiveQueue.Any(mq => mq.MessageType == I2NPMessage.MessageTypes.TunnelData))
                {
                    var removelist = ReceiveQueue.Where(mq => mq.MessageType == I2NPMessage.MessageTypes.TunnelData);
                    tdmsgs = removelist.Select(mq => (TunnelDataMessage)mq.Message).ToList();
                    foreach (var one in removelist.ToArray())
                    {
                        ReceiveQueue.Remove(one);
                    }
                }
                else
                {
                    msg = ReceiveQueue.Last.Value;
                    ReceiveQueue.RemoveLast();
                }
            }

            if (tdmsgs != null)
            {
                HandleTunnelData(tdmsgs);
                return(true);
            }

#if LOG_ALL_TUNNEL_TRANSFER
            Logging.LogDebug($"InboundTunnel {TunnelDebugTrace} HandleReceiveQueue: {msg.MessageType}");
#endif

            switch (msg.MessageType)
            {
            case I2NPMessage.MessageTypes.TunnelData:
                throw new NotImplementedException("Should not happen " + TunnelDebugTrace);

            case I2NPMessage.MessageTypes.TunnelBuildReply:
            case I2NPMessage.MessageTypes.VariableTunnelBuildReply:
                ThreadPool.QueueUserWorkItem(cb =>
                {
                    TunnelProvider.Inst.HandleTunnelBuildReply((II2NPHeader16)msg);
                });
                return(true);

            case I2NPMessage.MessageTypes.DeliveryStatus:
#if LOG_ALL_TUNNEL_TRANSFER
                Logging.LogDebug($"InboundTunnel {TunnelDebugTrace}: DeliveryStatus: {msg.Message}");
#endif

                ThreadPool.QueueUserWorkItem(cb => {
                    lock ( DeliveryStatusReceivedLock )
                    {
                        DeliveryStatusReceived?.Invoke((DeliveryStatusMessage)msg.Message);
                    }
                });
                break;

            case I2NPMessage.MessageTypes.DatabaseStore:
                var ds = (DatabaseStoreMessage)msg.Message;
                ThreadPool.QueueUserWorkItem(cb =>
                {
                    TunnelProvider.HandleDatabaseStore(ds);
                });
                break;

            case I2NPMessage.MessageTypes.Garlic:
#if LOG_ALL_TUNNEL_TRANSFER
                Logging.Log($"InboundTunnel {TunnelDebugTrace}: Garlic: {msg.Message}");
#endif

                ThreadPool.QueueUserWorkItem(cb =>
                {
                    lock ( GarlicMessageReceivedLock )
                    {
                        GarlicMessageReceived?.Invoke((GarlicMessage)msg.Message);
                    }
                });
                break;

            default:
                Logging.LogWarning($"InboundTunnel {TunnelDebugTrace} HandleReceiveQueue: Dropped {msg}");
                break;
            }

            return(true);
        }