Example #1
0
        public SyncPeerAllocation Borrow(BorrowOptions borrowOptions, string description)
        {
            SyncPeerAllocation allocation = new SyncPeerAllocation(description);

            if ((borrowOptions & BorrowOptions.DoNotReplace) == BorrowOptions.DoNotReplace)
            {
                allocation.CanBeReplaced = false;
            }

            PeerInfo bestPeer = SelectBestPeerForAllocation(allocation, "BORROW");

            if (bestPeer != null)
            {
                allocation.ReplaceCurrent(bestPeer);
            }

            _allocations.TryAdd(allocation, null);
            return(allocation);
        }
Example #2
0
        public SyncPeerAllocation Borrow(BorrowOptions borrowOptions, string description, long?minNumber = null)
        {
            SyncPeerAllocation allocation = new SyncPeerAllocation(description);

            allocation.MinBlocksAhead = minNumber - _blockTree.BestSuggestedHeader?.Number;

            if ((borrowOptions & BorrowOptions.DoNotReplace) == BorrowOptions.DoNotReplace)
            {
                allocation.CanBeReplaced = false;
            }

            PeerInfo bestPeer = SelectBestPeerForAllocation(allocation, "BORROW", (borrowOptions & BorrowOptions.LowPriority) == BorrowOptions.LowPriority);

            if (bestPeer != null)
            {
                allocation.ReplaceCurrent(bestPeer);
            }

            _allocations.TryAdd(allocation, null);
            return(allocation);
        }