using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; using OpenSSL.Core; using OpenSSL.Crypto; namespace Pithos.Network { //public class MD5BlockCalculator:IDisposable //{ // private MessageDigestContext _hasher ; // private ActionBlock> _actionBlock; // private long _currentBlock = 0; // public MD5BlockCalculator(int capacity) // { // var opt = new ExecutionDataflowBlockOptions { BoundedCapacity = capacity }; // _actionBlock = new ActionBlock>(t => ProcessBlock(t), opt); // _hasher = new MessageDigestContext(MessageDigest.CreateByName("md5")); // _hasher.Init(); // } // public MD5BlockCalculator() // { // _actionBlock = new ActionBlock>(t => ProcessBlock(t)); // _hasher = new MessageDigestContext(MessageDigest.CreateByName("md5")); // _hasher.Init(); // } // private void ProcessBlock(Tuple tuple) // { // if (tuple.Item1 == _currentBlock) // { // var size = tuple.Item3; // var buffer= tuple.Item2; // if (size == buffer.Length) // { // _hasher.Update(buffer); // } // else // { // var block = new byte[size]; // Buffer.BlockCopy(buffer, 0, block, 0, size); // _hasher.Update(block); // } // Interlocked.Increment(ref _currentBlock); // } // else // { // _actionBlock.Post(tuple); // } // } // public void PostBlock(long blockIndex,byte[] buffer,int size) // { // _actionBlock.Post(Tuple.Create(blockIndex, buffer, size)); // } // public async Task GetHash() // { // _actionBlock.Complete(); // await _actionBlock.Completion; // Debug.Assert(_actionBlock.InputCount == 0); // var hashBytes=_hasher.DigestFinal(); // var hash=hashBytes.ToHashString(); // return hash; // } // public void Dispose() // { // Dispose(true); // GC.SuppressFinalize(this); // } // protected virtual void Dispose(bool disposing) // { // if (disposing && _hasher!=null) // _hasher.Dispose(); // _hasher = null; // } //} }