Changeset 1693


Ignore:
Timestamp:
Jun 23, 2010, 2:04:44 PM (11 years ago)
Author:
Paul Lelgemann
Message:

o Work on the distributed KeySearcher cache

Location:
trunk/CrypPlugins/KeySearcher/P2P
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/P2P/DistributedBruteForceManager.cs

    r1682 r1693  
    11using System;
    2 using System.Collections.Generic;
    32using System.Diagnostics;
    43using System.Numerics;
  • trunk/CrypPlugins/KeySearcher/P2P/Presentation/StatisticsGenerator.cs

    r1682 r1693  
    9898            var remainingChunks = totalAmountOfChunks - nextChunk;
    9999            var secondsRemaining = (double) remainingChunks*secondsForOneChunk;
    100             status.EstimatedFinishDate = DateTime.Now.AddSeconds(secondsRemaining).ToString("dd.MM. HH:mm");
     100
     101            try
     102            {
     103                status.EstimatedFinishDate = DateTime.Now.AddSeconds(secondsRemaining).ToString("dd.MM. HH:mm");
     104            }
     105            catch (ArgumentOutOfRangeException)
     106            {
     107                status.EstimatedFinishDate = "~";
     108            }
     109
    101110            lastDateOfGlobalStatistics = DateTime.Now;
    102111
  • trunk/CrypPlugins/KeySearcher/P2P/Storage/StorageHelper.cs

    r1682 r1693  
    105105            }
    106106
     107            nodeToUpdate.UpdateCache();
    107108            return requestResult;
    108109        }
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/KeyPoolTree.cs

    r1682 r1693  
    7171            bool isReserved = false;
    7272            storageHelper.UpdateFromDht(currentNode, true);
    73             while (currentNode.IsCalculated() || ((isReserved = currentNode.IsReserverd()) && !useReservedLeafs))
     73            currentNode.UpdateCache();
     74            while (currentNode.IsCalculated() || (!useReservedLeafs && (isReserved = currentNode.IsReserverd())))
    7475            {
    7576                if (isReserved)
     
    8990                // Update the new _currentNode
    9091                storageHelper.UpdateFromDht(currentNode, true);
     92                currentNode.UpdateCache();
    9193            }
    9294
    9395            // currentNode is calculateable => find leaf
     96            currentNode.UpdateCache();
    9497            return currentNode.CalculatableLeaf(useReservedLeafs);
    9598        }
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/Leaf.cs

    r1674 r1693  
    1111    {
    1212        internal DateTime LastReservationDate;
     13        private bool isLeafReserved;
    1314
    1415        public Leaf(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger id, string distributedJobIdentifier)
     
    4748        }
    4849
     50        public override void UpdateCache()
     51        {
     52            var dateFiveMinutesBefore = DateTime.UtcNow.Subtract(new TimeSpan(0, 5, 0));
     53            isLeafReserved = dateFiveMinutesBefore < LastReservationDate;
     54        }
     55
    4956        public bool ReserveLeaf()
    5057        {
     
    5562        public override bool IsReserverd()
    5663        {
    57             var dateFiveMinutesBefore = DateTime.UtcNow.Subtract(new TimeSpan(0, 5, 0));
    58             var isReserverd = dateFiveMinutesBefore < LastReservationDate;
    59             return isReserverd;
     64            return isLeafReserved;
    6065        }
    6166
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/Node.cs

    r1674 r1693  
    1 using System.Numerics;
     1using System;
     2using System.Numerics;
    23using KeySearcher.Helper;
    34using KeySearcher.P2P.Exceptions;
     
    1314        private NodeBase leftChild;
    1415        private NodeBase rightChild;
     16        private bool leftChildReserved;
     17        private bool rightChildReserved;
    1518
    1619        public Node(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger @from, BigInteger to, string distributedJobIdentifier)
     
    6265        }
    6366
    64         public override Leaf CalculatableLeaf(bool useReservedNodes)
     67        public override void UpdateCache()
    6568        {
    6669            LoadOrUpdateChildNodes();
    6770
     71            leftChildReserved = LeftChildFinished || leftChild.IsReserverd();
     72            rightChildReserved = RightChildFinished || (rightChild != null && rightChild.IsReserverd());
     73        }
     74
     75        public override Leaf CalculatableLeaf(bool useReservedNodes)
     76        {
     77            // LoadOrUpdateChildNodes();
     78
    6879            // Left child not finished and not reserved (or reserved leafs are allowed)
    69             if (!LeftChildFinished && (!leftChild.IsReserverd() || useReservedNodes))
     80            if (!LeftChildFinished && (!leftChildReserved || useReservedNodes))
    7081            {
    7182                return leftChild.CalculatableLeaf(useReservedNodes);
     
    8697                LeftChildFinished = true;
    8798                leftChild = null;
     99                UpdateCache();
    88100                return;
    89101            }
     
    93105                RightChildFinished = true;
    94106                rightChild = null;
     107                UpdateCache();
    95108                return;
    96109            }
     
    99112        public override bool IsReserverd()
    100113        {
    101             LoadOrUpdateChildNodes();
     114            // LoadOrUpdateChildNodes();
    102115
    103             var leftChildFinishedOrReserved = LeftChildFinished || leftChild.IsReserverd();
     116            // var leftChildFinishedOrReserved = LeftChildFinished || leftChildReserved;
    104117
     118            if (LeftChildFinished && !RightChildFinished)
     119            {
     120                return rightChildReserved;
     121            }
     122
     123            if (!LeftChildFinished && RightChildFinished)
     124            {
     125                return leftChildReserved;
     126            }
     127
     128            if (!LeftChildFinished && !RightChildFinished && rightChildReserved)
     129            {
     130                return leftChildReserved;
     131            }
     132
     133            return rightChildReserved;
     134            /*
    105135            if (leftChildFinishedOrReserved && !RightChildFinished)
    106136            {
    107                 return rightChild.IsReserverd();
     137                return rightChildReserved;
    108138            }
    109139
    110             return !LeftChildFinished && leftChild.IsReserverd();
     140            return !LeftChildFinished && leftChildReserved;*/
    111141        }
    112142
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/NodeBase.cs

    r1682 r1693  
    5656            IntegrateResultsIntoParent();
    5757            ParentNode.ChildFinished(this);
     58            ParentNode.UpdateCache();
    5859
    5960            if (StorageHelper.RetrieveWithStatistic(StorageHelper.KeyInDht(this)).Status == RequestResultType.KeyNotFound)
     
    120121        public abstract void Reset();
    121122
     123        public abstract void UpdateCache();
     124
    122125        public override string ToString()
    123126        {
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/NodeFactory.cs

    r1674 r1693  
    2222            }
    2323
     24            newNode.UpdateCache();
    2425            return newNode;
    2526        }
Note: See TracChangeset for help on using the changeset viewer.