private bool HandleTunnelData(IEnumerable <TunnelDataMessage> msgs) { EncryptTunnelMessages(msgs); #if LOG_ALL_TUNNEL_TRANSFER LogDataSent.Log(() => "PassthroughTunnel " + Destination.Id32Short + " TunnelData sent."); #endif var dropped = 0; foreach (var one in msgs) { if (Limiter.DropMessage()) { ++dropped; continue; } one.TunnelId = SendTunnelId; Bandwidth.DataSent(one.Payload.Length); TransportProvider.Send(Destination, one); } #if LOG_ALL_TUNNEL_TRANSFER if (dropped > 0) { DebugUtils.LogDebug(() => string.Format("{0} bandwidth limit. {1} dropped messages. {2}", this, dropped, Bandwidth)); } #endif return(true); }
private bool HandleReceiveQueue() { II2NPHeader16[] messages = null; lock ( ReceiveQueue ) { if (ReceiveQueue.Count == 0) { return(true); } var msgs = new List <II2NPHeader16>(); int dropped = 0; foreach (var msg in ReceiveQueue) { if (Limiter.DropMessage()) { ++dropped; continue; } msgs.Add((II2NPHeader16)msg); } messages = msgs.ToArray(); #if LOG_ALL_TUNNEL_TRANSFER if (dropped > 0) { if (FilterMessageTypes.Update(new HashedItemGroup(Destination, 0x63e9))) { Logging.LogDebug(() => string.Format("{0} bandwidth limit. {1} dropped messages. {2}", this, dropped, Bandwidth)); } } #endif } if (messages == null || messages.Length == 0) { return(true); } var tdata = TunnelDataMessage.MakeFragments(messages.Select(msg => (TunnelMessage)(new TunnelMessageLocal(msg))), SendTunnelId); EncryptTunnelMessages(tdata); #if LOG_ALL_TUNNEL_TRANSFER if (FilterMessageTypes.Update(new HashedItemGroup(Destination, 0x17f3))) { Logging.Log("GatewayTunnel " + Destination.Id32Short + ": TunnelData sent."); } #endif foreach (var tdmsg in tdata) { Bandwidth.DataSent(tdmsg.Payload.Length); TransportProvider.Send(Destination, tdmsg); } return(true); }
private bool CreateTunnelMessageFragments(IEnumerable <TunnelMessage> messages) { var data = TunnelDataMessage.MakeFragments(messages, SendTunnelId); var encr = OutboundGatewayDecrypt(data); foreach (var msg in encr) { #if LOG_ALL_TUNNEL_TRANSFER if (FilterMessageTypes.Update(new HashedItemGroup((int)msg.MessageType, 0x4272))) { Logging.LogDebug($"OutboundTunnel: Send {NextHop.Id32Short} : {msg}"); } #endif Bandwidth.DataSent(msg.Payload.Length); TransportProvider.Send(NextHop, msg); } return(true); }
private bool HandleSendQueue() { I2NPMessage[] rawdata; lock ( SendRawQueue ) { rawdata = SendRawQueue.ToArray(); SendRawQueue.Clear(); } foreach (var msg in rawdata) { #if LOG_ALL_TUNNEL_TRANSFER if (FilterMessageTypes.Update(new HashedItemGroup((int)msg.MessageType, 0x1701))) { Logging.LogDebug($"OutboundTunnel: Send raw {NextHop.Id32Short} : {msg}"); } #endif Bandwidth.DataSent(msg.Payload.Length); TransportProvider.Send(NextHop, msg); } if (SendQueue.Count == 0) { return(true); } IEnumerable <TunnelMessage> messages; lock ( SendQueue ) { messages = SendQueue.ToArray(); SendQueue.Clear(); } return(CreateTunnelMessageFragments(messages)); }
private bool HandleTunnelData(IEnumerable <TunnelDataMessage> msgs) { EncryptTunnelMessages(msgs); var newmsgs = Reassembler.Process(msgs); var dropped = 0; foreach (var one in newmsgs) { if (Limiter.DropMessage()) { ++dropped; continue; } try { if (one.GetType() == typeof(TunnelMessageLocal)) { MessageReceived(((TunnelMessageLocal)one).Header); DebugUtils.Log("EndpointTunnel " + Destination.Id32Short + " TunnelData destination Local. Dropped.\r\n" + one.Header.ToString()); } else if (one.GetType() == typeof(TunnelMessageRouter)) { #if LOG_ALL_TUNNEL_TRANSFER if (FilterMessageTypes.Update(new HashedItemGroup(Destination, 0x2317))) { DebugUtils.LogDebug("EndpointTunnel " + Destination.Id32Short + " TunnelData Router :\r\n" + one.Header.MessageType.ToString()); } #endif var msg = one.Header.Message; Bandwidth.DataSent(msg.Payload.Length); TransportProvider.Send(((TunnelMessageRouter)one).Destination, msg); } else if (one.GetType() == typeof(TunnelMessageTunnel)) { var tone = (TunnelMessageTunnel)one; #if LOG_ALL_TUNNEL_TRANSFER if (FilterMessageTypes.Update(new HashedItemGroup(Destination, 0x6375))) { DebugUtils.LogDebug("EndpointTunnel " + Destination.Id32Short + " TunnelData Tunnel :\r\n" + one.Header.MessageType.ToString()); } #endif var gwmsg = new TunnelGatewayMessage(tone.Header, tone.Tunnel); Bandwidth.DataSent(gwmsg.Payload.Length); TransportProvider.Send(tone.Destination, gwmsg); } else { DebugUtils.LogDebug("EndpointTunnel " + Destination.Id32Short + " TunnelData of unexpected type: " + one.Header.ToString()); } } catch (Exception ex) { DebugUtils.Log("EndpointTunnel", ex); throw; // Kill tunnel is strange things happen } } #if LOG_ALL_TUNNEL_TRANSFER if (dropped > 0) { DebugUtils.LogDebug(() => string.Format("{0} bandwidth limit. {1} dropped messages. {2}", this, dropped, Bandwidth)); } #endif return(true); }