Exemplo n.º 1
0
        public MetamineBlock[] Next(MetamineStrategy strategy, PeerHash peer)
        {
            MetamineStrategyContext context = new MetamineStrategyContext
            {
                Peer          = peer,
                Blocks        = blocks,
                Configuration = configuration,
                Reservations  = reservations
            };

            return(strategy.Next(context).ToArray());
        }
Exemplo n.º 2
0
        public override IEnumerable <MetamineBlock> Next(MetamineStrategyContext context)
        {
            DateTime now  = DateTime.Now;
            int      left = context.Configuration.Size;

            for (int offset = 0; left > 0; offset += 16384, left -= 16384)
            {
                int           size  = Math.Min(left, 16384);
                MetamineBlock block = new MetamineBlock(offset / 16384, size);

                if (IsReservable(context, block, now))
                {
                    yield return(block);

                    yield break;
                }
            }
        }
Exemplo n.º 3
0
 public abstract IEnumerable <MetamineBlock> Next(MetamineStrategyContext context);
Exemplo n.º 4
0
 private bool HasReservation(MetamineStrategyContext context)
 {
     return(context.Reservations.Contains(context.Peer));
 }
Exemplo n.º 5
0
 private bool IsReserved(MetamineStrategyContext context, MetamineBlock block, DateTime now)
 {
     return(context.Reservations.Contains(block, now) ||
            context.Reservations.Contains(block, context.Peer));
 }
Exemplo n.º 6
0
 private bool IsCompleted(MetamineStrategyContext context, MetamineBlock block)
 {
     return(context.Blocks.Contains(block));
 }
Exemplo n.º 7
0
 private bool IsReservable(MetamineStrategyContext context, MetamineBlock block, DateTime now)
 {
     return(IsCompleted(context, block) == false &&
            IsReserved(context, block, now) == false &&
            HasReservation(context) == false);
 }