Exemplo n.º 1
0
        public void Read(ReadBuffer buffer, int length)
        {
            buffer.Read(out AddressTypeByte);

            switch (AddressType)
            {
            case DestAddressType.IPv4:
                DestAddress = buffer.ReadBytes(4);
                break;

            case DestAddressType.IPv6:
                DestAddress = buffer.ReadBytes(16);
                break;

            case DestAddressType.DomainName:
                byte destLen;
                buffer.Read(out destLen);
                var addressBytes = buffer.ReadBytes(destLen);
                DestDomainName = Encoding.ASCII.GetString(addressBytes);
                break;

            default:
                throw new Exception(string.Format("RouteListPacketData.ReadBytes: invalid address type {0}.", AddressTypeByte));
            }

            buffer.Read(out DestPort);
            buffer.Read(out RouteCount);  // total route count

            var remainingLength = length - buffer.TotalRead;

            var routesInPacket = remainingLength / PacketRoute.EncryptedSize;

            if (routesInPacket * PacketRoute.EncryptedSize != remainingLength)
            {
                throw new Exception(string.Format("RouteListPacketData.ReadBytes: remaining length {0} is not a multiple of {1}.", remainingLength, PacketRoute.EncryptedSize));
            }

            ReturnRoutes = new PacketRoute[routesInPacket];

            for (var r = 0; r < routesInPacket; r++)
            {
                ReturnRoutes[r] = new PacketRoute {
                    EncryptedBytes = buffer.ReadBytes(PacketRoute.EncryptedSize)
                }
            }
            ;
        }
Exemplo n.º 2
0
        public void Read(ReadBuffer buffer, int length)
        {
            var routeCount = length / PacketRoute.EncryptedSize;

            if (routeCount * PacketRoute.EncryptedSize != length)
            {
                throw new Exception(string.Format("RouteListPacketData.ReadBytes: length {0} is not a multiple of {1}.", length, PacketRoute.EncryptedSize));
            }

            ReturnRoutes = new PacketRoute[routeCount];

            for (var i = 0; i < routeCount; i++)
            {
                ReturnRoutes[i] = new PacketRoute {
                    EncryptedBytes = buffer.ReadBytes(PacketRoute.EncryptedSize)
                }
            }
            ;
        }