示例#1
0
        public void AddCompressionData(ListSegment <DataSegment> labels, int dnsOffset)
        {
            if (dnsOffset > 16383)
            {
                return;
            }
            switch (this.DomainNameCompressionMode)
            {
            case DnsDomainNameCompressionMode.All:
                if (this._data.ContainsKey(labels))
                {
                    break;
                }
                this._data.Add(labels, dnsOffset);
                break;

            case DnsDomainNameCompressionMode.Nothing:
                break;

            default:
                throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Invalid Domain Name Compression Mode {0}", new object[1]
                {
                    (object)this.DomainNameCompressionMode
                }));
            }
        }
示例#2
0
        internal int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
        {
            int num = 0;

            for (int startIndex = 0; startIndex != this.LabelsCount; ++startIndex)
            {
                ListSegment <DataSegment> labels = new ListSegment <DataSegment>((IList <DataSegment>) this._labels, startIndex);
                if (compressionData.IsAvailable(labels))
                {
                    return(num + 2);
                }
                compressionData.AddCompressionData(labels, offsetInDns + num);
                num += 1 + labels[0].Length;
            }
            return(num + 1);
        }
示例#3
0
        public bool TryGetOffset(ListSegment <DataSegment> labels, out int offsetInDns)
        {
            switch (DomainNameCompressionMode)
            {
            case DnsDomainNameCompressionMode.All:
                return(_data.TryGetValue(labels, out offsetInDns));

            case DnsDomainNameCompressionMode.Nothing:
                offsetInDns = 0;
                return(false);

            default:
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid Domain Name Compression Mode {0}",
                                                                  DomainNameCompressionMode));
            }
        }
示例#4
0
        internal int GetLength(DnsDomainNameCompressionData compressionData, int offsetInDns)
        {
            int length = 0;

            for (int i = 0; i != LabelsCount; ++i)
            {
                ListSegment <DataSegment> labels = new ListSegment <DataSegment>(_labels, i);
                if (compressionData.IsAvailable(labels))
                {
                    return(length + sizeof(ushort));
                }
                compressionData.AddCompressionData(labels, offsetInDns + length);
                length += sizeof(byte) + labels[0].Length;
            }
            return(length + sizeof(byte));
        }
示例#5
0
        internal int Write(byte[] buffer, int dnsOffset, DnsDomainNameCompressionData compressionData, int offsetInDns)
        {
            int num1 = 0;

            for (int startIndex = 0; startIndex != this.LabelsCount; ++startIndex)
            {
                ListSegment <DataSegment> labels = new ListSegment <DataSegment>((IList <DataSegment>) this._labels, startIndex);
                int offsetInDns1;
                if (compressionData.TryGetOffset(labels, out offsetInDns1))
                {
                    ByteArrayExtensions.Write(buffer, dnsOffset + offsetInDns + num1, (ushort)(49152U | (uint)(ushort)offsetInDns1), Endianity.Big);
                    return(num1 + 2);
                }
                DataSegment dataSegment = labels[0];
                compressionData.AddCompressionData(labels, offsetInDns + num1);
                ByteArrayExtensions.Write(buffer, dnsOffset + offsetInDns + num1, (byte)dataSegment.Length);
                int num2 = num1 + 1;
                dataSegment.Write(buffer, dnsOffset + offsetInDns + num2);
                num1 = num2 + dataSegment.Length;
            }
            return(num1 + 1);
        }
示例#6
0
        internal int Write(byte[] buffer, int dnsOffset, DnsDomainNameCompressionData compressionData, int offsetInDns)
        {
            int length = 0;

            for (int i = 0; i != LabelsCount; ++i)
            {
                ListSegment <DataSegment> labels = new ListSegment <DataSegment>(_labels, i);
                int pointerOffset;
                if (compressionData.TryGetOffset(labels, out pointerOffset))
                {
                    buffer.Write(dnsOffset + offsetInDns + length, (ushort)(CompressionMarker | (ushort)pointerOffset), Endianity.Big);
                    return(length + sizeof(ushort));
                }
                DataSegment currentLabel = labels[0];
                compressionData.AddCompressionData(labels, offsetInDns + length);
                buffer.Write(dnsOffset + offsetInDns + length, (byte)currentLabel.Length);
                length += sizeof(byte);
                currentLabel.Write(buffer, dnsOffset + offsetInDns + length);
                length += currentLabel.Length;
            }
            return(length + sizeof(byte));
        }
示例#7
0
        public void AddCompressionData(ListSegment <DataSegment> labels, int dnsOffset)
        {
            if (dnsOffset > DnsDomainName.OffsetMask)
            {
                return;
            }

            switch (DomainNameCompressionMode)
            {
            case DnsDomainNameCompressionMode.All:
                if (!_data.ContainsKey(labels))
                {
                    _data.Add(labels, dnsOffset);
                }
                return;

            case DnsDomainNameCompressionMode.Nothing:
                return;

            default:
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Invalid Domain Name Compression Mode {0}",
                                                                  DomainNameCompressionMode));
            }
        }
示例#8
0
        public bool IsAvailable(ListSegment <DataSegment> labels)
        {
            int offsetInDns;

            return(this.TryGetOffset(labels, out offsetInDns));
        }