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); } }
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; } } }
private bool IsCompleted(MetamineStrategyContext context, MetamineBlock block) { return(context.Blocks.Contains(block)); }
private bool IsReserved(MetamineStrategyContext context, MetamineBlock block, DateTime now) { return(context.Reservations.Contains(block, now) || context.Reservations.Contains(block, context.Peer)); }
private bool IsReservable(MetamineStrategyContext context, MetamineBlock block, DateTime now) { return(IsCompleted(context, block) == false && IsReserved(context, block, now) == false && HasReservation(context) == false); }
public void Complete(MetamineBlock block) { blocks.Complete(block); reservations.Complete(block); }
public PeerHash Reserve(PeerHash peer, MetamineBlock block) { return(reservations.Add(peer, block)); }
public void Complete(MetamineBlock block) { blocks.Add(block); }
public bool Contains(MetamineBlock block) { return(blocks.Contains(block)); }