Exemple #1
0
 public void SimpleSendToken(IoStream f, int token, MapFile buf, int offset, int n)
 {
     if (n > 0)
     {
         var l = 0;
         while (l < n)
         {
             var n1 = Math.Min(Match.ChunkSize, n - l);
             f.WriteInt(n1);
             var off = buf.MapPtr(offset + l, n1);
             f.Write(buf.P, off, n1);
             l += n1;
         }
     }
     if (token != -2)
     {
         f.WriteInt(-(token + 1));
     }
 }
Exemple #2
0
        public void GenerateAndSendSums(Stream fd, long len, IoStream f, Stream fCopy)
        {
            long    i;
            MapFile mapBuf;
            var     sum    = new SumStruct();
            long    offset = 0;

            SumSizesSqroot(sum, (UInt64)len);

            if (len > 0)
            {
                mapBuf = new MapFile(fd, (int)len, Options.MaxMapSize, (int)sum.BLength);
            }
            else
            {
                mapBuf = null;
            }

            WriteSumHead(f, sum);

            for (i = 0; i < sum.Count; i++)
            {
                var n1   = (UInt32)Math.Min(len, sum.BLength);
                var off  = mapBuf.MapPtr((int)offset, (int)n1);
                var map  = mapBuf.P;
                var sum1 = CheckSum.GetChecksum1(map, off, (int)n1);
                var sum2 = new byte[CheckSum.SumLength];

                sum2 = _checkSum.GetChecksum2(map, off, (int)n1);
                if (_options.Verbose > 3)
                {
                    Log.WriteLine("chunk[" + i + "] offset=" + offset + " len=" + n1 + " sum1=" + sum1);
                }
                f.WriteInt((int)sum1);
                f.Write(sum2, 0, sum.S2Length);
                len    -= n1;
                offset += n1;
            }
            if (mapBuf != null)
            {
                mapBuf = null;
            }
        }
Exemple #3
0
        public void MatchSums(IoStream f, SumStruct s, MapFile buf, int len)
        {
            var fileSum = new byte[CheckSum.Md4SumLength];

            _lastMatch    = 0;
            _falseAlarms  = 0;
            _tagHits      = 0;
            _matches      = 0;
            _dataTransfer = 0;

            var sum = new Sum(_options);

            sum.Init(_options.ChecksumSeed);

            if (len > 0 && s.Count > 0)
            {
                BuildHashTable(s);

                if (_options.Verbose > 2)
                {
                    Log.WriteLine("built hash table");
                }

                HashSearch(f, s, buf, len, sum);

                if (_options.Verbose > 2)
                {
                    Log.WriteLine("done hash search");
                }
            }
            else
            {
                for (var j = 0; j < len - ChunkSize; j += ChunkSize)
                {
                    var n1 = Math.Min(ChunkSize, (len - ChunkSize) - j);
                    Matched(f, s, buf, j + n1, -2, sum);
                }
                Matched(f, s, buf, len, -1, sum);
            }

            fileSum = sum.End();
            if (buf != null && buf.Status)
            {
                fileSum[0]++;
            }

            if (_options.Verbose > 2)
            {
                Log.WriteLine("sending fileSum");
            }
            f.Write(fileSum, 0, CheckSum.Md4SumLength);

            _targets.Clear();

            if (_options.Verbose > 2)
            {
                Log.WriteLine("falseAlarms=" + _falseAlarms + " tagHits=" + _tagHits + " matches=" + _matches);
            }

            _totalTagHits             += _tagHits;
            _totalFalseAlarms         += _falseAlarms;
            _totalMatches             += _matches;
            Options.Stats.LiteralData += _dataTransfer;
        }
Exemple #4
0
        public void SendFileEntry(FileStruct file, IoStream ioStream, UInt32 baseflags)
        {
            var flags = baseflags;
            int l1 = 0, l2 = 0;

            if (ioStream == null)
            {
                return;
            }
            if (file == null)
            {
                ioStream.WriteByte(0);
                _lastName = String.Empty;
                return;
            }
            var fileName = file.GetFullName().Replace(":", String.Empty);

            for (l1 = 0;
                 _lastName.Length > l1 && (fileName[l1] == _lastName[l1]) && (l1 < 255);
                 l1++)
            {
            }
            l2 = fileName.Substring(l1).Length;

            flags |= Options.XmitSameName;

            if (l2 > 255)
            {
                flags |= Options.XmitLongName;
            }
            if (_options.ProtocolVersion >= 28)
            {
                if (flags == 0 && !Util.S_ISDIR(file.Mode))
                {
                    flags |= Options.XmitTopDir;
                }

                /*if ((flags & 0xFF00) > 0 || flags == 0)
                 * {
                 *  flags |= Options.XMIT_EXTENDED_FLAGS;
                 *  f.writeByte((byte)flags);
                 *  f.writeByte((byte)(flags >> 8));
                 * }
                 * else					*/
                ioStream.WriteByte((byte)flags);
            }
            else
            {
                if ((flags & 0xFF) == 0 && !Util.S_ISDIR(file.Mode))
                {
                    flags |= Options.XmitTopDir;
                }
                if ((flags & 0xFF) == 0)
                {
                    flags |= Options.XmitLongName;
                }
                ioStream.WriteByte((byte)flags);
            }
            if ((flags & Options.XmitSameName) != 0)
            {
                ioStream.WriteByte((byte)l1);
            }
            if ((flags & Options.XmitLongName) != 0)
            {
                ioStream.WriteInt(l2);
            }
            else
            {
                ioStream.WriteByte((byte)l2);
            }


            var b = Encoding.ASCII.GetBytes(fileName);

            ioStream.Write(b, l1, l2);
            ioStream.WriteLongInt(file.Length);


            if ((flags & Options.XmitSameTime) == 0)
            {
                ioStream.WriteInt(file.ModTime.Second);
            }
            if ((flags & Options.XmitSameMode) == 0)
            {
                ioStream.WriteInt((int)file.Mode);
            }
            if (_options.PreserveUid && (flags & Options.XmitSameUid) == 0)
            {
                ioStream.WriteInt(file.Uid);
            }
            if (_options.PreserveGid && (flags & Options.XmitSameGid) == 0)
            {
                ioStream.WriteInt(file.Gid);
            }
            if (_options.AlwaysChecksum)
            {
                byte[] sum;
                if (!Util.S_ISDIR(file.Mode))
                {
                    sum = file.Sum;
                }
                else if (_options.ProtocolVersion < 28)
                {
                    sum = new byte[16];
                }
                else
                {
                    sum = null;
                }

                if (sum != null)
                {
                    ioStream.Write(sum, 0, _options.ProtocolVersion < 21 ? 2 : CheckSum.Md4SumLength);
                }
            }

            _lastName = fileName;
        }