Example #1
0
        private void SendData(IPacket packet, byte packetType)
        {
            byte[] data            = packet.GetBytes();
            byte[] typedPacketData = new byte[data.Length + 1];
            typedPacketData[0] = packetType;
            Array.Copy(data, 0, typedPacketData, 1, data.Length);
            // Pick a tunnel to send
            if (_mruTunnel == null || !_mruTunnel.Tunnel.IsTunnelEstablished || _mruTunnel.Tunnel.Degraded)
            {
#if DEBUG
                Logger.Debug("Choosing new tunnel for transmission");
#endif
                _mruTunnel = PickTunnel();
            }
#if DEBUG
            Logger.Debug("Using tunnel " + _mruTunnel.Tunnel.Id + " for transmission");
#endif
            _mruTunnel.Tunnel.SendData(typedPacketData);
        }
Example #2
0
        private void ProcessTunnelData(byte[] bytes, String id)
        {
            // Get the transport packet type out before
            byte[] packetData = new byte[bytes.Length - 1];
            Array.Copy(bytes, 1, packetData, 0, bytes.Length - 1);
            // Set this tunnel as MRU
            if (id != null && (_mruTunnel == null || !_mruTunnel.Tunnel.Id.Equals(id)) && _tunnels.ContainsKey(id))
            {
#if DEBUG
                Logger.Debug("Received data on tunnel " + id + ", this tunnels is now MRU");
#endif

                _mruTunnel = _tunnels[id];
            }
            if (bytes[0] == PACKET_TYPE_TCP)
            {
                TCPTransport.ProcessPacket(packetData);
            }
            else
            {
                Logger.Error("Error processing tunnel data, packet type not supported " + bytes[0]);
            }
        }