Changeset 1671


Ignore:
Timestamp:
Jun 18, 2010, 11:18:47 AM (12 years ago)
Author:
Paul Lelgemann
Message:

o Work on the distributed KeySearcher

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

Legend:

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

    r1665 r1671  
    11using System.Collections.Generic;
    2 using System.Data;
    3 using System.Numerics;
    42using Cryptool.PluginBase;
    53using KeySearcher.Helper;
    6 using KeySearcher.P2P.Exceptions;
    74using KeySearcher.P2P.Nodes;
    85
     
    1613        private readonly P2PHelper _p2PHelper;
    1714        private readonly NodeBase _rootNode;
    18         private bool _calculationFinishedOnStart;
    1915        private NodeBase _currentNode;
    20         private Leaf _currentLeaf;
    2116        private bool _skippedReservedNodes;
    22         private bool _useReservedNodes;
    23         private BigInteger _lastPatternId;
    2417
    2518        public KeyPoolTree(KeyPatternPool patternPool, KeySearcherSettings settings, KeySearcher keySearcher, KeyQualityHelper keyQualityHelper)
     
    3124            _p2PHelper = new P2PHelper(keySearcher);
    3225            _skippedReservedNodes = false;
    33             _useReservedNodes = false;
    34             _lastPatternId = -1;
    3526
    3627            _rootNode = NodeFactory.CreateNode(_p2PHelper, keyQualityHelper, null, 0, _patternPool.Length - 1, _settings.DistributedJobIdentifier);
    3728            _currentNode = _rootNode;
    38 
    39             _calculationFinishedOnStart = _rootNode.IsCalculated();
    4029        }
    4130
     
    5241                foundNode = FindNextLeaf(true);
    5342                _currentNode = foundNode;
    54                 _currentLeaf = foundNode;
    5543                return foundNode;
    5644            }
    5745
    5846            _currentNode = foundNode;
    59             _currentLeaf = foundNode;
    6047            return foundNode;
    6148        }
     
    6855            }
    6956
    70             bool isReserved = false;
    71             _p2PHelper.UpdateFromDht(_currentNode);
     57            var isReserved = false;
     58            _p2PHelper.UpdateFromDht(_currentNode, true);
    7259            while (_currentNode.IsCalculated() || ((isReserved = _currentNode.IsReserverd()) && !useReservedLeafs))
    7360            {
     
    8774
    8875                // Update the new _currentNode
    89                 _p2PHelper.UpdateFromDht(_currentNode);
     76                _p2PHelper.UpdateFromDht(_currentNode, true);
    9077            }
    9178
     
    10491        {
    10592            _rootNode.Reset();
    106             _currentNode = null;
    107             _currentLeaf = null;
     93            _currentNode = _rootNode;
    10894            _skippedReservedNodes = false;
    109             _useReservedNodes = false;
    110             _lastPatternId = -1;
    11195        }
    11296
    113         public void ProcessCurrentPatternCalculationResult(LinkedList<KeySearcher.ValueKey> result)
     97        public void ProcessCurrentPatternCalculationResult(Leaf currentLeaf, LinkedList<KeySearcher.ValueKey> result)
    11498        {
    115             _currentLeaf.HandleResults(result);
     99            currentLeaf.HandleResults(result);
    116100        }
    117101    }
  • trunk/CrypPlugins/KeySearcher/P2P/Nodes/Node.cs

    r1665 r1671  
    11using System.Numerics;
    22using KeySearcher.Helper;
     3using KeySearcher.P2P.Exceptions;
    34
    45namespace KeySearcher.P2P.Nodes
     
    5859            _leftChild = null;
    5960            _rightChild = null;
     61            LeftChildFinished = false;
     62            RightChildFinished = false;
    6063        }
    6164
     
    6871            {
    6972                return _leftChild.CalculatableLeaf(useReservedNodes);
     73            }
     74
     75            if (_rightChild == null)
     76            {
     77                throw new AlreadyCalculatedException();
    7078            }
    7179
  • trunk/CrypPlugins/KeySearcher/P2P/Nodes/P2PHelper.cs

    r1665 r1671  
    5555        internal RequestResult UpdateFromDht(NodeBase nodeToUpdate, bool forceUpdate = false)
    5656        {
    57             //var cacheActive = nodeToUpdate.LastUpdateResult != RequestResultType.KeyNotFound;
    58 
    5957            if (!forceUpdate && nodeToUpdate.LastUpdate > DateTime.Now.Subtract(new TimeSpan(0, 0, 5)))
    6058            {
  • trunk/CrypPlugins/KeySearcher/P2P/P2PBruteForce.cs

    r1665 r1671  
    3434
    3535            Leaf currentLeaf;
    36             while (!_keySearcher.stop && (currentLeaf = _keyPoolTree.FindNextLeaf()) != null)
     36            while (!_keySearcher.stop)
    3737            {
     38                try
     39                {
     40                    currentLeaf = _keyPoolTree.FindNextLeaf();
     41                    if (currentLeaf == null)
     42                    {
     43                        break;
     44                    }
     45                } catch(AlreadyCalculatedException)
     46                {
     47                    _keySearcher.GuiLogMessage("Node was already calculated.", NotificationLevel.Warning);
     48                    _keyPoolTree.Reset();
     49                    continue;
     50                }
     51
    3852                if (!currentLeaf.ReserveLeaf())
    3953                {
    4054                    _keySearcher.GuiLogMessage(
    41                         "Pattern " + currentLeaf.PatternId() +
     55                        "Pattern #" + currentLeaf.PatternId() +
    4256                        " was reserved before it could be reserved for this CrypTool instance.",
    4357                        NotificationLevel.Warning);
     
    5670                    if (!_keySearcher.stop)
    5771                    {
    58                         _keyPoolTree.ProcessCurrentPatternCalculationResult(result);
     72                        _keyPoolTree.ProcessCurrentPatternCalculationResult(currentLeaf, result);
    5973                    }
    6074                    else
     
    6983                catch(ReservationRemovedException)
    7084                {
    71                     _keySearcher.GuiLogMessage("Reservation removed. Proceeding to first available leaf...", NotificationLevel.Warning);
     85                    _keySearcher.GuiLogMessage("Reservation removed by another node (while calculating). " +
     86                                               "To avoid a state in limbo, proceeding to first available leaf...",
     87                                               NotificationLevel.Warning);
    7288                    _keyPoolTree.Reset();
    7389                    continue;
Note: See TracChangeset for help on using the changeset viewer.