public void SimpleSendToken(IOStream f, int token, MapFile buf, int offset, int n) { if (n > 0) { int l = 0; while (l < n) { int n1 = Math.Min(Match.CHUNK_SIZE, n - l); f.writeInt(n1); int off = buf.MapPtr(offset + l, n1); f.Write(buf.p, off, n1); l += n1; } } if (token != -2) { f.writeInt(-(token + 1)); } }
public void GenerateAndSendSums(Stream fd, long len, IOStream f, Stream fCopy) { long i; MapFile mapBuf; SumStruct sum = new SumStruct(); long offset = 0; SumSizesSqroot(sum, (UInt64)len); if (len > 0) { mapBuf = new MapFile(fd, (int)len, Options.MAX_MAP_SIZE, (int)sum.bLength); } else { mapBuf = null; } WriteSumHead(f, sum); for (i = 0; i < sum.count; i++) { UInt32 n1 = (UInt32)Math.Min(len, sum.bLength); int off = mapBuf.MapPtr((int)offset, (int)n1); byte[] map = mapBuf.p; UInt32 sum1 = CheckSum.GetChecksum1(map, off, (int)n1); byte[] sum2 = new byte[CheckSum.SUM_LENGTH]; 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; } }
public void MatchSums(IOStream f, SumStruct s, MapFile buf, int len) { byte[] fileSum = new byte[CheckSum.MD4_SUM_LENGTH]; lastMatch = 0; falseAlarms = 0; tagHits = 0; matches = 0; dataTransfer = 0; Sum 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 (int j = 0; j < len - CHUNK_SIZE; j += CHUNK_SIZE) { int n1 = Math.Min(CHUNK_SIZE, (len - CHUNK_SIZE) - 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.MD4_SUM_LENGTH); targets.Clear(); if (options.verbose > 2) { Log.WriteLine("falseAlarms=" + falseAlarms + " tagHits=" + tagHits + " matches=" + matches); } totalTagHits += tagHits; totalFalseAlarms += falseAlarms; totalMatches += matches; Options.stats.literalData += dataTransfer; }
public void MatchSums(IOStream f, SumStruct s, MapFile buf, int len) { byte[] fileSum = new byte[CheckSum.MD4_SUM_LENGTH]; lastMatch = 0; falseAlarms = 0; tagHits = 0; matches = 0; dataTransfer = 0; Sum 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 (int j = 0; j < len - CHUNK_SIZE; j += CHUNK_SIZE) { int n1 = Math.Min(CHUNK_SIZE,(len-CHUNK_SIZE)-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.MD4_SUM_LENGTH); targets.Clear(); if (options.verbose > 2) Log.WriteLine("falseAlarms=" + falseAlarms + " tagHits=" + tagHits + " matches=" + matches); totalTagHits += tagHits; totalFalseAlarms += falseAlarms; totalMatches += matches; Options.stats.literalData += dataTransfer; }
public void sendFileEntry(FileStruct file, IOStream ioStream, UInt32 baseflags) { UInt32 flags = baseflags; int l1 = 0, l2 = 0; if (ioStream == null) { return; } if (file == null) { ioStream.writeByte(0); lastName = String.Empty; return; } string 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.XMIT_SAME_NAME; if (l2 > 255) { flags |= Options.XMIT_LONG_NAME; } if (options.protocolVersion >= 28) { if (flags == 0 && !Util.S_ISDIR(file.mode)) { flags |= Options.XMIT_TOP_DIR; } /*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.XMIT_TOP_DIR; } if ((flags & 0xFF) == 0) { flags |= Options.XMIT_LONG_NAME; } ioStream.writeByte((byte)flags); } if ((flags & Options.XMIT_SAME_NAME) != 0) { ioStream.writeByte((byte)l1); } if ((flags & Options.XMIT_LONG_NAME) != 0) { ioStream.writeInt(l2); } else { ioStream.writeByte((byte)l2); } byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(fileName); ioStream.Write(b, l1, l2); ioStream.WriteLongInt(file.length); if ((flags & Options.XMIT_SAME_TIME) == 0) { ioStream.writeInt(file.modTime.Second); } if ((flags & Options.XMIT_SAME_MODE) == 0) { ioStream.writeInt((int)file.mode); } if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0) { ioStream.writeInt(file.uid); } if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 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.MD4_SUM_LENGTH); } } lastName = fileName; }
public void sendFileEntry(FileStruct file, IOStream f, UInt32 baseflags) { UInt32 flags = baseflags; int l1 = 0,l2 = 0; if(f == null) return; if(file == null) { f.writeByte(0); lastName = ""; return; } string fileName = file.FNameTo().Replace(":",""); for (l1 = 0; lastName.Length >l1 && (fileName[l1] == lastName[l1]) && (l1 < 255); l1++) {} l2 = fileName.Substring(l1).Length; flags |= Options.XMIT_SAME_NAME; if (l2 > 255) flags |= Options.XMIT_LONG_NAME; if(options.protocolVersion >= 28) { if(flags == 0 && !Util.S_ISDIR(file.mode)) flags |= Options.XMIT_TOP_DIR; /*if ((flags & 0xFF00) > 0 || flags == 0) { flags |= Options.XMIT_EXTENDED_FLAGS; f.writeByte((byte)flags); f.writeByte((byte)(flags >> 8)); } else */ f.writeByte((byte)flags); } else { if ((flags & 0xFF) == 0 && !Util.S_ISDIR(file.mode)) flags |= Options.XMIT_TOP_DIR; if ((flags & 0xFF) == 0) flags |= Options.XMIT_LONG_NAME; f.writeByte((byte)flags); } if ((flags & Options.XMIT_SAME_NAME) != 0) f.writeByte((byte)l1); if ((flags & Options.XMIT_LONG_NAME) != 0) f.writeInt(l2); else f.writeByte((byte)l2); byte[] b =System.Text.ASCIIEncoding.ASCII.GetBytes(fileName); f.Write(b, l1, l2); f.WriteLongInt(file.length); if ((flags & Options.XMIT_SAME_TIME) == 0) f.writeInt(file.modTime.Second); if ((flags & Options.XMIT_SAME_MODE) == 0) f.writeInt((int)file.mode); if (options.preserveUID && (flags & Options.XMIT_SAME_UID) == 0) { f.writeInt(file.uid); } if (options.preserveGID && (flags & Options.XMIT_SAME_GID) == 0) { f.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 ) { f.Write(sum, 0, options.protocolVersion < 21 ? 2 : CheckSum.MD4_SUM_LENGTH); } } lastName = fileName; }
public void SimpleSendToken(IOStream f,int token, MapFile buf, int offset, int n) { if (n > 0) { int l = 0; while (l < n) { int n1 = Math.Min(Match.CHUNK_SIZE,n-l); f.writeInt(n1); int off = buf.MapPtr(offset + l, n1); f.Write(buf.p, off, n1); l += n1; } } if (token != -2) f.writeInt(-(token+1)); }