public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted) { algorithm.Push(read.Buffer.Data, read.Buffer.Offset, Math.Min(read.Buffer.Count, read.Count)); Metainfo metainfo = context.Metainfo; byte[] expected = metainfo.Pieces[read.Piece].ToBytes(); byte[] hash = algorithm.Complete(); bool result = Bytes.Equals(hash, expected); bitfield[read.Piece] = result; algorithm.Dispose(); int next = Next(scope, read.Piece + 1); bool exists = context.View.Exists(next, 0); if (exists) { context.Queue.Add(new Start(bitfield, scope, next, block)); } else { block.Release(); onCompleted.Invoke(this); context.Bitfile.Write(bitfield); context.Hooks.CallDataVerified(metainfo.Hash, bitfield); } }
public void Execute(MetafileContext context) { if (context.IsCompleted) { algorithm.Dispose(); return; } if (read.Count > 0) { data.Add(read.Buffer.ToBytes(read.Count)); algorithm.Push(read.Buffer.Data, read.Buffer.Offset, read.Count); read.File.Read(read.Position + read.Count, new FileBuffer(16384), result => { context.Queue.Add(new MetafileTaskVerified(this, result)); }); } if (read.Count == 0) { byte[] bytes = algorithm.Complete(); FileHash computed = new FileHash(bytes); if (computed.Equals(context.Parameters.Hash)) { int position = 0; int size = data.Sum(x => x.Length); bytes = new byte[size]; foreach (byte[] chunk in data) { Array.Copy(chunk, 0, bytes, position, chunk.Length); position += chunk.Length; } context.IsCompleted = true; context.TotalSize = size; context.Hooks.CallMetafileVerified(context.Parameters.Hash, MetainfoFactory.FromBytes(bytes), size); algorithm.Dispose(); } else { context.IsCompleted = false; context.Hooks.CallMetafileRejected(context.Parameters.Hash); algorithm.Dispose(); } } }
public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted) { algorithm.Push(read.Buffer.Data, read.Buffer.Offset, Math.Min(read.Buffer.Count, read.Count)); Metainfo metainfo = context.Metainfo; byte[] expected = metainfo.Pieces[piece.Index].ToBytes(); byte[] hash = algorithm.Complete(); bool result = Bytes.Equals(hash, expected); AcceptIfRequired(context, result); RejectIfRequired(context, result); algorithm.Dispose(); block.Release(); onCompleted.Invoke(this); }