source: trunk/CrypPlugins/KeySearcher/P2P/DistributedBruteForceManager.cs

Last change on this file was 8983, checked in by kopal, 7 months ago

Complete CrypTool 2 project

  • renamed "Cryptool" namespace to "CrypTool" namespace
File size: 3.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Numerics;
5using System.Threading;
6using System.Windows.Threading; 
7using CrypTool.PluginBase;
8using KeySearcher.Helper;
9using KeySearcher.KeyPattern;
10using KeySearcher.P2P.Exceptions;
11using KeySearcher.P2P.Helper;
12using KeySearcher.P2P.Presentation;
13using KeySearcher.P2P.Storage;
14using KeySearcher.P2P.Tree;
15using KeySearcher.Presentation;
16using KeySearcher.Presentation.Controls;
17using KeySearcherPresentation.Controls;
18using KeySearcher.Properties;
19using System.Timers;
20using Timer = System.Timers.Timer;
21
22namespace KeySearcher.P2P
23{
24    internal class DistributedBruteForceManager
25    {
26        private readonly StorageKeyGenerator keyGenerator;
27        private readonly KeySearcher keySearcher;
28        private readonly KeySearcherSettings settings;
29        private readonly KeyQualityHelper keyQualityHelper;
30        private readonly P2PQuickWatchPresentation quickWatch;
31        private readonly KeyPoolTreePresentation _keyPoolTreePresentation;
32        private readonly KeyPatternPool patternPool;
33        private readonly StatusContainer status;
34        internal readonly StatisticsGenerator StatisticsGenerator;
35        internal readonly Stopwatch StopWatch;
36
37        private KeyPoolTree keyPoolTree;
38        private AutoResetEvent systemJoinEvent = new AutoResetEvent(false);
39
40        public DistributedBruteForceManager(KeySearcher keySearcher, KeyPattern.KeyPattern keyPattern, KeySearcherSettings settings,
41                                            KeyQualityHelper keyQualityHelper, P2PQuickWatchPresentation quickWatch, KeyPoolTreePresentation keyPoolTreePresentation)
42        {
43            this.keySearcher = keySearcher;
44            this.settings = settings;
45            this.keyQualityHelper = keyQualityHelper;
46            this.quickWatch = quickWatch;
47            _keyPoolTreePresentation = keyPoolTreePresentation;
48
49            // TODO when setting is still default (21), it is only displayed as 21 - but the settings-instance contains 0 for that key!
50            if (settings.NumberOfBlocks == 0)
51            {
52                settings.NumberOfBlocks = 3;
53            }
54
55            StopWatch = new Stopwatch();
56            status = new StatusContainer(keySearcher);
57            status.IsCurrentProgressIndeterminate = true;
58
59            keyGenerator = new StorageKeyGenerator(keySearcher, settings);
60            patternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, settings.NumberOfBlocks)));
61            StatisticsGenerator = new StatisticsGenerator(status, quickWatch, keySearcher, settings, this);
62            quickWatch.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateStatusContainerInQuickWatch));
63
64            _keyPoolTreePresentation.PatternPool = patternPool;
65            _keyPoolTreePresentation.KeyQualityHelper = keyQualityHelper;
66            _keyPoolTreePresentation.KeyGenerator = keyGenerator;
67            _keyPoolTreePresentation.StatusContainer = status;
68        }
69
70        public void Execute()
71        {
72            status.CurrentOperation = Resources.Initializing_connection_to_the_peer_to_peer_system;
73            new ConnectionHelper(keySearcher, settings).ValidateConnectionToPeerToPeerSystem();
74        }
75
76
77        private void UpdateStatusContainerInQuickWatch()
78        {
79            quickWatch.DataContext = status;
80            quickWatch.UpdateSettings(keySearcher, settings);
81        }
82    }
83}
Note: See TracBrowser for help on using the repository browser.