Changeset 1674


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

o Refactored distributed KeySearcher: updated directory structure and variable names

Location:
trunk/CrypPlugins
Files:
5 added
1 deleted
12 edited
5 copied
7 moved

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeyPatternJob/DistributableKeyPatternJob.cs

    r1448 r1674  
    1818using System.Linq;
    1919using System.Text;
    20 using KeySearcher;
     20using KeySearcher.KeyPattern;
    2121using Cryptool.PluginBase.Miscellaneous;
    2222using System.Numerics;
  • trunk/CrypPlugins/KeyPatternJob/KeyPatternJobPart.cs

    r1448 r1674  
    1818using System.Linq;
    1919using System.Text;
     20using KeySearcher.KeyPattern;
    2021using Cryptool.Plugins.PeerToPeer.Jobs;
    21 using KeySearcher;
    2222using System.IO;
    2323using Cryptool.PluginBase.Miscellaneous;
  • trunk/CrypPlugins/KeySearcher/Helper/KeyQualityHelper.cs

    r1634 r1674  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using Cryptool.PluginBase.Control;
     1using Cryptool.PluginBase.Control;
    62
    73namespace KeySearcher.Helper
     
    95    class KeyQualityHelper
    106    {
    11         private readonly IControlCost _costFunction;
     7        private readonly IControlCost costFunction;
    128
    139        public KeyQualityHelper(IControlCost costFunction)
    1410        {
    15             _costFunction = costFunction;
     11            this.costFunction = costFunction;
    1612        }
    1713
    1814        public bool IsBetter(double value, double threshold)
    1915        {
    20             if (_costFunction.getRelationOperator() == RelationOperator.LargerThen)
     16            if (costFunction.getRelationOperator() == RelationOperator.LargerThen)
    2117            {
    2218                if (value > threshold)
  • trunk/CrypPlugins/KeySearcher/KeyPattern/KeyPattern.cs

    r1673 r1674  
    1616
    1717using System;
    18 using System.Collections.Generic;
    19 using System.Linq;
    2018using System.Text;
    21 using Cryptool.PluginBase.Miscellaneous;
    2219using System.Collections;
    2320using System.IO;
    2421using System.Numerics;
    2522
    26 namespace KeySearcher
     23namespace KeySearcher.KeyPattern
    2724{
    2825    public class KeyPattern
  • trunk/CrypPlugins/KeySearcher/KeyPattern/KeyPatternPool.cs

    r1673 r1674  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using Cryptool.PluginBase.Miscellaneous;
    63using System.Collections;
    74using System.Numerics;
    85using System.Diagnostics;
    96
    10 namespace KeySearcher
     7namespace KeySearcher.KeyPattern
    118{
    129    /**
  • trunk/CrypPlugins/KeySearcher/KeyPattern/Wildcard.cs

    r1673 r1674  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 
    6 namespace KeySearcher
     1namespace KeySearcher.KeyPattern
    72{
    83    internal class Wildcard
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1647 r1674  
    1212using System.Threading;
    1313using System.Windows.Threading;
    14 using Cryptool.PluginBase.Miscellaneous;
    15 using System.IO;
    1614using Cryptool.PluginBase.IO;
    1715using System.Numerics;
    1816using KeySearcher.Helper;
    1917using KeySearcher.P2P;
     18using KeySearcher.Presentation;
    2019
    2120namespace KeySearcher
     
    3837        private KeyQualityHelper _keyQualityHelper;
    3938
    40         private KeyPattern pattern = null;
    41         public KeyPattern Pattern
     39        private KeyPattern.KeyPattern pattern = null;
     40        public KeyPattern.KeyPattern Pattern
    4241        {
    4342            get
     
    7271                if (value != null)
    7372                {
    74                     Pattern = new KeyPattern(value.getKeyPattern());
     73                    Pattern = new KeyPattern.KeyPattern(value.getKeyPattern());
    7574                    value.keyPatternChanged += keyPatternChanged;
    7675                    controlMaster = value;
     
    300299        {
    301300            object[] parameters = (object[])param;
    302             KeyPattern[] patterns = (KeyPattern[])parameters[0];
     301            KeyPattern.KeyPattern[] patterns = (KeyPattern.KeyPattern[])parameters[0];
    303302            int threadid = (int)parameters[1];
    304303            BigInteger[] doneKeysArray = (BigInteger[])parameters[2];
     
    309308            Stack threadStack = (Stack)parameters[7];
    310309
    311             KeyPattern pattern = patterns[threadid];
     310            KeyPattern.KeyPattern pattern = patterns[threadid];
    312311
    313312            bool useKeyblocks = false;
     
    331330                                if (maxThread == threadid && threadStack.Count != 0)
    332331                                {
    333                                     KeyPattern[] split = pattern.split();
     332                                    KeyPattern.KeyPattern[] split = pattern.split();
    334333                                    if (split != null)
    335334                                    {
     
    427426
    428427        private bool bruteforceBlock(IControlEncryption sender, int bytesToUse, ref ValueKey valueKey, byte[] keya, int[] arrayPointers,
    429             int[] arraySuccessors, int[] arrayUppers, int arrayPointer, ref int counter, KeyPattern pattern)
     428            int[] arraySuccessors, int[] arrayUppers, int arrayPointer, ref int counter, KeyPattern.KeyPattern pattern)
    430429        {
    431430            byte store = keya[arrayPointers[arrayPointer]];
     
    457456        }
    458457
    459         private bool decryptAndCalculate(IControlEncryption sender, int bytesToUse, ref ValueKey valueKey, byte[] keya, int counter, KeyPattern pattern)
     458        private bool decryptAndCalculate(IControlEncryption sender, int bytesToUse, ref ValueKey valueKey, byte[] keya, int counter, KeyPattern.KeyPattern pattern)
    460459        {
    461460            try
     
    551550        // modified by Christian Arnold 2009.12.07 - return type LinkedList (top10List)
    552551        // main entry point to the KeySearcher
    553         private LinkedList<ValueKey> bruteforcePattern(KeyPattern pattern)
     552        private LinkedList<ValueKey> bruteforcePattern(KeyPattern.KeyPattern pattern)
    554553        {
    555554            //For evaluation issues - added by Arnold 2010.03.17
     
    599598            GuiLogMessage("Launching p2p based bruteforce logic...", NotificationLevel.Info);
    600599            ValidateConnectionToPeerToPeerSystem();
    601             new P2PBruteForce(this, pattern, settings, _keyQualityHelper);
     600            var bruteForceManager = new DistributedBruteForceManager(this, pattern, settings, _keyQualityHelper);
     601            bruteForceManager.Execute();
    602602        }
    603603
     
    650650        #endregion
    651651
    652         internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern pattern)
     652        internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern.KeyPattern pattern)
    653653        {
    654654            BigInteger size = pattern.size();
    655             KeyPattern[] patterns = splitPatternForThreads(pattern);
     655            KeyPattern.KeyPattern[] patterns = splitPatternForThreads(pattern);
    656656
    657657            BigInteger[] doneKeysA = new BigInteger[patterns.Length];
     
    950950        #endregion
    951951
    952         private void startThreads(IControlEncryption sender, int bytesToUse, KeyPattern[] patterns, BigInteger[] doneKeysA, BigInteger[] keycounters, BigInteger[] keysleft, Stack threadStack)
     952        private void startThreads(IControlEncryption sender, int bytesToUse, KeyPattern.KeyPattern[] patterns, BigInteger[] doneKeysA, BigInteger[] keycounters, BigInteger[] keysleft, Stack threadStack)
    953953        {
    954954            for (int i = 0; i < patterns.Length; i++)
     
    962962        }
    963963
    964         private KeyPattern[] splitPatternForThreads(KeyPattern pattern)
    965         {
    966             KeyPattern[] patterns = new KeyPattern[settings.CoresUsed + 1];
     964        private KeyPattern.KeyPattern[] splitPatternForThreads(KeyPattern.KeyPattern pattern)
     965        {
     966            KeyPattern.KeyPattern[] patterns = new KeyPattern.KeyPattern[settings.CoresUsed + 1];
    967967            if (settings.CoresUsed > 0)
    968968            {
    969                 KeyPattern[] patterns2 = pattern.split();
     969                KeyPattern.KeyPattern[] patterns2 = pattern.split();
    970970                if (patterns2 == null)
    971971                {
    972                     patterns2 = new KeyPattern[1];
     972                    patterns2 = new KeyPattern.KeyPattern[1];
    973973                    patterns2[0] = pattern;
    974974                    return patterns2;
     
    988988                            maxPattern = i;
    989989                        }
    990                     KeyPattern[] patterns3 = patterns[maxPattern].split();
     990                    KeyPattern.KeyPattern[] patterns3 = patterns[maxPattern].split();
    991991                    if (patterns3 == null)
    992992                    {
    993                         patterns3 = new KeyPattern[p+1];
     993                        patterns3 = new KeyPattern.KeyPattern[p+1];
    994994                        for (int i = 0; i <= p; i++)
    995995                            patterns3[i] = patterns[i];
     
    10081008        private void keyPatternChanged()
    10091009        {
    1010             Pattern = new KeyPattern(controlMaster.getKeyPattern());
     1010            Pattern = new KeyPattern.KeyPattern(controlMaster.getKeyPattern());
    10111011        }
    10121012
     
    10211021        // added by Arnie -2009.12.02
    10221022        // for inheritance reasons
    1023         public void BruteforcePattern(KeyPattern pattern, byte[] encryptedData, byte[] initVector, IControlEncryption encryptControl, IControlCost costControl)
     1023        public void BruteforcePattern(KeyPattern.KeyPattern pattern, byte[] encryptedData, byte[] initVector, IControlEncryption encryptControl, IControlCost costControl)
    10241024        {
    10251025            /* Begin: New stuff because of changing the IControl data flow - Arnie 2010.01.18 */
  • trunk/CrypPlugins/KeySearcher/KeySearcher.csproj

    r1665 r1674  
    104104  <ItemGroup>
    105105    <Compile Include="Helper\KeyQualityHelper.cs" />
    106     <Compile Include="KeyPattern.cs" />
    107     <Compile Include="KeyPatternPool.cs" />
     106    <Compile Include="KeyPattern\KeyPattern.cs" />
     107    <Compile Include="KeyPattern\KeyPatternPool.cs" />
    108108    <Compile Include="KeySearcher.cs" />
    109     <Compile Include="KeySearcherQuickWatchPresentation.xaml.cs">
     109    <Compile Include="Presentation\KeySearcherQuickWatchPresentation.xaml.cs">
    110110      <DependentUpon>KeySearcherQuickWatchPresentation.xaml</DependentUpon>
    111111    </Compile>
     
    114114    <Compile Include="P2P\Exceptions\ReservationRemovedException.cs" />
    115115    <Compile Include="P2P\Exceptions\UpdateFailedException.cs" />
    116     <Compile Include="P2P\KeyPoolTree.cs" />
    117     <Compile Include="P2P\Nodes\Leaf.cs" />
    118     <Compile Include="P2P\Nodes\Node.cs" />
    119     <Compile Include="P2P\Nodes\NodeBase.cs" />
    120     <Compile Include="P2P\Nodes\NodeFactory.cs" />
    121     <Compile Include="P2P\Nodes\P2PHelper.cs" />
    122     <Compile Include="P2P\P2PBruteForce.cs" />
     116    <Compile Include="P2P\Storage\StorageKeyGenerator.cs" />
     117    <Compile Include="P2P\Tree\KeyPoolTree.cs" />
     118    <Compile Include="P2P\Tree\Leaf.cs" />
     119    <Compile Include="P2P\Tree\Node.cs" />
     120    <Compile Include="P2P\Tree\NodeBase.cs" />
     121    <Compile Include="P2P\Tree\NodeFactory.cs" />
     122    <Compile Include="P2P\Storage\StorageHelper.cs" />
     123    <Compile Include="P2P\DistributedBruteForceManager.cs" />
    123124    <Compile Include="Properties\AssemblyInfo.cs" />
    124     <Compile Include="Wildcard.cs" />
     125    <Compile Include="KeyPattern\Wildcard.cs" />
    125126  </ItemGroup>
    126127  <ItemGroup>
     
    146147      <SubType>Designer</SubType>
    147148    </Resource>
    148     <Page Include="KeySearcherQuickWatchPresentation.xaml">
     149    <Page Include="Presentation\KeySearcherQuickWatchPresentation.xaml">
    149150      <SubType>Designer</SubType>
    150151      <Generator>MSBuild:Compile</Generator>
  • trunk/CrypPlugins/KeySearcher/KeySearcherSettings.cs

    r1643 r1674  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    42using System.Numerics;
    5 using System.Text;
    63using Cryptool.PluginBase;
    74using System.ComponentModel;
    85using System.Collections.ObjectModel;
     6using KeySearcher.KeyPattern;
    97
    108namespace KeySearcher
     
    1210    public class KeySearcherSettings : ISettings
    1311    {
    14         private KeySearcher keysearcher;
     12        private readonly KeySearcher keysearcher;
    1513        private int coresUsed;
    1614        private const string GroupPeerToPeer = "Peer-to-Peer network";
     
    2422            CoresUsed = Environment.ProcessorCount - 1;
    2523
    26             distributedJobIdentifier = Guid.NewGuid().ToString();
    2724            chunkSize = 21;
    2825        }
     
    10299        }
    103100
    104         private string distributedJobIdentifier;
    105         [TaskPane("Job identifier", "Arbitrary description, that allows other peers to join this calculation.", GroupPeerToPeer, 2, false, DisplayLevel.Professional,
    106             ControlType.TextBox)]
    107         public string DistributedJobIdentifier
    108         {
    109             get { return distributedJobIdentifier; }
    110             set
    111             {
    112                 if (value != distributedJobIdentifier)
    113                 {
    114                     distributedJobIdentifier = value;
    115                     OnPropertyChanged("DistributedJobIdentifier");
    116                     HasChanges = true;
    117                 }
    118             }
    119         }
    120 
    121101        private int chunkSize;
    122102        [TaskPane("Chunk size", "Amount of keys, that will be calculated by one peer at a time. This value is the exponent of the power of two used for the chunk size.", GroupPeerToPeer, 3, false, DisplayLevel.Professional,
     
    147127                }
    148128
    149                 var keyPattern = new KeyPattern(keysearcher.ControlMaster.getKeyPattern());
     129                var keyPattern = new KeyPattern.KeyPattern(keysearcher.ControlMaster.getKeyPattern());
    150130                keyPattern.WildcardKey = key;
    151131                var keyPatternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, ChunkSize)));
  • trunk/CrypPlugins/KeySearcher/P2P/DistributedBruteForceManager.cs

    r1673 r1674  
    11using System;
     2using System.Collections.Generic;
    23using System.Numerics;
    34using Cryptool.PluginBase;
    45using KeySearcher.Helper;
     6using KeySearcher.KeyPattern;
    57using KeySearcher.P2P.Exceptions;
    6 using KeySearcher.P2P.Nodes;
     8using KeySearcher.P2P.Storage;
     9using KeySearcher.P2P.Tree;
    710
    811namespace KeySearcher.P2P
    912{
    10     class P2PBruteForce
     13    internal class DistributedBruteForceManager
    1114    {
    12         private readonly KeySearcher _keySearcher;
    13         private readonly KeySearcherSettings _settings;
    14         private readonly KeyPatternPool _patternPool;
    15         private readonly KeyPoolTree _keyPoolTree;
     15        private readonly StorageKeyGenerator keyGenerator;
     16        private readonly KeyPoolTree keyPoolTree;
     17        private readonly KeySearcher keySearcher;
     18        private readonly KeyPatternPool patternPool;
    1619
    17         public P2PBruteForce(KeySearcher keySearcher, KeyPattern keyPattern, KeySearcherSettings settings, KeyQualityHelper keyQualityHelper)
     20        public DistributedBruteForceManager(KeySearcher keySearcher, KeyPattern.KeyPattern keyPattern, KeySearcherSettings settings,
     21                                            KeyQualityHelper keyQualityHelper)
    1822        {
    19             _keySearcher = keySearcher;
    20             _settings = settings;
     23            this.keySearcher = keySearcher;
    2124
    2225            // TODO when setting is still default (21), it is only displayed as 21 - but the settings-instance contains 0 for that key!
     
    2629            }
    2730
    28             _patternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, settings.ChunkSize)));
    29             _keyPoolTree = new KeyPoolTree(_patternPool, _settings, _keySearcher, keyQualityHelper);
     31            keyGenerator = new StorageKeyGenerator(keySearcher, settings);
     32            patternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, settings.ChunkSize)));
     33            keyPoolTree = new KeyPoolTree(patternPool, this.keySearcher, keyQualityHelper, keyGenerator);
    3034
    31             _keySearcher.GuiLogMessage(
    32                 "Total amount of patterns: " + _patternPool.Length + ", each containing " + _patternPool.PartSize +
     35            keySearcher.GuiLogMessage(
     36                "Total amount of patterns: " + patternPool.Length + ", each containing " + patternPool.PartSize +
    3337                " keys.", NotificationLevel.Info);
     38        }
    3439
     40        public void Execute()
     41        {
    3542            Leaf currentLeaf;
    36             while (!_keySearcher.stop)
     43            while (!keySearcher.stop)
    3744            {
    3845                try
    3946                {
    40                     currentLeaf = _keyPoolTree.FindNextLeaf();
     47                    currentLeaf = keyPoolTree.FindNextLeaf();
    4148                    if (currentLeaf == null)
    4249                    {
    4350                        break;
    4451                    }
    45                 } catch(AlreadyCalculatedException)
     52                }
     53                catch (AlreadyCalculatedException)
    4654                {
    47                     _keySearcher.GuiLogMessage("Node was already calculated.", NotificationLevel.Warning);
    48                     _keyPoolTree.Reset();
     55                    keySearcher.GuiLogMessage("Node was already calculated.", NotificationLevel.Warning);
     56                    keyPoolTree.Reset();
    4957                    continue;
    5058                }
     
    5260                if (!currentLeaf.ReserveLeaf())
    5361                {
    54                     _keySearcher.GuiLogMessage(
     62                    keySearcher.GuiLogMessage(
    5563                        "Pattern #" + currentLeaf.PatternId() +
    5664                        " was reserved before it could be reserved for this CrypTool instance.",
    5765                        NotificationLevel.Warning);
    58                     _keyPoolTree.Reset();
     66                    keyPoolTree.Reset();
    5967                    continue;
    6068                }
    6169
    62                 _keySearcher.GuiLogMessage(
    63                     "Running pattern #" + (currentLeaf.PatternId() + 1) + " of " + _patternPool.Length,
     70                keySearcher.GuiLogMessage(
     71                    "Running pattern #" + (currentLeaf.PatternId() + 1) + " of " + patternPool.Length,
    6472                    NotificationLevel.Info);
    6573
    6674                try
    6775                {
    68                     var result = _keySearcher.BruteForceWithLocalSystem(_patternPool[currentLeaf.PatternId()]);
     76                    LinkedList<KeySearcher.ValueKey> result =
     77                        keySearcher.BruteForceWithLocalSystem(patternPool[currentLeaf.PatternId()]);
    6978
    70                     if (!_keySearcher.stop)
    71                     {
    72                         _keyPoolTree.ProcessCurrentPatternCalculationResult(currentLeaf, result);
    73                     }
     79                    if (!keySearcher.stop)
     80                        KeyPoolTree.ProcessCurrentPatternCalculationResult(currentLeaf, result);
    7481                    else
    75                     {
    76                         _keySearcher.GuiLogMessage("Brute force was stopped, not saving results...", NotificationLevel.Info);
    77                     }
     82                        keySearcher.GuiLogMessage("Brute force was stopped, not saving results...",
     83                                                  NotificationLevel.Info);
    7884
    79                     _keySearcher.GuiLogMessage(
     85                    keySearcher.GuiLogMessage(
    8086                        string.Format("Best match: {0} with {1}", result.First.Value.key, result.First.Value.value),
    81                         NotificationLevel.Info);               
     87                        NotificationLevel.Info);
    8288                }
    83                 catch(ReservationRemovedException)
     89                catch (ReservationRemovedException)
    8490                {
    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);
    88                     _keyPoolTree.Reset();
     91                    keySearcher.GuiLogMessage("Reservation removed by another node (while calculating). " +
     92                                              "To avoid a state in limbo, proceeding to first available leaf...",
     93                                              NotificationLevel.Warning);
     94                    keyPoolTree.Reset();
    8995                    continue;
    9096                }
    9197                catch (UpdateFailedException e)
    9298                {
    93                     _keySearcher.GuiLogMessage("Could not store results: " + e.Message, NotificationLevel.Warning);
    94                     _keyPoolTree.Reset();
     99                    keySearcher.GuiLogMessage("Could not store results: " + e.Message, NotificationLevel.Warning);
     100                    keyPoolTree.Reset();
    95101                    continue;
    96102                }
     
    98104
    99105            // Set progress to 100%
    100             if (!_keySearcher.stop && _keyPoolTree.IsCalculationFinished())
     106            if (!keySearcher.stop && keyPoolTree.IsCalculationFinished())
    101107            {
    102                 _keySearcher.showProgress(_keySearcher.costList, 1, 1, 1);
    103                 _keySearcher.GuiLogMessage("Calculation complete.", NotificationLevel.Info);
     108                keySearcher.showProgress(keySearcher.costList, 1, 1, 1);
     109                keySearcher.GuiLogMessage("Calculation complete.", NotificationLevel.Info);
    104110            }
    105111        }
  • trunk/CrypPlugins/KeySearcher/P2P/Exceptions/AlreadyCalculatedException.cs

    r1665 r1674  
    33namespace KeySearcher.P2P.Exceptions
    44{
     5    /// <summary>
     6    /// Represents errors that occur, when node states of the KeyPoolTree
     7    /// change during the process of finding the next leaf.
     8    /// If that happens, this exception is thrown in order to
     9    /// reinitialize the tree.
     10    /// </summary>
    511    public class AlreadyCalculatedException : Exception
    612    {
  • trunk/CrypPlugins/KeySearcher/P2P/Exceptions/ReservationRemovedException.cs

    r1665 r1674  
    33namespace KeySearcher.P2P.Exceptions
    44{
     5    /// <summary>
     6    /// Represents a reservation error that can occur,
     7    /// if the instance of this CrypTool reserved a leaf, but
     8    /// needs more time than the timeout to calculate the result
     9    /// of the leaf. Another node claims the reserved leaf, finishes it
     10    /// and removes it from the distributted storage before this
     11    /// instance is finished.
     12    /// </summary>
    513    public class ReservationRemovedException : Exception
    614    {
    7         public ReservationRemovedException(string msg) : base(msg) {}
     15        public ReservationRemovedException(string msg) : base(msg)
     16        {
     17        }
    818    }
    919}
  • trunk/CrypPlugins/KeySearcher/P2P/Exceptions/UpdateFailedException.cs

    r1665 r1674  
    33namespace KeySearcher.P2P.Exceptions
    44{
    5     class UpdateFailedException : Exception
     5    /// <summary>
     6    /// Represents errors, that occur when this instance is
     7    /// unable to update the stored data of a key.
     8    /// </summary>
     9    internal class UpdateFailedException : Exception
    610    {
    7         public UpdateFailedException(string msg) : base(msg) {}
     11        public UpdateFailedException(string msg) : base(msg)
     12        {
     13        }
    814    }
    915}
  • trunk/CrypPlugins/KeySearcher/P2P/Storage/StorageHelper.cs

    r1673 r1674  
    33using Cryptool.P2P;
    44using Cryptool.P2P.Internal;
     5using KeySearcher.P2P.Tree;
    56
    6 namespace KeySearcher.P2P.Nodes
     7namespace KeySearcher.P2P.Storage
    78{
    8     class P2PHelper
     9    class StorageHelper
    910    {
    10         private readonly KeySearcher _keySearcher;
     11        private readonly KeySearcher keySearcher;
    1112
    12         public P2PHelper(KeySearcher keySearcher)
     13        public StorageHelper(KeySearcher keySearcher)
    1314        {
    14             _keySearcher = keySearcher;
     15            this.keySearcher = keySearcher;
    1516        }
    1617
     
    6465            var requestResult = P2PManager.Retrieve(KeyInDht(nodeToUpdate));
    6566            var nodeBytes = requestResult.Data;
    66             nodeToUpdate.LastUpdateResult = requestResult.Status;
    6767
    6868            if (nodeBytes == null)
     
    9696            if (resultCount > 0)
    9797            {
    98                 _keySearcher.IntegrateNewResults(nodeToUpdate.Result);
     98                keySearcher.IntegrateNewResults(nodeToUpdate.Result);
    9999            }
    100100
     
    119119        internal static string KeyInDht(NodeBase node)
    120120        {
    121             return string.Format("p2pjob_{0}_node_{1}_{2}", node.DistributedJobIdentifier, node.From, node.To);
     121            return string.Format("{0}_node_{1}_{2}", node.DistributedJobIdentifier, node.From, node.To);
    122122        }
    123123    }
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/KeyPoolTree.cs

    r1673 r1674  
    22using Cryptool.PluginBase;
    33using KeySearcher.Helper;
    4 using KeySearcher.P2P.Nodes;
     4using KeySearcher.KeyPattern;
     5using KeySearcher.P2P.Storage;
    56
    6 namespace KeySearcher.P2P
     7namespace KeySearcher.P2P.Tree
    78{
    8     class KeyPoolTree
     9    internal class KeyPoolTree
    910    {
    10         private readonly KeyPatternPool _patternPool;
    11         private readonly KeySearcherSettings _settings;
    12         private readonly KeySearcher _keySearcher;
    13         private readonly P2PHelper _p2PHelper;
    14         private readonly NodeBase _rootNode;
    15         private NodeBase _currentNode;
    16         private bool _skippedReservedNodes;
     11        private readonly KeySearcher keySearcher;
     12        private readonly KeyPatternPool patternPool;
     13        private readonly NodeBase rootNode;
     14        private readonly StorageHelper storageHelper;
     15        private NodeBase currentNode;
     16        private bool skippedReservedNodes;
    1717
    18         public KeyPoolTree(KeyPatternPool patternPool, KeySearcherSettings settings, KeySearcher keySearcher, KeyQualityHelper keyQualityHelper)
     18        public KeyPoolTree(KeyPatternPool patternPool, KeySearcher keySearcher, KeyQualityHelper keyQualityHelper,
     19                           StorageKeyGenerator identifierGenerator)
    1920        {
    20             _patternPool = patternPool;
    21             _settings = settings;
    22             _keySearcher = keySearcher;
     21            this.patternPool = patternPool;
     22            this.keySearcher = keySearcher;
    2323
    24             _p2PHelper = new P2PHelper(keySearcher);
    25             _skippedReservedNodes = false;
     24            storageHelper = new StorageHelper(keySearcher);
     25            skippedReservedNodes = false;
    2626
    27             _rootNode = NodeFactory.CreateNode(_p2PHelper, keyQualityHelper, null, 0, _patternPool.Length - 1, _settings.DistributedJobIdentifier);
    28             _currentNode = _rootNode;
     27            rootNode = NodeFactory.CreateNode(storageHelper, keyQualityHelper, null, 0, this.patternPool.Length - 1,
     28                                              identifierGenerator.Generate());
     29            currentNode = rootNode;
    2930        }
    3031
    3132        public Leaf FindNextLeaf()
    3233        {
    33             var nodeBeforeStarting = _currentNode;
     34            var nodeBeforeStarting = currentNode;
    3435            var foundNode = FindNextLeaf(false);
    3536
    36             if (foundNode == null && _skippedReservedNodes)
     37            if (foundNode == null && skippedReservedNodes)
    3738            {
    38                 _keySearcher.GuiLogMessage("Searching again with reserved nodes enabled...", NotificationLevel.Warning);
     39                keySearcher.GuiLogMessage("Searching again with reserved nodes enabled...", NotificationLevel.Warning);
    3940
    40                 _currentNode = nodeBeforeStarting;
     41                currentNode = nodeBeforeStarting;
    4142                foundNode = FindNextLeaf(true);
    42                 _currentNode = foundNode;
     43                currentNode = foundNode;
    4344                return foundNode;
    4445            }
    4546
    46             _currentNode = foundNode;
     47            currentNode = foundNode;
    4748            return foundNode;
    4849        }
     
    5051        private Leaf FindNextLeaf(bool useReservedLeafs)
    5152        {
    52             if (_currentNode == null)
     53            if (currentNode == null)
    5354            {
    5455                return null;
    5556            }
    5657
    57             var isReserved = false;
    58             _p2PHelper.UpdateFromDht(_currentNode, true);
    59             while (_currentNode.IsCalculated() || ((isReserved = _currentNode.IsReserverd()) && !useReservedLeafs))
     58            bool isReserved = false;
     59            storageHelper.UpdateFromDht(currentNode, true);
     60            while (currentNode.IsCalculated() || ((isReserved = currentNode.IsReserverd()) && !useReservedLeafs))
    6061            {
    6162                if (isReserved)
    62                     _skippedReservedNodes = true;
     63                    skippedReservedNodes = true;
    6364
    6465                // Current node is calculated or reserved,
    6566                // move one node up and update it
    66                 _currentNode = _currentNode.ParentNode;
     67                currentNode = currentNode.ParentNode;
    6768
    6869                // Root node calculated => everything finished
    69                 if (_currentNode == null)
     70                if (currentNode == null)
    7071                {
    71                     _currentNode = _rootNode;
     72                    currentNode = rootNode;
    7273                    return null;
    7374                }
    7475
    7576                // Update the new _currentNode
    76                 _p2PHelper.UpdateFromDht(_currentNode, true);
     77                storageHelper.UpdateFromDht(currentNode, true);
    7778            }
    7879
    7980            // currentNode is calculateable => find leaf
    80             return _currentNode.CalculatableLeaf(useReservedLeafs);
     81            return currentNode.CalculatableLeaf(useReservedLeafs);
    8182        }
    8283
     
    8485        internal bool IsCalculationFinished()
    8586        {
    86             _p2PHelper.UpdateFromDht(_rootNode, true);
    87             return _rootNode.IsCalculated();
     87            storageHelper.UpdateFromDht(rootNode, true);
     88            return rootNode.IsCalculated();
    8889        }
    8990
    9091        internal void Reset()
    9192        {
    92             _rootNode.Reset();
    93             _currentNode = _rootNode;
    94             _skippedReservedNodes = false;
     93            rootNode.Reset();
     94            currentNode = rootNode;
     95            skippedReservedNodes = false;
    9596        }
    9697
    97         public void ProcessCurrentPatternCalculationResult(Leaf currentLeaf, LinkedList<KeySearcher.ValueKey> result)
     98        public static void ProcessCurrentPatternCalculationResult(Leaf currentLeaf,
     99                                                                  LinkedList<KeySearcher.ValueKey> result)
    98100        {
    99101            currentLeaf.HandleResults(result);
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/Leaf.cs

    r1673 r1674  
    44using KeySearcher.Helper;
    55using KeySearcher.P2P.Exceptions;
     6using KeySearcher.P2P.Storage;
    67
    7 namespace KeySearcher.P2P.Nodes
     8namespace KeySearcher.P2P.Tree
    89{
    910    class Leaf : NodeBase
     
    1112        internal DateTime LastReservationDate;
    1213
    13         public Leaf(P2PHelper p2PHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger id, string distributedJobIdentifier)
    14             : base(p2PHelper, keyQualityHelper, parentNode, id, id, distributedJobIdentifier)
     14        public Leaf(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger id, string distributedJobIdentifier)
     15            : base(storageHelper, keyQualityHelper, parentNode, id, id, distributedJobIdentifier)
    1516        {
    1617        }
     
    4950        {
    5051            LastReservationDate = DateTime.UtcNow;
    51             return P2PHelper.UpdateInDht(this).IsSuccessful();
     52            return StorageHelper.UpdateInDht(this).IsSuccessful();
    5253        }
    5354
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/Node.cs

    r1673 r1674  
    22using KeySearcher.Helper;
    33using KeySearcher.P2P.Exceptions;
     4using KeySearcher.P2P.Storage;
    45
    5 namespace KeySearcher.P2P.Nodes
     6namespace KeySearcher.P2P.Tree
    67{
    78    class Node : NodeBase
     
    1011        internal bool RightChildFinished;
    1112
    12         private NodeBase _leftChild;
    13         private NodeBase _rightChild;
     13        private NodeBase leftChild;
     14        private NodeBase rightChild;
    1415
    15         public Node(P2PHelper p2PHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger @from, BigInteger to, string distributedJobIdentifier)
    16             : base(p2PHelper, keyQualityHelper, parentNode, @from, to, distributedJobIdentifier)
     16        public Node(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger @from, BigInteger to, string distributedJobIdentifier)
     17            : base(storageHelper, keyQualityHelper, parentNode, @from, to, distributedJobIdentifier)
    1718        {
    1819        }
     
    2425            if (!LeftChildFinished)
    2526            {
    26                 if (_leftChild == null)
     27                if (leftChild == null)
    2728                {
    28                     _leftChild = NodeFactory.CreateNode(P2PHelper, KeyQualityHelper, this, From, middle,
     29                    leftChild = NodeFactory.CreateNode(StorageHelper, KeyQualityHelper, this, From, middle,
    2930                                                        DistributedJobIdentifier);
    3031                }
    3132                else
    3233                {
    33                     P2PHelper.UpdateFromDht(_leftChild);
     34                    StorageHelper.UpdateFromDht(leftChild);
    3435                }
    3536            }
    3637
    3738            // Only load right node, if the left one is finished or reserved
    38             if ((LeftChildFinished || _leftChild.IsReserverd()) && !RightChildFinished)
     39            if ((LeftChildFinished || leftChild.IsReserverd()) && !RightChildFinished)
    3940            {
    40                 if (_rightChild == null)
     41                if (rightChild == null)
    4142                {
    42                     _rightChild = NodeFactory.CreateNode(P2PHelper, KeyQualityHelper, this, middle + 1, To,
     43                    rightChild = NodeFactory.CreateNode(StorageHelper, KeyQualityHelper, this, middle + 1, To,
    4344                                                         DistributedJobIdentifier);
    4445                }
    4546                else
    4647                {
    47                     P2PHelper.UpdateFromDht(_rightChild);
     48                    StorageHelper.UpdateFromDht(rightChild);
    4849                }
    4950            }
     
    5758        public override void Reset()
    5859        {
    59             _leftChild = null;
    60             _rightChild = null;
    61             LeftChildFinished = false;
    62             RightChildFinished = false;
     60            leftChild = null;
     61            rightChild = null;
    6362        }
    6463
     
    6867
    6968            // Left child not finished and not reserved (or reserved leafs are allowed)
    70             if (!LeftChildFinished && (!_leftChild.IsReserverd() || useReservedNodes))
     69            if (!LeftChildFinished && (!leftChild.IsReserverd() || useReservedNodes))
    7170            {
    72                 return _leftChild.CalculatableLeaf(useReservedNodes);
     71                return leftChild.CalculatableLeaf(useReservedNodes);
    7372            }
    7473
    75             if (_rightChild == null)
     74            if (rightChild == null)
    7675            {
    7776                throw new AlreadyCalculatedException();
    7877            }
    7978
    80             return _rightChild.CalculatableLeaf(useReservedNodes);
     79            return rightChild.CalculatableLeaf(useReservedNodes);
    8180        }
    8281
    8382        public void ChildFinished(NodeBase childNode)
    8483        {
    85             if (childNode == _leftChild)
     84            if (childNode == leftChild)
    8685            {
    8786                LeftChildFinished = true;
    88                 _leftChild = null;
     87                leftChild = null;
    8988                return;
    9089            }
    9190
    92             if (childNode == _rightChild)
     91            if (childNode == rightChild)
    9392            {
    9493                RightChildFinished = true;
    95                 _rightChild = null;
     94                rightChild = null;
    9695                return;
    9796            }
     
    102101            LoadOrUpdateChildNodes();
    103102
    104             var leftChildFinishedOrReserved = LeftChildFinished || _leftChild.IsReserverd();
     103            var leftChildFinishedOrReserved = LeftChildFinished || leftChild.IsReserverd();
    105104
    106105            if (leftChildFinishedOrReserved && !RightChildFinished)
    107106            {
    108                 return _rightChild.IsReserverd();
     107                return rightChild.IsReserverd();
    109108            }
    110109
    111             return !LeftChildFinished && _leftChild.IsReserverd();
     110            return !LeftChildFinished && leftChild.IsReserverd();
    112111        }
    113112
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/NodeBase.cs

    r1673 r1674  
    66using KeySearcher.Helper;
    77using KeySearcher.P2P.Exceptions;
     8using KeySearcher.P2P.Storage;
    89
    9 namespace KeySearcher.P2P.Nodes
     10namespace KeySearcher.P2P.Tree
    1011{
    1112    abstract class NodeBase
     
    1415        protected internal readonly BigInteger To;
    1516        protected internal readonly string DistributedJobIdentifier;
    16         protected readonly P2PHelper P2PHelper;
     17        protected readonly StorageHelper StorageHelper;
    1718        protected readonly KeyQualityHelper KeyQualityHelper;
    1819
    1920        protected internal DateTime LastUpdate;
    20         protected internal RequestResultType LastUpdateResult;
    2121
    2222        public readonly Node ParentNode;
    2323        public LinkedList<KeySearcher.ValueKey> Result;
    2424
    25         protected NodeBase(P2PHelper p2PHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger @from, BigInteger to, string distributedJobIdentifier)
     25        protected NodeBase(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger @from, BigInteger to, string distributedJobIdentifier)
    2626        {
    27             P2PHelper = p2PHelper;
     27            StorageHelper = storageHelper;
    2828            KeyQualityHelper = keyQualityHelper;
    2929            ParentNode = parentNode;
     
    3535            Result = new LinkedList<KeySearcher.ValueKey>();
    3636
    37             P2PHelper.UpdateFromDht(this);
     37            StorageHelper.UpdateFromDht(this);
    3838        }
    3939
     
    4848
    4949            // Compare with refreshed parent node
    50             var result = P2PHelper.UpdateFromDht(ParentNode, true);
     50            var result = StorageHelper.UpdateFromDht(ParentNode, true);
    5151            if (!result.IsSuccessful())
    5252            {
     
    5757            ParentNode.ChildFinished(this);
    5858
    59             if (P2PManager.Retrieve(P2PHelper.KeyInDht(this)).Status == RequestResultType.KeyNotFound)
     59            if (P2PManager.Retrieve(StorageHelper.KeyInDht(this)).Status == RequestResultType.KeyNotFound)
    6060            {
    6161                throw new ReservationRemovedException("Before updating parent node, this leaf's reservation was deleted.");
    6262            }
    6363
    64             var updateResult = P2PHelper.UpdateInDht(ParentNode);
     64            var updateResult = StorageHelper.UpdateInDht(ParentNode);
    6565            if (!updateResult.IsSuccessful())
    6666            {
     
    6868            }
    6969
    70             P2PManager.Remove(P2PHelper.KeyInDht(this));
     70            P2PManager.Remove(StorageHelper.KeyInDht(this));
    7171
    7272            if (ParentNode.IsCalculated())
     
    108108        private void UpdateDhtForRootNode()
    109109        {
    110             P2PHelper.UpdateFromDht(this, true);
    111             P2PHelper.UpdateInDht(this);
     110            StorageHelper.UpdateFromDht(this, true);
     111            StorageHelper.UpdateInDht(this);
    112112        }
    113113
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/NodeFactory.cs

    r1673 r1674  
    11using System.Numerics;
    22using KeySearcher.Helper;
     3using KeySearcher.P2P.Storage;
    34
    4 namespace KeySearcher.P2P.Nodes
     5namespace KeySearcher.P2P.Tree
    56{
    6     static class NodeFactory
     7    internal static class NodeFactory
    78    {
    8         public static NodeBase CreateNode(P2PHelper p2PHelper, KeyQualityHelper keyQualityHelper, Node parentNode, BigInteger from, BigInteger to, string distributedJobIdentifier)
     9        public static NodeBase CreateNode(StorageHelper storageHelper, KeyQualityHelper keyQualityHelper,
     10                                          Node parentNode, BigInteger from, BigInteger to,
     11                                          string distributedJobIdentifier)
    912        {
    1013            NodeBase newNode;
    11            
     14
    1215            if (from == to)
    1316            {
    14                 newNode = new Leaf(p2PHelper, keyQualityHelper, parentNode, from, distributedJobIdentifier);
    15             } else
     17                newNode = new Leaf(storageHelper, keyQualityHelper, parentNode, from, distributedJobIdentifier);
     18            }
     19            else
    1620            {
    17                 newNode = new Node(p2PHelper, keyQualityHelper, parentNode, from, to, distributedJobIdentifier);
     21                newNode = new Node(storageHelper, keyQualityHelper, parentNode, from, to, distributedJobIdentifier);
    1822            }
    1923
  • trunk/CrypPlugins/KeySearcher/Presentation/KeySearcherQuickWatchPresentation.xaml

    r1673 r1674  
    1 <UserControl x:Class="KeySearcher.KeySearcherQuickWatchPresentation"
     1<UserControl x:Class="KeySearcher.Presentation.KeySearcherQuickWatchPresentation"
    22    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    33    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  • trunk/CrypPlugins/KeySearcher/Presentation/KeySearcherQuickWatchPresentation.xaml.cs

    r1673 r1674  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Windows;
    62using System.Windows.Controls;
    7 using System.Windows.Data;
    8 using System.Windows.Documents;
    9 using System.Windows.Input;
    103using System.Windows.Media;
    11 using System.Windows.Media.Imaging;
    12 using System.Windows.Navigation;
    13 using System.Windows.Shapes;
    144using System.Collections.ObjectModel;
    155
    16 namespace KeySearcher
     6namespace KeySearcher.Presentation
    177{   
    18     /// <summary>
    19     /// Interaktionslogik für KeySearcherQuickWatchPresentation.xaml
    20     /// </summary>
    218    public partial class KeySearcherQuickWatchPresentation : UserControl
    229    {       
  • trunk/CrypPlugins/KeySearcher_IControl/IControlKeySearcher.cs

    r1090 r1674  
    55using Cryptool.PluginBase.Control;
    66// KeyPattern kicked out of this project and will be sourced from the namespace KeySearcher
    7 using KeySearcher;
     7using KeySearcher.KeyPattern;
    88using Cryptool.Plugins.KeySearcher_IControl;
    99
  • trunk/CrypPlugins/KeySearcher_IControl/KeySearcher_IControl.cs

    r1448 r1674  
    2626using Cryptool.PluginBase.Analysis;
    2727// KeyPattern kicked out of this project and will be sourced from the namespace KeySearcher
    28 using KeySearcher;
    2928using Cryptool.PluginBase.Control;
    3029using Cryptool.Plugins.PeerToPeer;
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManager_KeyPattern.cs

    r1448 r1674  
    2525using System.ComponentModel;
    2626using KeySearcher;
     27using KeySearcher.KeyPattern;
    2728using System.Windows.Controls;
    2829using System.Windows.Threading;
Note: See TracChangeset for help on using the changeset viewer.