public int ClientRun(ClientInfo cInfo, int pid, string[] args) { Options options = cInfo.Options; IOStream f = cInfo.IoStream; FileList fList; ArrayList fileList; MainClass.SetupProtocol(cInfo); if(options.protocolVersion >= 23 && !options.readBatch) f.IOStartMultiplexIn(); if(options.amSender) { f.IOStartBufferingOut(); if (options.deleteMode && !options.deleteExcluded) { Exclude excl = new Exclude(options); excl.SendExcludeList(f); } if (options.verbose > 3) Log.Write("File list sent\n"); f.Flush(); fList = new FileList(options); fileList = fList.sendFileList(cInfo, args); if(options.verbose > 3) Log.WriteLine("file list sent"); f.Flush(); Sender sender = new Sender(options); sender.SendFiles(fileList, cInfo); f.Flush(); f.writeInt(-1); return -1; } options.dir = args[0]; if(options.dir.CompareTo("") != 0 && options.dir.IndexOf(':') == -1) { if(options.dir[0] == '/') options.dir = "c:" + options.dir; else if(options.dir.IndexOf('/') != -1) { options.dir = options.dir.Insert(options.dir.IndexOf('/') - 1,":"); } } if(!options.readBatch) { Exclude excl = new Exclude(options); excl.SendExcludeList(f); } fList = new FileList(options); fileList = fList.receiveFileList(cInfo); return Daemon.DoReceive(cInfo,fileList,null); }
public bool ReceiveData(ClientInfo clientInfo, string fileNameR, Stream fdR, long sizeR, string fileName, Stream fd, int totalSize) { IOStream f = clientInfo.IoStream; byte[] fileSum1 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] fileSum2 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] data = new byte[Match.CHUNK_SIZE]; SumStruct sumStruct = new SumStruct(); MapFile mapBuf = null; Sender sender = new Sender(options); sender.ReadSumHead(clientInfo, ref sumStruct); int offset = 0; UInt32 len; if (fdR != null && sizeR > 0) { int mapSize = (int)Math.Max(sumStruct.bLength * 2, 16 * 1024); mapBuf = new MapFile(fdR, (int)sizeR, mapSize, (int)sumStruct.bLength); if (options.verbose > 2) { Log.WriteLine("recv mapped " + fileNameR + " of size " + sizeR); } } Sum sum = new Sum(options); sum.Init(options.checksumSeed); int i; Token token = new Token(options); while ((i = token.ReceiveToken(f, ref data, 0)) != 0) { if (options.doProgress) { Progress.ShowProgress(offset, totalSize); } if (i > 0) { if (options.verbose > 3) { Log.WriteLine("data recv " + i + " at " + offset); } Options.stats.literalData += i; sum.Update(data, 0, i); if (fd != null && FileIO.WriteFile(fd, data, 0, i) != i) { goto report_write_error; } offset += i; continue; } i = -(i + 1); int offset2 = (int)(i * sumStruct.bLength); len = sumStruct.bLength; if (i == sumStruct.count - 1 && sumStruct.remainder != 0) { len = sumStruct.remainder; } Options.stats.matchedData += len; if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] of size " + len + " at " + offset2 + " offset=" + offset); } byte[] map = null; int off = 0; if (mapBuf != null) { off = mapBuf.MapPtr(offset2, (int)len); map = mapBuf.p; token.SeeToken(map, offset, (int)len); sum.Update(map, off, (int)len); } if (options.inplace) { if (offset == offset2 && fd != null) { offset += (int)len; if (fd.Seek(len, SeekOrigin.Current) != offset) { MainClass.Exit("seek failed on " + Util.fullFileName(fileName), clientInfo); } continue; } } if (fd != null && FileIO.WriteFile(fd, map, off, (int)len) != (int)len) { goto report_write_error; } offset += (int)len; } if (options.doProgress) { Progress.EndProgress(totalSize); } if (fd != null && offset > 0 && FileIO.SparseEnd(fd) != 0) { MainClass.Exit("write failed on " + Util.fullFileName(fileName), clientInfo); } fileSum1 = sum.End(); if (mapBuf != null) { mapBuf = null; } fileSum2 = f.ReadBuffer(CheckSum.MD4_SUM_LENGTH); if (options.verbose > 2) { Log.WriteLine("got fileSum"); } if (fd != null && Util.MemoryCompare(fileSum1, 0, fileSum2, 0, CheckSum.MD4_SUM_LENGTH) != 0) { return false; } return true; report_write_error: { MainClass.Exit("write failed on " + Util.fullFileName(fileName), clientInfo); } return true; }
public int ClientRun(ClientInfo cInfo, int pid, string[] args) { Options options = cInfo.Options; IOStream f = cInfo.IoStream; FileList fList; ArrayList fileList; MainClass.SetupProtocol(cInfo); if (options.protocolVersion >= 23 && !options.readBatch) { f.IOStartMultiplexIn(); } if (options.amSender) { f.IOStartBufferingOut(); if (options.deleteMode && !options.deleteExcluded) { Exclude excl = new Exclude(options); excl.SendExcludeList(f); } if (options.verbose > 3) { Log.Write("File list sent\n"); } f.Flush(); fList = new FileList(options); fileList = fList.sendFileList(cInfo, args); if (options.verbose > 3) { Log.WriteLine("file list sent"); } f.Flush(); Sender sender = new Sender(options); sender.SendFiles(fileList, cInfo); f.Flush(); f.writeInt(-1); return(-1); } options.dir = args[0]; if (options.dir.CompareTo("") != 0 && options.dir.IndexOf(':') == -1) { if (options.dir[0] == '/') { options.dir = "c:" + options.dir; } else if (options.dir.IndexOf('/') != -1) { options.dir = options.dir.Insert(options.dir.IndexOf('/') - 1, ":"); } } if (!options.readBatch) { Exclude excl = new Exclude(options); excl.SendExcludeList(f); } fList = new FileList(options); fileList = fList.receiveFileList(cInfo); return(Daemon.DoReceive(cInfo, fileList, null)); }
static void DoServerSender(ClientInfo clientInfo, string[] args) { string dir = args[0]; IOStream ioStream = clientInfo.IoStream; Options options = clientInfo.Options; if (options.verbose > 2) { Log.Write("Server sender starting"); } if (options.amDaemon && config.ModuleIsWriteOnly(options.ModuleId)) { MainClass.Exit("ERROR: module " + config.GetModuleName(options.ModuleId) + " is write only", clientInfo); return; } if (!options.relativePaths && !Util.pushDir(dir)) { MainClass.Exit("Push_dir#3 " + dir + "failed", clientInfo); return; } FileList fList = new FileList(options); List<FileStruct> fileList = fList.sendFileList(clientInfo, args); if (options.verbose > 3) { Log.WriteLine("File list sent"); } if (fileList.Count == 0) { MainClass.Exit("File list is empty", clientInfo); return; } ioStream.IOStartBufferingIn(); ioStream.IOStartBufferingOut(); Sender sender = new Sender(options); sender.SendFiles(fileList, clientInfo); ioStream.Flush(); MainClass.Report(clientInfo); if (options.protocolVersion >= 24) { ioStream.readInt(); } ioStream.Flush(); }
public bool ReceiveData(ClientInfo cInfo, string fileNameR, Stream fdR, long sizeR, string fileName, Stream fd, int totalSize) { IOStream f = cInfo.IoStream; byte[] file_sum1 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] file_sum2 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] data = new byte[Match.CHUNK_SIZE]; SumStruct sum = new SumStruct(); MapFile mapBuf = null; Sender sender = new Sender(options); sender.ReadSumHead(cInfo, ref sum); int offset = 0; UInt32 len; if (fdR != null && sizeR > 0) { int mapSize = (int)Math.Max(sum.bLength * 2, 16 * 1024); mapBuf = new MapFile(fdR, (int)sizeR, mapSize, (int)sum.bLength); if (options.verbose > 2) { Log.WriteLine("recv mapped " + fileNameR + " of size " + sizeR); } ; } Sum s = new Sum(options); s.Init(options.checksumSeed); int i; Token token = new Token(options); while ((i = token.ReceiveToken(f, ref data, 0)) != 0) { if (options.doProgress) { Progress.ShowProgress(offset, totalSize); } if (i > 0) { if (options.verbose > 3) { Log.WriteLine("data recv " + i + " at " + offset); } Options.stats.literalData += i; s.Update(data, 0, i); if (fd != null && FileIO.WriteFile(fd, data, 0, i) != i) { goto report_write_error; } offset += i; continue; } i = -(i + 1); int offset2 = (int)(i * sum.bLength); len = sum.bLength; if (i == sum.count - 1 && sum.remainder != 0) { len = sum.remainder; } Options.stats.matchedData += len; if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] of size " + len + " at " + offset2 + " offset=" + offset); } byte[] map = null; int off = 0; if (mapBuf != null) { off = mapBuf.MapPtr(offset2, (int)len); map = mapBuf.p; token.SeeToken(map, offset, (int)len); s.Update(map, off, (int)len); } if (options.inplace) { if (offset == offset2 && fd != null) { offset += (int)len; if (fd.Seek(len, SeekOrigin.Current) != offset) { MainClass.Exit("seek failed on " + Util.fullFileName(fileName), cInfo); } continue; } } if (fd != null && FileIO.WriteFile(fd, map, off, (int)len) != (int)len) { goto report_write_error; } offset += (int)len; } if (options.doProgress) { Progress.EndProgress(totalSize); } if (fd != null && offset > 0 && FileIO.SparseEnd(fd) != 0) { MainClass.Exit("write failed on " + Util.fullFileName(fileName), cInfo); } file_sum1 = s.End(); if (mapBuf != null) { mapBuf = null; } file_sum2 = f.ReadBuf(CheckSum.MD4_SUM_LENGTH); if (options.verbose > 2) { Log.WriteLine("got fileSum"); } if (fd != null && Util.MemCmp(file_sum1, 0, file_sum2, 0, CheckSum.MD4_SUM_LENGTH) != 0) { return(false); } return(true); report_write_error: { MainClass.Exit("write failed on " + Util.fullFileName(fileName), cInfo); } return(true); }