예제 #1
0
            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);
                }
            }
예제 #2
0
            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);
            }