Ejemplo n.º 1
0
 public Continue(PieceInfo piece, RepositoryViewRead read, HashAlgorithm algorithm, RepositoryMemoryBlock block)
 {
     this.piece     = piece;
     this.read      = read;
     this.algorithm = algorithm;
     this.block     = block;
 }
Ejemplo n.º 2
0
 public Complete(Bitfield bitfield, Bitfield scope, HashAlgorithm algorithm, RepositoryViewRead read, RepositoryMemoryBlock block)
 {
     this.bitfield  = bitfield;
     this.scope     = scope;
     this.algorithm = algorithm;
     this.read      = read;
     this.block     = block;
 }
Ejemplo n.º 3
0
            public Start(Bitfield bitfield, Bitfield scope, int piece, RepositoryMemoryBlock block)
            {
                this.algorithm = SHA1.Create();

                this.bitfield = bitfield;
                this.scope    = scope;
                this.piece    = piece;
                this.block    = block;
            }
Ejemplo n.º 4
0
        public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
        {
            int blockSize = context.Metainfo.Properties.BlockSize;
            RepositoryMemoryBlock block  = context.Dependencies.Memory.Allocate(blockSize);
            FileBuffer            buffer = new FileBuffer(block.Data, 0, blockSize);

            context.View.Read(buffer, index.Piece.Index, index.Offset / blockSize, result =>
            {
                context.Queue.Add(new Complete(index, result));
            });
        }
Ejemplo n.º 5
0
        public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
        {
            HashAlgorithm algorithm  = SHA1.Create();
            int           bufferSize = context.Configuration.BufferSize;

            RepositoryMemoryBlock block = context.Dependencies.Memory.Allocate(bufferSize);
            int step = block.Length / context.Metainfo.Properties.BlockSize;

            context.View.Read(block.Data, piece.Index, 0, args =>
            {
                if (args.Count > 0 && context.View.Exists(piece.Index, args.Block + step))
                {
                    context.Queue.Add(new Continue(piece, args, algorithm, block));
                }
                else
                {
                    context.Queue.Add(new Complete(piece, args, algorithm, block));
                }
            });
        }
Ejemplo n.º 6
0
        public void Execute(RepositoryContext context, RepositoryTaskCallback onCompleted)
        {
            int      length   = context.Metainfo.Pieces.Length;
            Bitfield bitfield = context.Bitfile.Read();

            bitfield = bitfield ?? new Bitfield(length);
            Bitfield reduced = ReduceScope(bitfield);
            int      next    = Next(reduced, 0);

            if (next < length)
            {
                int bufferSize = context.Configuration.BufferSize;
                RepositoryMemoryBlock block = context.Dependencies.Memory.Allocate(bufferSize);

                context.Queue.Add(new Start(bitfield, reduced, next, block));
            }
            else
            {
                onCompleted.Invoke(this);
                context.Hooks.CallDataVerified(context.Metainfo.Hash, bitfield);
            }
        }