Changeset 1682


Ignore:
Timestamp:
Jun 20, 2010, 10:27:22 PM (11 years ago)
Author:
Paul Lelgemann
Message:

o Work on the distributed KeySearcher presentation

Location:
trunk/CrypPlugins/KeySearcher
Files:
9 added
7 edited
4 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/Converter/FalseToVisibleConverter.cs

    r1677 r1682  
    44using System.Windows.Data;
    55
    6 namespace Cryptool.P2PEditor.Converters
     6namespace KeySearcherConverter
    77{
    88    [ValueConversion(typeof (bool), typeof (Visibility))]
    9     public class ConnectivityToVisibilityConverter : IValueConverter
     9    public class FalseToVisibleConverter : IValueConverter
    1010    {
    1111        #region IValueConverter Members
     
    1515        {
    1616            if (targetType != typeof (Visibility))
    17                 throw new InvalidOperationException("The target must be a Visibility");
     17                throw new InvalidOperationException("The target must be of Visibility");
    1818
    1919            if ((bool) value)
    2020            {
    2121                return Visibility.Hidden;
    22             } else
    23             {
    24                 return Visibility.Visible;
    2522            }
     23
     24            return Visibility.Visible;
    2625        }
    2726
  • trunk/CrypPlugins/KeySearcher/Converter/TimeSpanToRoundedStringConverter.cs

    r1677 r1682  
    11using System;
    22using System.Globalization;
    3 using System.Windows;
    43using System.Windows.Data;
    54
    6 namespace Cryptool.P2PEditor.Converters
     5namespace KeySearcherConverter
    76{
    8     [ValueConversion(typeof (bool), typeof (Visibility))]
    9     public class ConnectivityToVisibilityConverter : IValueConverter
     7    [ValueConversion(typeof (TimeSpan), typeof (string))]
     8    public class TimeSpanToRoundedStringConverter : IValueConverter
    109    {
    1110        #region IValueConverter Members
     
    1413                              CultureInfo culture)
    1514        {
    16             if (targetType != typeof (Visibility))
    17                 throw new InvalidOperationException("The target must be a Visibility");
     15            if (!(value is TimeSpan))
     16            {
     17                return "-";
     18            }
    1819
    19             if ((bool) value)
    20             {
    21                 return Visibility.Hidden;
    22             } else
    23             {
    24                 return Visibility.Visible;
    25             }
     20            var timeSpan = (TimeSpan) value;
     21            return String.Format("{0}:{1}:{2}.{3}",
     22                                 timeSpan.Hours,
     23                                 timeSpan.Minutes,
     24                                 timeSpan.Seconds,
     25                                 Math.Round((decimal) timeSpan.Milliseconds, 3));
     26
    2627        }
    2728
  • trunk/CrypPlugins/KeySearcher/Converter/TrueToVisibleConverter.cs

    r1677 r1682  
    44using System.Windows.Data;
    55
    6 namespace Cryptool.P2PEditor.Converters
     6namespace KeySearcherConverter
    77{
    88    [ValueConversion(typeof (bool), typeof (Visibility))]
    9     public class ConnectivityToVisibilityConverter : IValueConverter
     9    public class TrueToVisibleConverter : IValueConverter
    1010    {
    1111        #region IValueConverter Members
     
    1515        {
    1616            if (targetType != typeof (Visibility))
    17                 throw new InvalidOperationException("The target must be a Visibility");
     17                throw new InvalidOperationException("The target must be of Visibility");
    1818
    1919            if ((bool) value)
    2020            {
    21                 return Visibility.Hidden;
    22             } else
    23             {
    2421                return Visibility.Visible;
    2522            }
     23
     24            return Visibility.Hidden;
    2625        }
    2726
  • trunk/CrypPlugins/KeySearcher/Converter/TrueToVisibleOrCollapsedConverter.cs

    r1677 r1682  
    44using System.Windows.Data;
    55
    6 namespace Cryptool.P2PEditor.Converters
     6namespace KeySearcherConverter
    77{
    88    [ValueConversion(typeof (bool), typeof (Visibility))]
    9     public class ConnectivityToVisibilityConverter : IValueConverter
     9    public class TrueToVisibleOrCollapsedConverter : IValueConverter
    1010    {
    1111        #region IValueConverter Members
     
    1515        {
    1616            if (targetType != typeof (Visibility))
    17                 throw new InvalidOperationException("The target must be a Visibility");
     17                throw new InvalidOperationException("The target must be of Visibility");
    1818
    1919            if ((bool) value)
    2020            {
    21                 return Visibility.Hidden;
    22             } else
    23             {
    2421                return Visibility.Visible;
    2522            }
     23
     24            return Visibility.Collapsed;
    2625        }
    2726
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1674 r1682  
    1616using KeySearcher.Helper;
    1717using KeySearcher.P2P;
    18 using KeySearcher.Presentation;
     18using KeySearcherPresentation;
     19using KeySearcherPresentation.Controls;
    1920
    2021namespace KeySearcher
     
    3536        private Mutex maxThreadMutex = new Mutex();
    3637
    37         private KeyQualityHelper _keyQualityHelper;
     38        private KeyQualityHelper keyQualityHelper;
     39        private P2PQuickWatchPresentation p2PQuickWatchPresentation;
     40        private LocalQuickWatchPresentation localQuickWatchPresentation;
    3841
    3942        private KeyPattern.KeyPattern pattern = null;
     
    9497            {
    9598                costMaster = value;
    96                 _keyQualityHelper = new KeyQualityHelper(costMaster);
     99                keyQualityHelper = new KeyQualityHelper(costMaster);
    97100            }
    98101        }
     
    204207
    205208        private KeySearcherSettings settings;
    206         private AutoResetEvent _connectResetEvent;
     209        private AutoResetEvent connectResetEvent;
    207210
    208211        public KeySearcher()
    209212        {
    210213            settings = new KeySearcherSettings(this);
    211             QuickWatchPresentation = new KeySearcherQuickWatchPresentation();
     214            QuickWatchPresentation = new QuickWatch();
     215            localQuickWatchPresentation = ((QuickWatch) QuickWatchPresentation).LocalQuickWatchPresentation;
     216            p2PQuickWatchPresentation = ((QuickWatch)QuickWatchPresentation).P2PQuickWatchPresentation;
     217            p2PQuickWatchPresentation.UpdateSettings(this, settings);
     218
     219            settings.PropertyChanged += SettingsPropertyChanged;
     220        }
     221
     222        void SettingsPropertyChanged(object sender, PropertyChangedEventArgs e)
     223        {
     224            p2PQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
     225                                                             new Action(UpdateIsP2PEnabledSetting));
     226        }
     227
     228        void UpdateIsP2PEnabledSetting()
     229        {
     230            ((QuickWatch)QuickWatchPresentation).IsP2PEnabled = settings.UsePeerToPeer;
     231            p2PQuickWatchPresentation.UpdateSettings(this, settings);
    212232        }
    213233
     
    283303
    284304        #endregion
    285 
    286         /* BEGIN functionality */
    287305
    288306        #region whole KeySearcher functionality
     
    547565        private IControlEncryption sender;
    548566        private DateTime beginBruteforcing;
     567        private DistributedBruteForceManager distributedBruteForceManager;
    549568
    550569        // modified by Christian Arnold 2009.12.07 - return type LinkedList (top10List)
     
    570589            }
    571590
    572             bytesToUse = 0;
     591            // bytesToUse = 0;
    573592
    574593            try
     
    591610        }
    592611
    593         private Dispatcher _dispatcher;
    594 
    595612        private void BruteForceWithPeerToPeerSystem()
    596613        {
    597             _dispatcher = Dispatcher.CurrentDispatcher;
    598614            GuiLogMessage("Launching p2p based bruteforce logic...", NotificationLevel.Info);
    599615            ValidateConnectionToPeerToPeerSystem();
    600             var bruteForceManager = new DistributedBruteForceManager(this, pattern, settings, _keyQualityHelper);
    601             bruteForceManager.Execute();
     616            distributedBruteForceManager = new DistributedBruteForceManager(this, pattern, settings, keyQualityHelper,
     617                                                                     p2PQuickWatchPresentation);
     618            distributedBruteForceManager.Execute();
    602619        }
    603620
     
    625642        {
    626643            P2PManager.ConnectionManager.OnP2PConnectionStateChangeOccurred += HandleConnectionStateChange;
    627             _connectResetEvent = new AutoResetEvent(false);
     644            connectResetEvent = new AutoResetEvent(false);
    628645
    629646            P2PManager.Connect();
    630647
    631             _connectResetEvent.WaitOne();
     648            connectResetEvent.WaitOne();
    632649
    633650            if (P2PManager.IsConnected)
     
    645662        void HandleConnectionStateChange(object sender, bool newState)
    646663        {
    647             _connectResetEvent.Set();
     664            connectResetEvent.Set();
    648665        }
    649666
    650667        #endregion
    651668
    652         internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern.KeyPattern pattern)
     669        internal LinkedList<ValueKey> BruteForceWithLocalSystem(KeyPattern.KeyPattern pattern, bool redirectResultsToStatisticsGenerator = false)
    653670        {
    654671            BigInteger size = pattern.size();
     
    703720                #endregion
    704721
    705                 showProgress(costList, size, keycounter, doneKeys);
     722                if (redirectResultsToStatisticsGenerator)
     723                {
     724                    distributedBruteForceManager.StatisticsGenerator.ShowProgress(costList, size, keycounter, doneKeys);
     725                }
     726                else
     727                {
     728                    showProgress(costList, size, keycounter, doneKeys);
     729                }
     730               
    706731
    707732                #region set doneKeys to 0
     
    719744                ((ThreadStackElement)threadStack.Pop()).ev.Set();
    720745
    721             if (!stop)
     746            if (!stop && !redirectResultsToStatisticsGenerator)
    722747                ProgressChanged(1, 1);
    723748
     
    758783            ProgressChanged((double)keycounter / (double) size, 1.0);
    759784
    760             if (QuickWatchPresentation.IsVisible && doneKeys != 0 && !stop)
     785            if (localQuickWatchPresentation.IsVisible && doneKeys != 0 && !stop)
    761786            {
    762787                double time = (Math.Pow(10, BigInteger.Log((size - keycounter), 10) - BigInteger.Log(doneKeys, 10)));
     
    783808                }
    784809
    785                 ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    786                 {
    787                     ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).keysPerSecond.Text = "" + doneKeys;
     810                localQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     811                {
     812                    localQuickWatchPresentation.keysPerSecond.Text = "" + doneKeys;
    788813                    if (timeleft != new TimeSpan(-1))
    789814                    {
    790                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).timeLeft.Text = "" + timeleft;
     815                        localQuickWatchPresentation.timeLeft.Text = "" + timeleft;
    791816                        try
    792817                        {
    793                             ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).endTime.Text = "" + DateTime.Now.Add(timeleft);
     818                            localQuickWatchPresentation.endTime.Text = "" + DateTime.Now.Add(timeleft);
    794819                        }
    795820                        catch
    796821                        {
    797                             ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).endTime.Text = "in a galaxy far, far away...";
     822                            localQuickWatchPresentation.endTime.Text = "in a galaxy far, far away...";
    798823                        }
    799824                    }
    800825                    else
    801826                    {
    802                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).timeLeft.Text = "incalculable :-)";
    803                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).endTime.Text = "in a galaxy far, far away...";
     827                        localQuickWatchPresentation.timeLeft.Text = "incalculable :-)";
     828                        localQuickWatchPresentation.endTime.Text = "in a galaxy far, far away...";
    804829                    }
    805830
    806                     ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Clear();
     831                    localQuickWatchPresentation.entries.Clear();
    807832                    linkedListNode = costList.First;
    808833                   
     
    818843                        entry.Text = enc.GetString(linkedListNode.Value.decryption);
    819844
    820                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Add(entry);
     845                        localQuickWatchPresentation.entries.Add(entry);
    821846                        linkedListNode = linkedListNode.Next;
    822847                    }
     
    826851
    827852
    828             else if (!stop && QuickWatchPresentation.IsVisible)
    829             {
    830 
    831                 ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    832                 {
    833                     ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Clear();
     853            else if (!stop && localQuickWatchPresentation.IsVisible)
     854            {
     855
     856                localQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     857                {
     858                    localQuickWatchPresentation.entries.Clear();
    834859                    linkedListNode = costList.First;                   
    835860                    int i = 0;
     
    845870                        entry.Text = enc.GetString(linkedListNode.Value.decryption);
    846871
    847                         ((KeySearcherQuickWatchPresentation)QuickWatchPresentation).entries.Add(entry);
     872                        localQuickWatchPresentation.entries.Add(entry);
    848873                        linkedListNode = linkedListNode.Next;
    849874                    }
     
    872897        }
    873898
    874         internal void IntegrateNewResults(LinkedList<ValueKey> costList)
    875         {
    876             foreach (var valueKey in costList)
    877             {
    878                 if (_keyQualityHelper.IsBetter(valueKey.value, value_threshold))
     899        internal void IntegrateNewResults(LinkedList<ValueKey> updatedCostList)
     900        {
     901            foreach (var valueKey in updatedCostList)
     902            {
     903                if (keyQualityHelper.IsBetter(valueKey.value, value_threshold))
    879904                {
    880905                    valuequeue.Enqueue(valueKey);
     
    883908
    884909            updateToplist();
    885             UpdateWithShowProgress();
    886910        }
    887911
     
    941965                }
    942966            }
    943         }
    944 
    945         private void UpdateWithShowProgress()
    946         {
    947             showProgress(costList, 1, 0, 0);
    948967        }
    949968
  • trunk/CrypPlugins/KeySearcher/KeySearcher.csproj

    r1674 r1682  
    103103  </ItemGroup>
    104104  <ItemGroup>
     105    <Compile Include="Converter\TimeSpanToRoundedStringConverter.cs" />
     106    <Compile Include="Converter\TrueToVisibleOrCollapsedConverter.cs" />
     107    <Compile Include="Converter\FalseToVisibleConverter.cs" />
     108    <Compile Include="Converter\TrueToVisibleConverter.cs" />
    105109    <Compile Include="Helper\KeyQualityHelper.cs" />
    106110    <Compile Include="KeyPattern\KeyPattern.cs" />
    107111    <Compile Include="KeyPattern\KeyPatternPool.cs" />
    108112    <Compile Include="KeySearcher.cs" />
    109     <Compile Include="Presentation\KeySearcherQuickWatchPresentation.xaml.cs">
    110       <DependentUpon>KeySearcherQuickWatchPresentation.xaml</DependentUpon>
     113    <Compile Include="P2P\Presentation\StatisticsGenerator.cs" />
     114    <Compile Include="P2P\Presentation\StatusContainer.cs" />
     115    <Compile Include="Presentation\Controls\LocalQuickWatchPresentation.xaml.cs">
     116      <DependentUpon>LocalQuickWatchPresentation.xaml</DependentUpon>
    111117    </Compile>
    112118    <Compile Include="KeySearcherSettings.cs" />
     
    122128    <Compile Include="P2P\Storage\StorageHelper.cs" />
    123129    <Compile Include="P2P\DistributedBruteForceManager.cs" />
     130    <Compile Include="Presentation\Controls\P2PQuickWatchPresentation.xaml.cs">
     131      <DependentUpon>P2PQuickWatchPresentation.xaml</DependentUpon>
     132    </Compile>
     133    <Compile Include="Presentation\QuickWatch.xaml.cs">
     134      <DependentUpon>QuickWatch.xaml</DependentUpon>
     135    </Compile>
    124136    <Compile Include="Properties\AssemblyInfo.cs" />
    125137    <Compile Include="KeyPattern\Wildcard.cs" />
     
    141153  </ItemGroup>
    142154  <ItemGroup>
     155    <Page Include="Presentation\Controls\P2PQuickWatchPresentation.xaml">
     156      <SubType>Designer</SubType>
     157      <Generator>MSBuild:Compile</Generator>
     158    </Page>
     159    <Page Include="Presentation\QuickWatch.xaml">
     160      <SubType>Designer</SubType>
     161      <Generator>MSBuild:Compile</Generator>
     162    </Page>
    143163    <Resource Include="DetailedDescription\Description.xaml">
    144164      <Generator>MSBuild:Compile</Generator>
     
    147167      <SubType>Designer</SubType>
    148168    </Resource>
    149     <Page Include="Presentation\KeySearcherQuickWatchPresentation.xaml">
     169    <Page Include="Presentation\Controls\LocalQuickWatchPresentation.xaml">
    150170      <SubType>Designer</SubType>
    151171      <Generator>MSBuild:Compile</Generator>
  • trunk/CrypPlugins/KeySearcher/KeySearcherSettings.cs

    r1674 r1682  
    9999        }
    100100
     101        private bool verbosePeerToPeerDisplay;
     102        [TaskPane("Display verbose information", "Display verbose information about network requests in the quick watch.", GroupPeerToPeer, 2, true, DisplayLevel.Beginner,
     103            ControlType.CheckBox)]
     104        public bool VerbosePeerToPeerDisplay
     105        {
     106            get { return verbosePeerToPeerDisplay; }
     107            set
     108            {
     109                if (value != verbosePeerToPeerDisplay)
     110                {
     111                    verbosePeerToPeerDisplay = value;
     112                    OnPropertyChanged("VerbosePeerToPeerDisplay");
     113                    HasChanges = true;
     114                }
     115            }
     116        }
     117
    101118        private int chunkSize;
    102119        [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,
     
    114131                    HasChanges = true;
    115132                }
    116             }
    117         }
    118 
    119         [TaskPane("Amount of chunks", "Total number of chunks that must be calculated with the given chunk size.", GroupPeerToPeer, 4, false, DisplayLevel.Professional,
    120             ControlType.TextBox)]
    121         public double TotalAmountOfChunks
    122         {
    123             get {
    124                 if (keysearcher.Pattern == null || !keysearcher.Pattern.testWildcardKey(key) || ChunkSize == 0)
    125                 {
    126                     return 0;
    127                 }
    128 
    129                 var keyPattern = new KeyPattern.KeyPattern(keysearcher.ControlMaster.getKeyPattern());
    130                 keyPattern.WildcardKey = key;
    131                 var keyPatternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, ChunkSize)));
    132                 return (double) keyPatternPool.Length;
    133             }
    134             set
    135             {
    136                 OnPropertyChanged("TotalAmountOfChunks");
    137133            }
    138134        }
  • trunk/CrypPlugins/KeySearcher/P2P/DistributedBruteForceManager.cs

    r1674 r1682  
    11using System;
    22using System.Collections.Generic;
     3using System.Diagnostics;
    34using System.Numerics;
     5using System.Windows.Threading;
    46using Cryptool.PluginBase;
    57using KeySearcher.Helper;
    68using KeySearcher.KeyPattern;
    79using KeySearcher.P2P.Exceptions;
     10using KeySearcher.P2P.Presentation;
    811using KeySearcher.P2P.Storage;
    912using KeySearcher.P2P.Tree;
     13using KeySearcherPresentation.Controls;
    1014
    1115namespace KeySearcher.P2P
     
    1620        private readonly KeyPoolTree keyPoolTree;
    1721        private readonly KeySearcher keySearcher;
     22        private readonly KeySearcherSettings settings;
     23        private readonly P2PQuickWatchPresentation quickWatch;
    1824        private readonly KeyPatternPool patternPool;
     25        private readonly StatusContainer status;
     26        internal readonly StatisticsGenerator StatisticsGenerator;
     27        internal readonly Stopwatch StopWatch;
    1928
    2029        public DistributedBruteForceManager(KeySearcher keySearcher, KeyPattern.KeyPattern keyPattern, KeySearcherSettings settings,
    21                                             KeyQualityHelper keyQualityHelper)
     30                                            KeyQualityHelper keyQualityHelper, P2PQuickWatchPresentation quickWatch)
    2231        {
    2332            this.keySearcher = keySearcher;
     33            this.settings = settings;
     34            this.quickWatch = quickWatch;
    2435
    2536            // TODO when setting is still default (21), it is only displayed as 21 - but the settings-instance contains 0 for that key!
     
    3142            keyGenerator = new StorageKeyGenerator(keySearcher, settings);
    3243            patternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, settings.ChunkSize)));
    33             keyPoolTree = new KeyPoolTree(patternPool, this.keySearcher, keyQualityHelper, keyGenerator);
     44            status = new StatusContainer();
     45            StatisticsGenerator = new StatisticsGenerator(status, quickWatch, keySearcher, settings, this);
     46            keyPoolTree = new KeyPoolTree(patternPool, this.keySearcher, keyQualityHelper, keyGenerator, status, StatisticsGenerator);
     47            StopWatch = new Stopwatch();
     48
     49            quickWatch.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateStatusContainerInQuickWatch));
    3450
    3551            keySearcher.GuiLogMessage(
     
    5874                }
    5975
     76                StatisticsGenerator.CalculateGlobalStatistics(currentLeaf.PatternId());
    6077                if (!currentLeaf.ReserveLeaf())
    6178                {
     
    7188                    "Running pattern #" + (currentLeaf.PatternId() + 1) + " of " + patternPool.Length,
    7289                    NotificationLevel.Info);
     90                status.CurrentChunk = currentLeaf.PatternId() + 1;
    7391
    7492                try
    7593                {
    76                     LinkedList<KeySearcher.ValueKey> result =
    77                         keySearcher.BruteForceWithLocalSystem(patternPool[currentLeaf.PatternId()]);
     94                    status.IsCurrentProgressIndeterminate = false;
     95                    StopWatch.Start();
     96                    var result = keySearcher.BruteForceWithLocalSystem(patternPool[currentLeaf.PatternId()], true);
     97                    StopWatch.Stop();
     98                    status.IsCurrentProgressIndeterminate = true;
    7899
    79100                    if (!keySearcher.stop)
     101                    {
    80102                        KeyPoolTree.ProcessCurrentPatternCalculationResult(currentLeaf, result);
     103                        StatisticsGenerator.ProcessPatternResults(result);
     104                       
     105                        status.LocalFinishedChunks++;
     106                        keySearcher.GuiLogMessage(
     107                        string.Format("Best match: {0} with {1}", result.First.Value.key, result.First.Value.value),
     108                        NotificationLevel.Info);
     109                    }
    81110                    else
     111                    {
    82112                        keySearcher.GuiLogMessage("Brute force was stopped, not saving results...",
    83113                                                  NotificationLevel.Info);
    84 
    85                     keySearcher.GuiLogMessage(
    86                         string.Format("Best match: {0} with {1}", result.First.Value.key, result.First.Value.value),
    87                         NotificationLevel.Info);
     114                        status.ProgressOfCurrentChunk = 0;
     115                    }
    88116                }
    89117                catch (ReservationRemovedException)
     
    108136                keySearcher.showProgress(keySearcher.costList, 1, 1, 1);
    109137                keySearcher.GuiLogMessage("Calculation complete.", NotificationLevel.Info);
     138                status.ProgressOfCurrentChunk = 0;
     139                status.IsSearchingForReservedNodes = false;
    110140            }
     141        }
     142
     143        private void UpdateStatusContainerInQuickWatch()
     144        {
     145            quickWatch.DataContext = status;
     146            quickWatch.UpdateSettings(keySearcher, settings);
    111147        }
    112148    }
  • trunk/CrypPlugins/KeySearcher/P2P/Storage/StorageHelper.cs

    r1674 r1682  
    33using Cryptool.P2P;
    44using Cryptool.P2P.Internal;
     5using KeySearcher.P2P.Presentation;
    56using KeySearcher.P2P.Tree;
    67
     
    1011    {
    1112        private readonly KeySearcher keySearcher;
     13        private readonly StatisticsGenerator statisticsGenerator;
     14        private readonly StatusContainer statusContainer;
    1215
    13         public StorageHelper(KeySearcher keySearcher)
     16        public StorageHelper(KeySearcher keySearcher, StatisticsGenerator statisticsGenerator, StatusContainer statusContainer)
    1417        {
    1518            this.keySearcher = keySearcher;
     19            this.statisticsGenerator = statisticsGenerator;
     20            this.statusContainer = statusContainer;
    1621        }
    1722
    18         internal static RequestResult UpdateInDht(NodeBase nodeToUpdate)
     23        internal RequestResult UpdateInDht(NodeBase nodeToUpdate)
    1924        {
    2025            var memoryStream = new MemoryStream();
     
    3944            }
    4045
    41             return P2PManager.Store(KeyInDht(nodeToUpdate), memoryStream.ToArray());
     46            return StoreWithStatistic(KeyInDht(nodeToUpdate), memoryStream.ToArray());
    4247        }
    4348
     
    6368            nodeToUpdate.LastUpdate = DateTime.Now;
    6469
    65             var requestResult = P2PManager.Retrieve(KeyInDht(nodeToUpdate));
     70            var requestResult = RetrieveWithStatistic(KeyInDht(nodeToUpdate));
    6671            var nodeBytes = requestResult.Data;
    6772
     
    97102            {
    98103                keySearcher.IntegrateNewResults(nodeToUpdate.Result);
     104                statisticsGenerator.ProcessPatternResults(nodeToUpdate.Result);
    99105            }
    100106
     
    121127            return string.Format("{0}_node_{1}_{2}", node.DistributedJobIdentifier, node.From, node.To);
    122128        }
     129
     130        public RequestResult RetrieveWithStatistic(string key)
     131        {
     132            statusContainer.RetrieveRequests++;
     133            statusContainer.TotalDhtRequests++;
     134            return P2PManager.Retrieve(key);
     135        }
     136
     137        public RequestResult RemoveWithStatistic(string key)
     138        {
     139            statusContainer.RemoveRequests++;
     140            statusContainer.TotalDhtRequests++;
     141            return P2PManager.Remove(key);
     142        }
     143
     144        public RequestResult StoreWithStatistic(string key, byte[] data)
     145        {
     146            statusContainer.StoreRequests++;
     147            statusContainer.TotalDhtRequests++;
     148            return P2PManager.Store(key, data);
     149        }
    123150    }
    124151}
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/KeyPoolTree.cs

    r1674 r1682  
    33using KeySearcher.Helper;
    44using KeySearcher.KeyPattern;
     5using KeySearcher.P2P.Presentation;
    56using KeySearcher.P2P.Storage;
    67
     
    1011    {
    1112        private readonly KeySearcher keySearcher;
     13        private readonly StatusContainer statusContainer;
     14        private readonly StatisticsGenerator statisticsGenerator;
    1215        private readonly KeyPatternPool patternPool;
    1316        private readonly NodeBase rootNode;
    1417        private readonly StorageHelper storageHelper;
     18
    1519        private NodeBase currentNode;
    1620        private bool skippedReservedNodes;
    1721
    18         public KeyPoolTree(KeyPatternPool patternPool, KeySearcher keySearcher, KeyQualityHelper keyQualityHelper,
    19                            StorageKeyGenerator identifierGenerator)
     22        public KeyPoolTree(KeyPatternPool patternPool, KeySearcher keySearcher, KeyQualityHelper keyQualityHelper, StorageKeyGenerator identifierGenerator, StatusContainer statusContainer, StatisticsGenerator statisticsGenerator)
    2023        {
    2124            this.patternPool = patternPool;
    2225            this.keySearcher = keySearcher;
     26            this.statusContainer = statusContainer;
     27            this.statisticsGenerator = statisticsGenerator;
    2328
    24             storageHelper = new StorageHelper(keySearcher);
     29            storageHelper = new StorageHelper(keySearcher, statisticsGenerator, statusContainer);
    2530            skippedReservedNodes = false;
    2631
     
    3237        public Leaf FindNextLeaf()
    3338        {
     39            statusContainer.IsSearchingForReservedNodes = false;
     40            statisticsGenerator.MarkStartOfNodeSearch();
     41
    3442            var nodeBeforeStarting = currentNode;
    3543            var foundNode = FindNextLeaf(false);
     
    3745            if (foundNode == null && skippedReservedNodes)
    3846            {
    39                 keySearcher.GuiLogMessage("Searching again with reserved nodes enabled...", NotificationLevel.Warning);
     47                keySearcher.GuiLogMessage("Searching again with reserved nodes enabled...", NotificationLevel.Info);
    4048
    4149                currentNode = nodeBeforeStarting;
     50                statusContainer.IsSearchingForReservedNodes = true;
    4251                foundNode = FindNextLeaf(true);
    4352                currentNode = foundNode;
     53
     54                statisticsGenerator.MarkEndOfNodeSearch();
    4455                return foundNode;
    4556            }
    4657
    4758            currentNode = foundNode;
     59
     60            statisticsGenerator.MarkEndOfNodeSearch();
    4861            return foundNode;
    4962        }
  • trunk/CrypPlugins/KeySearcher/P2P/Tree/NodeBase.cs

    r1674 r1682  
    5757            ParentNode.ChildFinished(this);
    5858
    59             if (P2PManager.Retrieve(StorageHelper.KeyInDht(this)).Status == RequestResultType.KeyNotFound)
     59            if (StorageHelper.RetrieveWithStatistic(StorageHelper.KeyInDht(this)).Status == RequestResultType.KeyNotFound)
    6060            {
    6161                throw new ReservationRemovedException("Before updating parent node, this leaf's reservation was deleted.");
     
    6868            }
    6969
    70             P2PManager.Remove(StorageHelper.KeyInDht(this));
     70            StorageHelper.RemoveWithStatistic(StorageHelper.KeyInDht(this));
    7171
    7272            if (ParentNode.IsCalculated())
  • trunk/CrypPlugins/KeySearcher/Presentation/Controls/LocalQuickWatchPresentation.xaml

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

    r1677 r1682  
    11using System;
    2 using System.Windows.Controls;
    32using System.Windows.Media;
    43using System.Collections.ObjectModel;
     4using KeySearcher;
    55
    6 namespace KeySearcher.Presentation
     6namespace KeySearcherPresentation.Controls
    77{   
    8     public partial class KeySearcherQuickWatchPresentation : UserControl
     8    public partial class LocalQuickWatchPresentation
    99    {       
    1010        public ObservableCollection<ResultEntry> entries = new ObservableCollection<ResultEntry>();
    1111
    12         public KeySearcherQuickWatchPresentation()
     12        public LocalQuickWatchPresentation()
    1313        {
    1414            InitializeComponent();
Note: See TracChangeset for help on using the changeset viewer.