示例#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());
        }
        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;
                }
            }
        }
示例#3
0
 public abstract IEnumerable <MetamineBlock> Next(MetamineStrategyContext context);
 private bool HasReservation(MetamineStrategyContext context)
 {
     return(context.Reservations.Contains(context.Peer));
 }
 private bool IsReserved(MetamineStrategyContext context, MetamineBlock block, DateTime now)
 {
     return(context.Reservations.Contains(block, now) ||
            context.Reservations.Contains(block, context.Peer));
 }
 private bool IsCompleted(MetamineStrategyContext context, MetamineBlock block)
 {
     return(context.Blocks.Contains(block));
 }
 private bool IsReservable(MetamineStrategyContext context, MetamineBlock block, DateTime now)
 {
     return(IsCompleted(context, block) == false &&
            IsReserved(context, block, now) == false &&
            HasReservation(context) == false);
 }