Changeset 1665


Ignore:
Timestamp:
Jun 17, 2010, 5:11:02 PM (11 years ago)
Author:
Paul Lelgemann
Message:

+ CrypP2P: Return types of synchronous methods Store/Retrieve/Remove changed
o Work on the distributed KeySearcher

Location:
trunk
Files:
6 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/CrypP2P.csproj

    r1616 r1665  
    192192    <Compile Include="Internal\ConnectionManager.cs" />
    193193    <Compile Include="Internal\NotConnectedException.cs" />
     194    <Compile Include="Internal\RequestResult.cs" />
     195    <Compile Include="Internal\RequestResultType.cs" />
     196    <Compile Include="Internal\RequestType.cs" />
    194197    <Compile Include="P2PSettings.Designer.cs">
    195198      <AutoGen>True</AutoGen>
  • trunk/CrypP2P/Internal/P2PBase.cs

    r1645 r1665  
    351351        /// </summary>
    352352        /// <param name = "key">Key of DHT Entry</param>
     353        /// <param name = "value">Value of DHT Entry</param>
     354        /// <returns>True, when storing is completed!</returns>
     355        public RequestResult SynchStore(string key, string value)
     356        {
     357            return SynchStore(key, Encoding.UTF8.GetBytes(value));
     358        }
     359
     360        /// <summary>
     361        ///   Stores a value in the DHT at the given key
     362        /// </summary>
     363        /// <param name = "key">Key of DHT Entry</param>
    353364        /// <param name = "data">Value of DHT Entry</param>
    354365        /// <returns>True, when storing is completed!</returns>
    355         public bool SynchStore(string key, byte[] data)
     366        public RequestResult SynchStore(string key, byte[] data)
    356367        {
    357368            var autoResetEvent = new AutoResetEvent(false);
     
    360371            LogToMonitor("Begin: SynchStore. Key: " + key + ", " + data.Length + " bytes");
    361372
    362             var responseWait = new ResponseWait {WaitHandle = autoResetEvent, key = key, value = data};
    363             VersionedDht.Store(OnSynchStoreCompleted, key, data, responseWait);
     373            var requestResult = new RequestResult {WaitHandle = autoResetEvent, Key = key, Data = data};
     374            VersionedDht.Store(OnSynchStoreCompleted, key, data, requestResult);
    364375
    365376            // blocking till response
    366377            autoResetEvent.WaitOne();
    367378
    368             LogToMonitor("End: SynchStore. Key: " + key + ". Success: " + responseWait.success);
    369 
    370             return responseWait.success;
    371         }
    372 
    373         /// <summary>
    374         ///   Stores a value in the DHT at the given key
    375         /// </summary>
    376         /// <param name = "key">Key of DHT Entry</param>
    377         /// <param name = "value">Value of DHT Entry</param>
    378         /// <returns>True, when storing is completed!</returns>
    379         public bool SynchStore(string key, string value)
    380         {
    381             return SynchStore(key, Encoding.UTF8.GetBytes(value));
     379            LogToMonitor("End: SynchStore. Key: " + key + ". Status: " + requestResult.Status);
     380
     381            return requestResult;
    382382        }
    383383
     
    388388        private static void OnSynchStoreCompleted(StoreResult storeResult)
    389389        {
    390             var responseWait = storeResult.AsyncState as ResponseWait;
    391             if (responseWait == null)
    392             {
    393                 LogToMonitor("Received OnSynchStoreCompleted, but ResponseWait object is missing. Discarding.");
     390            var requestResult = storeResult.AsyncState as RequestResult;
     391            if (requestResult == null)
     392            {
     393                LogToMonitor("Received OnSynchStoreCompleted, but RequestResult object is missing. Discarding.");
    394394                return;
    395395            }
    396396
    397             responseWait.success = storeResult.Status == OperationStatus.Success;
    398             responseWait.operationStatus = storeResult.Status;
    399             responseWait.Message = Encoding.UTF8.GetBytes(storeResult.Status.ToString());
     397            requestResult.Parse(storeResult);
    400398
    401399            // unblock WaitHandle in the synchronous method
    402             responseWait.WaitHandle.Set();
     400            requestResult.WaitHandle.Set();
    403401        }
    404402
     
    408406        /// <param name = "key">Key of DHT Entry</param>
    409407        /// <returns>Value of DHT Entry</returns>
    410         public byte[] SynchRetrieve(string key)
     408        public RequestResult SynchRetrieve(string key)
    411409        {
    412410            LogToMonitor("Begin: SynchRetrieve. Key: " + key);
    413411
    414412            var autoResetEvent = new AutoResetEvent(false);
    415             var responseWait = new ResponseWait {WaitHandle = autoResetEvent, key = key};
    416             Dht.Retrieve(OnSynchRetrieveCompleted, key, responseWait);
     413            var requestResult = new RequestResult() {WaitHandle = autoResetEvent, Key = key};
     414            Dht.Retrieve(OnSynchRetrieveCompleted, key, requestResult);
    417415
    418416            // blocking till response
    419417            autoResetEvent.WaitOne();
    420418
    421             LogToMonitor("End: SynchRetrieve. Key: " + key + ". Success: " + responseWait.success);
    422 
    423             return responseWait.Message;
     419            LogToMonitor("End: SynchRetrieve. Key: " + key + ". Status: " + requestResult.Status);
     420
     421            return requestResult;
    424422        }
    425423
     
    430428        private static void OnSynchRetrieveCompleted(RetrieveResult retrieveResult)
    431429        {
    432             var responseWait = retrieveResult.AsyncState as ResponseWait;
    433             if (responseWait == null)
    434             {
    435                 LogToMonitor("Received OnSynchRetrieveCompleted, but ResponseWait object is missing. Discarding.");
     430            var requestResult = retrieveResult.AsyncState as RequestResult;
     431            if (requestResult == null)
     432            {
     433                LogToMonitor("Received OnSynchRetrieveCompleted, but RequestResult object is missing. Discarding.");
    436434                return;
    437435            }
    438436
    439             switch (retrieveResult.Status)
    440             {
    441                 case OperationStatus.Success:
    442                     responseWait.success = true;
    443                     responseWait.Message = retrieveResult.Data;
    444                     break;
    445                 case OperationStatus.KeyNotFound:
    446                     responseWait.success = true;
    447                     responseWait.Message = null;
    448                     break;
    449                 default:
    450                     responseWait.success = false;
    451                     responseWait.Message = null;
    452                     break;
    453             }
    454 
    455             responseWait.operationStatus = retrieveResult.Status;
     437            requestResult.Parse(retrieveResult);
    456438
    457439            // unblock WaitHandle in the synchronous method
    458             responseWait.WaitHandle.Set();
     440            requestResult.WaitHandle.Set();
    459441        }
    460442
     
    464446        /// <param name = "key">Key of the DHT Entry</param>
    465447        /// <returns>True, when removing is completed!</returns>
    466         public bool SynchRemove(string key)
     448        public RequestResult SynchRemove(string key)
    467449        {
    468450            LogToMonitor("Begin SynchRemove. Key: " + key);
    469451
    470452            var autoResetEvent = new AutoResetEvent(false);
    471             var responseWait = new ResponseWait {WaitHandle = autoResetEvent, key = key};
    472             VersionedDht.Remove(OnSynchRemoveCompleted, key, responseWait);
     453            var requestResult = new RequestResult { WaitHandle = autoResetEvent, Key = key };
     454            VersionedDht.Remove(OnSynchRemoveCompleted, key, requestResult);
    473455
    474456            // blocking till response
    475457            autoResetEvent.WaitOne();
    476458
    477             LogToMonitor("End: SynchRemove. Key: " + key + ". Success: " + responseWait.success);
    478 
    479             return responseWait.success;
     459            LogToMonitor("End: SynchRemove. Key: " + key + ". Status: " + requestResult.Status);
     460
     461            return requestResult;
    480462        }
    481463
     
    486468        private static void OnSynchRemoveCompleted(RemoveResult removeResult)
    487469        {
    488             var responseWait = removeResult.AsyncState as ResponseWait;
    489             if (responseWait == null)
    490             {
    491                 LogToMonitor("Received OnSynchRemoveCompleted, but ResponseWait object is missing. Discarding.");
     470            var requestResult = removeResult.AsyncState as RequestResult;
     471            if (requestResult == null)
     472            {
     473                LogToMonitor("Received OnSynchRemoveCompleted, but RequestResult object is missing. Discarding.");
    492474                return;
    493475            }
    494476
    495             responseWait.success = removeResult.Status != OperationStatus.Failure &&
    496                                    removeResult.Status != OperationStatus.VersionMismatch;
    497             responseWait.operationStatus = removeResult.Status;
    498             responseWait.Message = Encoding.UTF8.GetBytes(removeResult.Status.ToString());
     477            requestResult.Parse(removeResult);
    499478
    500479            // unblock WaitHandle in the synchronous method
    501             responseWait.WaitHandle.Set();
     480            requestResult.WaitHandle.Set();
    502481        }
    503482
  • trunk/CrypP2P/P2PManager.cs

    r1616 r1665  
    9696        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
    9797        /// <returns>true if the store attempt was successful, false otherwise</returns>
    98         public static bool Store(string key, byte[] data)
     98        public static RequestResult Store(string key, byte[] data)
    9999        {
    100100            if (!IsConnected)
     
    113113        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
    114114        /// <returns>true if the store attempt was successful, false otherwise</returns>
    115         public static bool Store(string key, string data)
     115        public static RequestResult Store(string key, string data)
    116116        {
    117117            if (!IsConnected)
     
    127127        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
    128128        /// <returns>byte array containing the data</returns>
    129         public static byte[] Retrieve(string key)
     129        public static RequestResult Retrieve(string key)
    130130        {
    131131            if (!IsConnected)
     
    143143        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
    144144        /// <returns>bool determining wether the attempt was successful</returns>
    145         public static bool Remove(string key)
     145        public static RequestResult Remove(string key)
    146146        {
    147147            if (!IsConnected)
  • trunk/CrypPlugins/KeySearcher/KeySearcher.csproj

    r1647 r1665  
    111111    </Compile>
    112112    <Compile Include="KeySearcherSettings.cs" />
    113     <Compile Include="P2P\Exceptions\LeafReservedException.cs" />
     113    <Compile Include="P2P\Exceptions\AlreadyCalculatedException.cs" />
     114    <Compile Include="P2P\Exceptions\ReservationRemovedException.cs" />
     115    <Compile Include="P2P\Exceptions\UpdateFailedException.cs" />
    114116    <Compile Include="P2P\KeyPoolTree.cs" />
    115117    <Compile Include="P2P\Nodes\Leaf.cs" />
  • trunk/CrypPlugins/KeySearcher/P2P/KeyPoolTree.cs

    r1651 r1665  
    11using System.Collections.Generic;
     2using System.Data;
    23using System.Numerics;
     4using Cryptool.PluginBase;
    35using KeySearcher.Helper;
    46using KeySearcher.P2P.Exceptions;
     
    1113        private readonly KeyPatternPool _patternPool;
    1214        private readonly KeySearcherSettings _settings;
     15        private readonly KeySearcher _keySearcher;
    1316        private readonly P2PHelper _p2PHelper;
    1417        private readonly NodeBase _rootNode;
    15         private readonly bool _calculationFinishedOnStart;
     18        private bool _calculationFinishedOnStart;
    1619        private NodeBase _currentNode;
    1720        private Leaf _currentLeaf;
     
    2427            _patternPool = patternPool;
    2528            _settings = settings;
     29            _keySearcher = keySearcher;
    2630
    2731            _p2PHelper = new P2PHelper(keySearcher);
    2832            _skippedReservedNodes = false;
     33            _useReservedNodes = false;
    2934            _lastPatternId = -1;
    3035
    3136            _rootNode = NodeFactory.CreateNode(_p2PHelper, keyQualityHelper, null, 0, _patternPool.Length - 1, _settings.DistributedJobIdentifier);
    32 
    33             AdvanceToFirstLeaf();
     37            _currentNode = _rootNode;
    3438
    3539            _calculationFinishedOnStart = _rootNode.IsCalculated();
    3640        }
    3741
    38         private void AdvanceToFirstLeaf()
     42        public Leaf FindNextLeaf()
    3943        {
    40             _currentNode = _rootNode.CalculatableNode(false);
     44            var nodeBeforeStarting = _currentNode;
     45            var foundNode = FindNextLeaf(false);
     46
     47            if (foundNode == null && _skippedReservedNodes)
     48            {
     49                _keySearcher.GuiLogMessage("Searching again with reserved nodes enabled...", NotificationLevel.Warning);
     50
     51                _currentNode = nodeBeforeStarting;
     52                foundNode = FindNextLeaf(true);
     53                _currentNode = foundNode;
     54                _currentLeaf = foundNode;
     55                return foundNode;
     56            }
     57
     58            _currentNode = foundNode;
     59            _currentLeaf = foundNode;
     60            return foundNode;
    4161        }
    4262
    43         public bool LocateNextPattern()
     63        private Leaf FindNextLeaf(bool useReservedLeafs)
    4464        {
    45             _useReservedNodes = false;
    46             _skippedReservedNodes = false;
    47             var patternLocated = LocateNextPattern(false);
    48 
    49             if (!patternLocated && _skippedReservedNodes)
     65            if (_currentNode == null)
    5066            {
    51                 patternLocated = LocateNextPattern(true);
    52                 _useReservedNodes = patternLocated;
     67                return null;
    5368            }
    5469
    55             return patternLocated;
     70            bool isReserved = false;
     71            _p2PHelper.UpdateFromDht(_currentNode);
     72            while (_currentNode.IsCalculated() || ((isReserved = _currentNode.IsReserverd()) && !useReservedLeafs))
     73            {
     74                if (isReserved)
     75                    _skippedReservedNodes = true;
     76
     77                // Current node is calculated or reserved,
     78                // move one node up and update it
     79                _currentNode = _currentNode.ParentNode;
     80
     81                // Root node calculated => everything finished
     82                if (_currentNode == null)
     83                {
     84                    _currentNode = _rootNode;
     85                    return null;
     86                }
     87
     88                // Update the new _currentNode
     89                _p2PHelper.UpdateFromDht(_currentNode);
     90            }
     91
     92            // currentNode is calculateable => find leaf
     93            return _currentNode.CalculatableLeaf(useReservedLeafs);
    5694        }
    5795
    58         private bool LocateNextPattern(bool includeReserved)
     96
     97        internal bool IsCalculationFinished()
    5998        {
    60             if (_calculationFinishedOnStart)
    61                 return false;
    62 
    63             if (_rootNode is Leaf)
    64             {
    65                 _currentLeaf = (Leaf) _rootNode;
    66                 return _rootNode.IsCalculated();
    67             }
    68 
    69             var nextNode = _currentNode.ParentNode;
    70             while (nextNode != null)
    71             {
    72                 _p2PHelper.UpdateFromDht(nextNode);
    73                 if (nextNode.IsCalculated())
    74                 {
    75                     nextNode = nextNode.ParentNode;
    76                     continue;
    77                 }
    78 
    79                 // Use next (independant of its reserved state), or use when not reserved
    80                 if (includeReserved || !nextNode.IsReserverd())
    81                 {
    82                     break;
    83                 }
    84                
    85                 _skippedReservedNodes = true;
    86                 nextNode = nextNode.ParentNode;
    87             }
    88 
    89             if (nextNode == null)
    90             {
    91                 return false;
    92             }
    93 
    94             _currentNode = nextNode.CalculatableNode(_useReservedNodes);
    95 
    96             if (((Leaf)_currentNode).PatternId() == _lastPatternId)
    97             {
    98                 AdvanceToFirstLeaf();
    99             }
    100 
    101             _currentLeaf = (Leaf)_currentNode;
    102             _lastPatternId = CurrentPatternId();
    103             return true;
     99            _p2PHelper.UpdateFromDht(_rootNode, true);
     100            return _rootNode.IsCalculated();
    104101        }
    105102
    106         public KeyPattern CurrentPattern()
     103        internal void Reset()
    107104        {
    108             if (!_currentLeaf.ReserveLeaf())
    109             {
    110                 throw new LeafReservedException();
    111             }
    112 
    113             return _patternPool[CurrentPatternId()];
     105            _rootNode.Reset();
     106            _currentNode = null;
     107            _currentLeaf = null;
     108            _skippedReservedNodes = false;
     109            _useReservedNodes = false;
     110            _lastPatternId = -1;
    114111        }
    115112
     
    118115            _currentLeaf.HandleResults(result);
    119116        }
    120 
    121         public BigInteger CurrentPatternId()
    122         {
    123             return _currentLeaf.PatternId();
    124         }
    125117    }
    126118}
  • trunk/CrypPlugins/KeySearcher/P2P/Nodes/Leaf.cs

    r1651 r1665  
    33using System.Numerics;
    44using KeySearcher.Helper;
     5using KeySearcher.P2P.Exceptions;
    56
    67namespace KeySearcher.P2P.Nodes
     
    2627        }
    2728
    28         public override NodeBase CalculatableNode(bool useReservedNodes)
     29        public override Leaf CalculatableLeaf(bool useReservedNodes)
    2930        {
     31            if (IsCalculated())
     32            {
     33                throw new AlreadyCalculatedException();
     34            }
     35
    3036            return this;
    3137        }
     
    3642        }
    3743
     44        public override void Reset()
     45        {
     46        }
     47
    3848        public bool ReserveLeaf()
    3949        {
    4050            LastReservationDate = DateTime.UtcNow;
    41             return P2PHelper.UpdateInDht(this);
     51            return P2PHelper.UpdateInDht(this).IsSuccessful();
    4252        }
    4353
  • trunk/CrypPlugins/KeySearcher/P2P/Nodes/Node.cs

    r1651 r1665  
    1717        }
    1818
    19         private void LoadOrUpdateChildNodes(bool ignoreReservation = false)
     19        private void LoadOrUpdateChildNodes()
    2020        {
    2121            var middle = (From + To)/2;
     
    3535
    3636            // Only load right node, if the left one is finished or reserved
    37             var leftChildsReservationExistingAndNotIgnored = !LeftChildFinished && _leftChild.IsReserverd() && !ignoreReservation;
    38             if ((LeftChildFinished || !leftChildsReservationExistingAndNotIgnored) && !RightChildFinished)
     37            if ((LeftChildFinished || _leftChild.IsReserverd()) && !RightChildFinished)
    3938            {
    4039                if (_rightChild == null)
     
    5150
    5251        public override bool IsCalculated()
    53         { 
     52        {
    5453            return LeftChildFinished && RightChildFinished;
    5554        }
    5655
    57         public override NodeBase CalculatableNode(bool useReservedNodes)
     56        public override void Reset()
    5857        {
    59             if (IsCalculated())
     58            _leftChild = null;
     59            _rightChild = null;
     60        }
     61
     62        public override Leaf CalculatableLeaf(bool useReservedNodes)
     63        {
     64            LoadOrUpdateChildNodes();
     65
     66            // Left child not finished and not reserved (or reserved leafs are allowed)
     67            if (!LeftChildFinished && (!_leftChild.IsReserverd() || useReservedNodes))
    6068            {
    61                 return null;
     69                return _leftChild.CalculatableLeaf(useReservedNodes);
    6270            }
    6371
    64             LoadOrUpdateChildNodes(true);
    65 
    66             if ((LeftChildFinished || (_leftChild.IsReserverd() && !useReservedNodes)) && !RightChildFinished)
    67             {
    68                 return _rightChild.CalculatableNode(useReservedNodes);
    69             }
    70 
    71             return _leftChild.CalculatableNode(useReservedNodes);
     72            return _rightChild.CalculatableLeaf(useReservedNodes);
    7273        }
    7374
     
    8990        }
    9091
    91 
    9292        public override bool IsReserverd()
    9393        {
    94             LoadOrUpdateChildNodes(true);
     94            LoadOrUpdateChildNodes();
    9595
    9696            var leftChildFinishedOrReserved = LeftChildFinished || _leftChild.IsReserverd();
  • trunk/CrypPlugins/KeySearcher/P2P/Nodes/NodeBase.cs

    r1651 r1665  
    33using System.Numerics;
    44using Cryptool.P2P;
     5using Cryptool.P2P.Internal;
    56using KeySearcher.Helper;
     7using KeySearcher.P2P.Exceptions;
    68
    79namespace KeySearcher.P2P.Nodes
     
    1618
    1719        protected internal DateTime LastUpdate;
     20        protected internal RequestResultType LastUpdateResult;
    1821
    1922        public readonly Node ParentNode;
     
    4548
    4649            // Compare with refreshed parent node
    47             P2PHelper.UpdateFromDht(ParentNode);
     50            var result = P2PHelper.UpdateFromDht(ParentNode, true);
     51            if (!result.IsSuccessful())
     52            {
     53                throw new UpdateFailedException("Parent node could not be updated: " + result.Status);
     54            }
    4855
     56            IntegrateResultsIntoParent();
     57            ParentNode.ChildFinished(this);
     58
     59            if (P2PManager.Retrieve(P2PHelper.KeyInDht(this)).Status == RequestResultType.KeyNotFound)
     60            {
     61                throw new ReservationRemovedException("Before updating parent node, this leaf's reservation was deleted.");
     62            }
     63
     64            var updateResult = P2PHelper.UpdateInDht(ParentNode);
     65            if (!updateResult.IsSuccessful())
     66            {
     67                throw new UpdateFailedException("Parent node could not be updated: " + updateResult.Status);
     68            }
     69
     70            P2PManager.Remove(P2PHelper.KeyInDht(this));
     71
     72            if (ParentNode.IsCalculated())
     73            {
     74                ParentNode.UpdateDht();
     75            }
     76        }
     77
     78        private void IntegrateResultsIntoParent()
     79        {
    4980            var bestValue = double.MinValue;
    5081            if (ParentNode.Result.Count > 0)
     
    73104                }
    74105            }
    75 
    76             ParentNode.ChildFinished(this);
    77 
    78             P2PHelper.UpdateInDht(ParentNode);
    79             P2PManager.Retrieve(P2PHelper.KeyInDht(this));
    80             P2PManager.Remove(P2PHelper.KeyInDht(this));
    81 
    82             if (ParentNode.IsCalculated())
    83             {
    84                 ParentNode.UpdateDht();
    85             }
    86106        }
    87107
    88108        private void UpdateDhtForRootNode()
    89109        {
    90             P2PHelper.UpdateFromDht(this);
     110            P2PHelper.UpdateFromDht(this, true);
    91111            P2PHelper.UpdateInDht(this);
    92112        }
     
    94114        public abstract bool IsReserverd();
    95115
    96         public abstract NodeBase CalculatableNode(bool useReservedNodes);
     116        public abstract Leaf CalculatableLeaf(bool useReservedNodes);
    97117
    98118        public abstract bool IsCalculated();
     119
     120        public abstract void Reset();
    99121
    100122        public override string ToString()
  • trunk/CrypPlugins/KeySearcher/P2P/Nodes/P2PHelper.cs

    r1651 r1665  
    22using System.IO;
    33using Cryptool.P2P;
     4using Cryptool.P2P.Internal;
    45
    56namespace KeySearcher.P2P.Nodes
     
    78    class P2PHelper
    89    {
    9         private KeySearcher _keySearcher;
     10        private readonly KeySearcher _keySearcher;
    1011
    1112        public P2PHelper(KeySearcher keySearcher)
     
    1415        }
    1516
    16         internal static bool UpdateInDht(NodeBase nodeToUpdate)
     17        internal static RequestResult UpdateInDht(NodeBase nodeToUpdate)
    1718        {
    1819            var memoryStream = new MemoryStream();
     
    5253        }
    5354
    54         internal void UpdateFromDht(NodeBase nodeToUpdate)
     55        internal RequestResult UpdateFromDht(NodeBase nodeToUpdate, bool forceUpdate = false)
    5556        {
    56             if (nodeToUpdate.LastUpdate > DateTime.Now.Subtract(new TimeSpan(0, 0, 5)))
     57            //var cacheActive = nodeToUpdate.LastUpdateResult != RequestResultType.KeyNotFound;
     58
     59            if (!forceUpdate && nodeToUpdate.LastUpdate > DateTime.Now.Subtract(new TimeSpan(0, 0, 5)))
    5760            {
    58                 return;
     61                return new RequestResult { Status = RequestResultType.Success };
    5962            }
    6063
    6164            nodeToUpdate.LastUpdate = DateTime.Now;
    6265
    63             var nodeBytes = P2PManager.Retrieve(KeyInDht(nodeToUpdate));
     66            var requestResult = P2PManager.Retrieve(KeyInDht(nodeToUpdate));
     67            var nodeBytes = requestResult.Data;
     68            nodeToUpdate.LastUpdateResult = requestResult.Status;
    6469
    6570            if (nodeBytes == null)
    6671            {
    67                 return;
     72                return requestResult;
    6873            }
    6974
     
    95100                _keySearcher.IntegrateNewResults(nodeToUpdate.Result);
    96101            }
     102
     103            return requestResult;
    97104        }
    98105
  • trunk/CrypPlugins/KeySearcher/P2P/P2PBruteForce.cs

    r1651 r1665  
    44using KeySearcher.Helper;
    55using KeySearcher.P2P.Exceptions;
     6using KeySearcher.P2P.Nodes;
    67
    78namespace KeySearcher.P2P
     
    1011    {
    1112        private readonly KeySearcher _keySearcher;
    12         private readonly KeyPattern _keyPattern;
    1313        private readonly KeySearcherSettings _settings;
    1414        private readonly KeyPatternPool _patternPool;
     
    1818        {
    1919            _keySearcher = keySearcher;
    20             _keyPattern = keyPattern;
    2120            _settings = settings;
    2221
     
    3231            _keySearcher.GuiLogMessage(
    3332                "Total amount of patterns: " + _patternPool.Length + ", each containing " + _patternPool.PartSize +
    34                 " keys.", NotificationLevel.Debug);
     33                " keys.", NotificationLevel.Info);
    3534
    36             while (!_keySearcher.stop && _keyPoolTree.LocateNextPattern())
     35            Leaf currentLeaf;
     36            while (!_keySearcher.stop && (currentLeaf = _keyPoolTree.FindNextLeaf()) != null)
    3737            {
     38                if (!currentLeaf.ReserveLeaf())
     39                {
     40                    _keySearcher.GuiLogMessage(
     41                        "Pattern " + currentLeaf.PatternId() +
     42                        " was reserved before it could be reserved for this CrypTool instance.",
     43                        NotificationLevel.Warning);
     44                    _keyPoolTree.Reset();
     45                    continue;
     46                }
     47
    3848                _keySearcher.GuiLogMessage(
    39                     "Running pattern #" + (_keyPoolTree.CurrentPatternId() + 1) + " of " + _patternPool.Length,
     49                    "Running pattern #" + (currentLeaf.PatternId() + 1) + " of " + _patternPool.Length,
    4050                    NotificationLevel.Info);
    4151
    4252                try
    4353                {
    44                     var result = _keySearcher.BruteForceWithLocalSystem(_keyPoolTree.CurrentPattern());
     54                    var result = _keySearcher.BruteForceWithLocalSystem(_patternPool[currentLeaf.PatternId()]);
    4555
    4656                    if (!_keySearcher.stop)
     
    5666                        string.Format("Best match: {0} with {1}", result.First.Value.key, result.First.Value.value),
    5767                        NotificationLevel.Info);               
    58                 } catch (LeafReservedException e)
     68                }
     69                catch(ReservationRemovedException)
    5970                {
    60                     _keySearcher.GuiLogMessage("Pattern was reserved before it could be reserved for this CrypTool instance.", NotificationLevel.Warning);
     71                    _keySearcher.GuiLogMessage("Reservation removed. Proceeding to first available leaf...", NotificationLevel.Warning);
     72                    _keyPoolTree.Reset();
     73                    continue;
     74                }
     75                catch (UpdateFailedException e)
     76                {
     77                    _keySearcher.GuiLogMessage("Could not store results: " + e.Message, NotificationLevel.Warning);
     78                    _keyPoolTree.Reset();
    6179                    continue;
    6280                }
     
    6482
    6583            // Set progress to 100%
    66             if (!_keySearcher.stop && !_keyPoolTree.LocateNextPattern())
     84            if (!_keySearcher.stop && _keyPoolTree.IsCalculationFinished())
    6785            {
    6886                _keySearcher.showProgress(_keySearcher.costList, 1, 1, 1);
     87                _keySearcher.GuiLogMessage("Calculation complete.", NotificationLevel.Info);
    6988            }
    70 
    71             if (!_keySearcher.stop)
    72                 _keySearcher.GuiLogMessage("Calculation complete or no more free nodes found.", NotificationLevel.Info);
    7389        }
    7490    }
  • trunk/CrypPlugins/P2PEditor/Distributed/JobListManager.cs

    r1643 r1665  
    1 using System.Collections.Generic;
     1using System;
     2using System.Collections.Generic;
    23using System.IO;
    34using System.Runtime.Serialization.Formatters.Binary;
     
    2829            }
    2930
    30             byte[] serialisedJobList = P2PManager.Retrieve(JoblistKey);
    31 
     31            var serialisedJobList = P2PManager.Retrieve(JoblistKey).Data;
    3232            if (serialisedJobList == null)
    3333            {
     
    102102        public void CompleteDistributedJob(DistributedJob distributedJob)
    103103        {
    104             distributedJob.ConvertRawWorkspaceToLocalFile(P2PManager.Retrieve(GenerateWorkspaceKey(distributedJob)));
     104            distributedJob.ConvertRawWorkspaceToLocalFile(P2PManager.Retrieve(GenerateWorkspaceKey(distributedJob)).Data);
    105105        }
    106106
  • trunk/CrypPlugins/PeerToPeerBaseProxy/P2PPeer.cs

    r1634 r1665  
    332332        public bool DHTstore(string sKey, byte[] byteValue)
    333333        {
    334             return P2PManager.IsConnected && P2PManager.Store(sKey, byteValue);
     334            return P2PManager.IsConnected && P2PManager.Store(sKey, byteValue).IsSuccessful();
    335335        }
    336336
    337337        public bool DHTstore(string sKey, string sValue)
    338338        {
    339             return P2PManager.IsConnected && P2PManager.Store(sKey, sValue);
     339            return P2PManager.IsConnected && P2PManager.Store(sKey, sValue).IsSuccessful();
    340340        }
    341341
    342342        public byte[] DHTload(string sKey)
    343343        {
    344             return P2PManager.IsConnected ? P2PManager.Retrieve(sKey) : null;
     344            return P2PManager.IsConnected ? P2PManager.Retrieve(sKey).Data : null;
    345345        }
    346346
    347347        public bool DHTremove(string sKey)
    348348        {
    349             return P2PManager.IsConnected && P2PManager.Remove(sKey);
     349            return P2PManager.IsConnected && P2PManager.Remove(sKey).IsSuccessful();
    350350        }
    351351
  • trunk/CrypPlugins/QuadraticSieve/PeerToPeer.cs

    r1657 r1665  
    106106        {
    107107            ownerID = 0;
    108             byte[] yield = P2PManager.Retrieve(YieldIdentifier(index));
     108            byte[] yield = P2PManager.Retrieve(YieldIdentifier(index)).Data;
    109109            if (yield == null)
    110110                return null;
     
    151151                    if (!nameCache.ContainsKey(ownerID))
    152152                    {
    153                         byte[] n = P2PManager.Retrieve(NameIdentifier(ownerID));
     153                        byte[] n = P2PManager.Retrieve(NameIdentifier(ownerID)).Data;
    154154                        if (n != null)
    155155                            nameCache.Add(ownerID, System.Text.ASCIIEncoding.ASCII.GetString(n));
     
    225225                    {
    226226                        byte[] yield = (byte[])storequeue.Dequeue();
    227                         bool success = P2PManager.Store(YieldIdentifier(head), yield);
     227                        bool success = P2PManager.Store(YieldIdentifier(head), yield).IsSuccessful();
    228228                        while (!success)
    229229                        {
    230230                            SynchronizeHead();
    231                             success = P2PManager.Store(YieldIdentifier(head), yield);
     231                            success = P2PManager.Store(YieldIdentifier(head), yield).IsSuccessful();
    232232                        }
    233233                        SetProgressYield(head, ourID, null);
     
    289289        private void UpdatePeerPerformanceInformation(int peerID)
    290290        {
    291             byte[] performancebytes = P2PManager.Retrieve(PerformanceIdentifier(peerID));
     291            byte[] performancebytes = P2PManager.Retrieve(PerformanceIdentifier(peerID)).Data;
    292292            if (performancebytes != null)
    293293            {
     
    318318        private void SynchronizeHead()
    319319        {
    320             byte[] h = P2PManager.Retrieve(HeadIdentifier());
     320            byte[] h = P2PManager.Retrieve(HeadIdentifier()).Data;
    321321            if (h != null)
    322322            {
     
    324324                if (head > dhthead)
    325325                {
    326                     bool success = P2PManager.Store(HeadIdentifier(), System.Text.ASCIIEncoding.ASCII.GetBytes(head.ToString()));
     326                    bool success = P2PManager.Store(HeadIdentifier(), System.Text.ASCIIEncoding.ASCII.GetBytes(head.ToString())).IsSuccessful();
    327327                    if (!success)
    328328                        SynchronizeHead();
     
    337337            else
    338338            {
    339                 bool success = P2PManager.Store(HeadIdentifier(), System.Text.ASCIIEncoding.ASCII.GetBytes(head.ToString()));
     339                bool success = P2PManager.Store(HeadIdentifier(), System.Text.ASCIIEncoding.ASCII.GetBytes(head.ToString())).IsSuccessful();
    340340                if (!success)
    341341                    SynchronizeHead();
     
    526526            FactorManager dhtFactorManager = null;
    527527            //load DHT Factor Manager:
    528             byte[] dhtFactorManagerBytes = P2PManager.Retrieve(FactorListIdentifier());
     528            byte[] dhtFactorManagerBytes = P2PManager.Retrieve(FactorListIdentifier()).Data;
    529529            if (dhtFactorManagerBytes != null)
    530530            {
     
    554554                bformatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
    555555                bformatter.Serialize(memstream, factorManager);
    556                 bool success = P2PManager.Store(FactorListIdentifier(), memstream.ToArray());
     556                bool success = P2PManager.Store(FactorListIdentifier(), memstream.ToArray()).IsSuccessful();
    557557                if (!success)
    558558                {
Note: See TracChangeset for help on using the changeset viewer.