private bool m_CreateDataPackets() { CFileBlock sendBlock; sendBlock=(CFileBlock)m_UploadBlocks[0]; byte[] Datos=null; CElement element=(CElement)CKernel.FilesList[sendBlock.FileHash]; m_UploadElement=element; if (CKernel.SameHash(ref m_UpFileHash,ref sendBlock.FileHash)) { Buffer.BlockCopy(sendBlock.FileHash,0,m_UpFileHash,0,16); } if ((element!=null)&&(sendBlock.end-sendBlock.start<185000)) { Datos=element.File.ReadBlock(sendBlock.start,sendBlock.end-1,false); } if ((Datos==null)||(element==null)) { // cancel upload Debug.Write("Part not found in file\n"); CancelUploadTransfer(false); return false; } MemoryStream DatosStream=new MemoryStream(Datos); //if you uncoment this upload compression will be enabled (not so tested) //if (bEsMula) //{ // CCompressedBlockSend EnvioBloque=new CCompressedBlockSend(Datos,sendBlock.inicio,sendBlock.fin,sendBlock.FileHash,ref m_UploadDataPackets); //} //else //{ CSendBlock EnvioBloque=new CSendBlock(DatosStream,sendBlock.start,sendBlock.end,sendBlock.FileHash,ref m_UploadDataPackets); //} Datos=null; m_UploadBlocks.Remove(sendBlock); //GC.Collect(); return true; }
public CCompressedBlockSend(byte[] data,uint start,uint end,byte[] FileHash,ref ArrayList UploadDataPackets) { // byte[] buffercomp=new byte[final-inicio+300]; // Deflater descompresor=new Deflater(); // descompresor.SetInput(datos); // descompresor.Flush(); // int compressedsize=descompresor.Deflate(buffercomp,0,(int)(final-inicio)+300); // descompresor.Finish(); byte[] buffercomp=null; int compressedsize=ComprimirBuffer(data,ref buffercomp); if (compressedsize>=end-start) { buffercomp=null; MemoryStream strmdatos=new MemoryStream(data); CSendBlock EnvioBloque=new CSendBlock(strmdatos,start,end,FileHash,ref UploadDataPackets); return; } Debug.Write("Compressed comp:"+compressedsize.ToString()+" win: "+Convert.ToString(end-start-compressedsize)+"\n"); MemoryStream datosComp=new MemoryStream(buffercomp); end=start+(uint)compressedsize; MemoryStream buffer; uint size; BinaryReader reader=new BinaryReader(datosComp); BinaryWriter writer; byte[] aux_buffer; while (start!=end) { buffer=new MemoryStream(); writer=new BinaryWriter(buffer); DonkeyHeader header=new DonkeyHeader((byte)Protocol.ClientCommandExt.CompressedPart,writer,Protocol.ProtocolType.eMule); writer.Write(FileHash); if (end-start>10240) size=10240; else size=end-start; writer.Write(start); writer.Write(compressedsize); aux_buffer=reader.ReadBytes((int)size); writer.Write(aux_buffer); start+=size; header.Packetlength=(uint)writer.BaseStream.Length-header.Packetlength+1; writer.Seek(0,SeekOrigin.Begin); header.Serialize(writer); UploadDataPackets.Add(buffer); writer=null; buffer=null; } reader.Close(); datosComp.Close(); datosComp=null; reader=null; }