public PeerHash Add(PeerHash peer, MetamineBlock request)
        {
            PeerHash            previous = null;
            MetamineReservation book;

            if (byBlock.TryGetValue(request, out book))
            {
                previous = book.Peer;
            }

            byBlock[request] = new MetamineReservation
            {
                Peer    = peer,
                Expires = DateTime.Now.AddSeconds(30),
                Request = request
            };

            if (byPeer.ContainsKey(peer) == false)
            {
                byPeer.Add(peer, new HashSet <MetamineReservation>());
            }

            byPeer[peer].Add(byBlock[request]);
            return(previous);
        }
        public bool Contains(MetamineBlock request, PeerHash peer)
        {
            MetamineReservation book;

            if (byBlock.TryGetValue(request, out book) == false)
            {
                return(false);
            }

            return(book.Peer.Equals(peer));
        }
        public bool Contains(MetamineBlock request, DateTime now)
        {
            MetamineReservation book;

            if (byBlock.TryGetValue(request, out book) == false)
            {
                return(false);
            }

            return(book.Expires > now);
        }
        public void Complete(MetamineBlock request)
        {
            MetamineReservation block;

            byBlock.TryGetValue(request, out block);

            if (block != null)
            {
                byPeer[block.Peer].Remove(block);
                byBlock.Remove(request);
            }
        }
예제 #5
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;
                }
            }
        }
예제 #6
0
 private bool IsCompleted(MetamineStrategyContext context, MetamineBlock block)
 {
     return(context.Blocks.Contains(block));
 }
예제 #7
0
 private bool IsReserved(MetamineStrategyContext context, MetamineBlock block, DateTime now)
 {
     return(context.Reservations.Contains(block, now) ||
            context.Reservations.Contains(block, context.Peer));
 }
예제 #8
0
 private bool IsReservable(MetamineStrategyContext context, MetamineBlock block, DateTime now)
 {
     return(IsCompleted(context, block) == false &&
            IsReserved(context, block, now) == false &&
            HasReservation(context) == false);
 }
예제 #9
0
 public void Complete(MetamineBlock block)
 {
     blocks.Complete(block);
     reservations.Complete(block);
 }
예제 #10
0
 public PeerHash Reserve(PeerHash peer, MetamineBlock block)
 {
     return(reservations.Add(peer, block));
 }
예제 #11
0
 public void Complete(MetamineBlock block)
 {
     blocks.Add(block);
 }
예제 #12
0
 public bool Contains(MetamineBlock block)
 {
     return(blocks.Contains(block));
 }