Ignore:
Timestamp:
Feb 22, 2010, 2:19:39 PM (12 years ago)
Author:
arnold
Message:

P2PManager: Design embellished and added an "estimated end time" information.
Samples: Output Boxes for KeySearcher Outputs

Location:
trunk/CrypPlugins/PeerToPeerManager_NEW
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerBase_NEW.cs

    r1144 r1166  
    106106        }
    107107
     108        private DateTime startWorkingTime = DateTime.MinValue;
     109        /// <summary>
     110        /// This value will be initialized after allocating the first job to a worker.
     111        /// Before initialization this is MinValue! Used for end time approximation
     112        /// </summary>
     113        public DateTime StartWorkingTime
     114        {
     115            get { return this.startWorkingTime; }
     116        }
     117
    108118        #endregion
    109119
     
    122132            if (this.distributableJobControl != null && this.p2pControl != null)
    123133            {
     134                //set value to null, when restarting the manager
     135                this.startWorkingTime = DateTime.MinValue;
    124136                this.TopicName = sTopic;
    125137                this.AliveMesageInterval = aliveMessageInterval;
     
    344356            GuiLogging("REMOVED worker " + peerId, NotificationLevel.Info);
    345357
    346             // push job back and remove list entries for "jobs in progress"
    347             List<BigInteger> allJobsForRemovedPeer = (from k in this.jobsInProgress where k.Value == peerId select k.Key).ToList<BigInteger>();
    348 
    349             BigInteger jobId;
    350             for (int i = 0; i < allJobsForRemovedPeer.Count; i++)
    351             {
    352                 jobId = allJobsForRemovedPeer[i];
    353                 this.distributableJobControl.Push(jobId);
    354                 this.jobsInProgress.Remove(jobId);
    355                 GuiLogging("Pushed job '" + jobId.ToString() + "' back to the stack, because peer left the network.", NotificationLevel.Debug);
    356             }
    357 
    358             // Set the JobDeclined-status for all jobs of the removed peer, which are still waiting
    359             // for an acceptance information. Than remove all jobs from the "jobs waiting for acceptance info" List
    360             List<BigInteger> allWaitingEntriesForRemovedPeer = (from k in this.jobsWaitingForAcceptanceInfo where k.Value == peerId select k.Key).ToList<BigInteger>();
    361 
    362             for (int i = 0; i < allWaitingEntriesForRemovedPeer.Count; i++)
    363             {
    364                 this.distributableJobControl.JobDeclined(allWaitingEntriesForRemovedPeer[i]);
    365                 this.jobsWaitingForAcceptanceInfo.Remove(allWaitingEntriesForRemovedPeer[i]);
    366                 GuiLogging("Declined job '" + allWaitingEntriesForRemovedPeer[i].ToString() + "', because peer left the network.", NotificationLevel.Debug);
     358            // necessary lock, because the amount of jobs in Progress could change while traversing this list
     359            lock (this.jobsInProgress)
     360            {
     361                // push job back and remove list entries for "jobs in progress"
     362                List<BigInteger> allJobsForRemovedPeer = (from k in this.jobsInProgress where k.Value == peerId select k.Key).ToList<BigInteger>();
     363
     364                BigInteger jobId;
     365                for (int i = 0; i < allJobsForRemovedPeer.Count; i++)
     366                {
     367                    jobId = allJobsForRemovedPeer[i];
     368                    this.distributableJobControl.Push(jobId);
     369                    this.jobsInProgress.Remove(jobId);
     370                    GuiLogging("Pushed job '" + jobId.ToString() + "' back to the stack, because peer left the network.", NotificationLevel.Debug);
     371                }
     372            }
     373
     374            // necessary lock, because the amount of jobs in Progress could change while traversing this list
     375            lock (this.jobsWaitingForAcceptanceInfo)
     376            {
     377                // Set the JobDeclined-status for all jobs of the removed peer, which are still waiting
     378                // for an acceptance information. Than remove all jobs from the "jobs waiting for acceptance info" List
     379                List<BigInteger> allWaitingEntriesForRemovedPeer = (from k in this.jobsWaitingForAcceptanceInfo where k.Value == peerId select k.Key).ToList<BigInteger>();
     380
     381                for (int i = 0; i < allWaitingEntriesForRemovedPeer.Count; i++)
     382                {
     383                    this.distributableJobControl.JobDeclined(allWaitingEntriesForRemovedPeer[i]);
     384                    this.jobsWaitingForAcceptanceInfo.Remove(allWaitingEntriesForRemovedPeer[i]);
     385                    GuiLogging("Declined job '" + allWaitingEntriesForRemovedPeer[i].ToString() + "', because peer left the network.", NotificationLevel.Debug);
     386                }
    367387            }
    368388
     
    382402
    383403            GuiLogging("Trying to allocate " + freePeers.Count + " job(s) to workers.", NotificationLevel.Debug);
     404
     405            // set the start working time after allocating the FIRST job
     406            if (this.startWorkingTime == DateTime.MinValue && freePeers.Count > 0)
     407                this.startWorkingTime = DateTime.Now;
    384408
    385409            foreach (PeerId worker in freePeers)
     
    447471        }
    448472
     473        /// <summary>
     474        /// returns the estimated end time (correlation between Start Time, Total amount of jobs and finished jobs).
     475        /// When no job is finished yet, it returns an empty timespan
     476        /// </summary>
     477        /// <returns></returns>
     478        public DateTime EstimatedEndTime()
     479        {
     480            DateTime retTime = DateTime.MaxValue;
     481            if (this.distributableJobControl.FinishedAmount.LongValue() > 0)
     482            {
     483                TimeSpan bruteforcingTime = DateTime.Now.Subtract(this.StartWorkingTime);
     484                double jobsPerSecond = bruteforcingTime.TotalSeconds / this.distributableJobControl.FinishedAmount.LongValue();
     485                double restSeconds = jobsPerSecond *
     486                    (this.distributableJobControl.TotalAmount - this.distributableJobControl.FinishedAmount).LongValue();
     487                //retTime.TotalSeconds = jobsPerSecond * (2 - (progressInPercent / 100));
     488                retTime = DateTime.Now.AddSeconds(restSeconds);
     489            }
     490            return retTime;
     491        }
     492
    449493        #region Forward PeerManagement Values
    450494
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerPresentation.xaml

    r1137 r1166  
    44        HorizontalAlignment="Stretch"
    55        VerticalAlignment="Stretch"
    6         Background="Azure"
     6        Name="MngrMain"
     7        Background="LightBlue"
    78    MinHeight="150" MinWidth="100"
    89    Height="Auto" Width="Auto">
    9 
     10   
    1011    <Canvas Name="Canvas" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
    1112        <Grid Name="Grid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
     
    2021            </Grid.ColumnDefinitions>
    2122
    22             <Expander Name="Expander_JobStatus" Header="Job Status Info" IsExpanded="True" FontSize="10" Background="Yellow">
     23            <Expander Name="Expander_JobStatus" Header="Job Status Info" IsExpanded="True" FontSize="10">
    2324                <Grid Name="JobGrid">
    2425                    <Grid.RowDefinitions>
     
    3839                            <RowDefinition/>
    3940                            <RowDefinition/>
     41                            <RowDefinition/>
     42                            <RowDefinition/>
    4043                        </Grid.RowDefinitions>
    4144                        <Grid.ColumnDefinitions>
     
    4447
    4548                        <Label Grid.Row="0" Grid.Column="0" FontSize="10" FontWeight="Bold" VerticalContentAlignment="Bottom"
    46                            VerticalAlignment="Bottom" HorizontalContentAlignment="Center" Width="AUTO">Total Progress:</Label>
     49                           VerticalAlignment="Top" HorizontalContentAlignment="Center" >Total Progress:</Label>
    4750                        <TextBox Name="txtProgressInPercent" Grid.Row="1" Grid.Column="0" TextAlignment="Center"
    4851                             IsReadOnly="True" TextWrapping="WrapWithOverflow" FontSize="10" FontWeight="Bold"
    49                              BorderThickness="0" VerticalContentAlignment="Top" HorizontalContentAlignment="Center" Background="Yellow"/>
     52                             BorderThickness="0" VerticalContentAlignment="Top" HorizontalContentAlignment="Center"/>
     53                       
     54                        <Label Grid.Row="2" Grid.Column="0" FontSize="10" FontWeight="Bold" FontStyle="Italic" VerticalContentAlignment="Bottom"
     55                           VerticalAlignment="Top" HorizontalContentAlignment="Center" >Estimated end time:</Label>
     56                        <TextBox Name="txtEstimatedEndTime" Text="no finished jobs" Grid.Row="3" Grid.Column="0" TextAlignment="Center"
     57                             IsReadOnly="True" TextWrapping="WrapWithOverflow" FontSize="8" FontWeight="Bold"
     58                             BorderThickness="0" VerticalContentAlignment="Top" HorizontalContentAlignment="Center"/>
    5059                    </Grid>
    5160
    52                     <Label Grid.Row="0" Grid.Column="0" FontSize="8" FontWeight="Bold" Background="Azure" VerticalAlignment="Top" Height="23" Width="AUTO">Total:</Label>
     61                    <Label Grid.Row="0" Grid.Column="0" FontSize="8" FontWeight="Bold" VerticalAlignment="Top" Height="23" Width="AUTO">Total:</Label>
    5362                    <TextBox Name="txtTotal" Grid.Row="0" Grid.Column="1" TextAlignment="Left"
    5463                     IsReadOnly="True" TextWrapping="WrapWithOverflow" VerticalAlignment="Top"
    5564                     Height="23" FontSize="8" FontWeight="Bold" BorderThickness="1" />
    5665
    57                     <Label Grid.Row="1" Grid.Column="0" FontSize="8" Background="Bisque" VerticalAlignment="Top" Height="23" Width="AUTO">In Progress:</Label>
     66                    <Label Grid.Row="1" Grid.Column="0" FontSize="8" Background="DarkGray" VerticalAlignment="Top" Height="23" Width="AUTO">In Progress:</Label>
    5867                    <TextBox Name="txtInProgress" Grid.Row="1" Grid.Column="1" TextAlignment="Left"
    5968                     IsReadOnly="True" TextWrapping="WrapWithOverflow" VerticalAlignment="Top"
    6069                     Height="23" FontSize="8" BorderThickness="1"/>
    6170
    62                     <Label Grid.Row="2" Grid.Column="0" FontSize="8" Background="Azure" VerticalAlignment="Top" Height="23" Width="AUTO">Left:</Label>
     71                    <Label Grid.Row="2" Grid.Column="0" FontSize="8" VerticalAlignment="Top" Height="23" Width="AUTO">Left:</Label>
    6372                    <TextBox Name="txtLeft" Grid.Row="2" Grid.Column="1" TextAlignment="Left"
    6473                     IsReadOnly="True" TextWrapping="WrapWithOverflow" VerticalAlignment="Top"
    6574                     Height="23" FontSize="8" BorderThickness="1"/>
    6675
    67                     <Label Grid.Row="3" Grid.Column="0" FontSize="8" FontWeight="Bold" Background="Bisque" VerticalAlignment="Top" Height="23" Width="AUTO">Finished:</Label>
     76                    <Label Grid.Row="3" Grid.Column="0" FontSize="8" FontWeight="Bold" Background="DarkGray" VerticalAlignment="Top" Height="23" Width="AUTO">Finished:</Label>
    6877                    <TextBox Name="txtFinished" Grid.Row="3" Grid.Column="1" TextAlignment="Left"
    6978                     IsReadOnly="True" TextWrapping="WrapWithOverflow" VerticalAlignment="Top"
     
    7382            </Expander>
    7483
    75             <Expander Name="Expander_List" Header="Global Top 10 List" IsExpanded="True" FontSize="10" Background="AliceBlue" Grid.Row="1">
     84            <Expander Name="Expander_List" Header="Global Top 10 List" IsExpanded="True" FontSize="10" Grid.Row="1">
    7685                <ListView Name="ListView" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" FontSize="8">
    7786                    <ListView.View>
     
    110119            </Expander>
    111120
    112             <Expander Name="Expander_WorkerInfo" Header="Worker Info" IsExpanded="False" FontSize="10" Background="LimeGreen" Grid.Row="2">
     121            <Expander Name="Expander_WorkerInfo" Header="Worker Info" IsExpanded="False" FontSize="10" Grid.Row="2">
    113122                <Grid Name="WorkerGrid">
    114123                    <Grid.RowDefinitions>
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerPresentation.xaml.cs

    r1139 r1166  
    2424        public ObservableCollection<ResultEntry> entries = new ObservableCollection<ResultEntry>();
    2525
     26        #region Different radient brushes
     27
     28        public LinearGradientBrush GetGradientBlue()
     29        {
     30            LinearGradientBrush myBrush = new LinearGradientBrush();
     31            myBrush.GradientStops.Add(new GradientStop(Colors.DodgerBlue, 0.0)); //CadetBlue
     32            myBrush.GradientStops.Add(new GradientStop(Colors.CornflowerBlue, 0.5));
     33            myBrush.GradientStops.Add(new GradientStop(Colors.AliceBlue, 1.0));
     34            return myBrush;
     35        }
     36
     37        public LinearGradientBrush GetGradientGray()
     38        {
     39            LinearGradientBrush myBrush = new LinearGradientBrush();
     40            myBrush.GradientStops.Add(new GradientStop(Colors.DarkGray, 0.0));
     41            myBrush.GradientStops.Add(new GradientStop(Colors.Gray, 0.5));
     42            myBrush.GradientStops.Add(new GradientStop(Colors.WhiteSmoke, 1.0));
     43            return myBrush;
     44        }
     45
     46        #endregion
     47
    2648        public P2PManagerPresentation()
    2749        {
     
    3759            //this.ListView.SizeChanged += new SizeChangedEventHandler(ListView_SizeChanged);
    3860            this.ListView.SourceUpdated += new EventHandler<DataTransferEventArgs>(ListView_SourceUpdated);
     61
     62            LinearGradientBrush blueBrush = GetGradientBlue();
     63
     64            this.MngrMain.Background = blueBrush;
     65            this.Expander_JobStatus.Background = blueBrush;
     66            this.Expander_WorkerInfo.Background = blueBrush;
     67            this.Expander_List.Background = GetGradientGray();
    3968        }
    4069
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManager_KeyPattern.cs

    r1139 r1166  
    6262        }
    6363
     64        /// <summary>
     65        /// after starting the execution, set this value, so after receiving
     66        /// a Job result, the WPF UpdateQuickWatch can use this value, without
     67        /// accessing the Settings every time.
     68        /// </summary>
     69        private int bytesToUseForDecryption = 0;
     70
    6471        #region In and Output
    6572
     
    225232                    ((P2PManagerPresentation)QuickWatchPresentation).txtBusyWorker.Text = "" + busyWorkers;
    226233
     234                    /* START approximation of end time */
     235                    // this value is MinValue until the first job is allocated to a worker
     236                    DateTime estimateDateTime = this.p2pManager.EstimatedEndTime();
     237                    if(estimateDateTime != DateTime.MaxValue)
     238                    {
     239                        ((P2PManagerPresentation)QuickWatchPresentation).txtEstimatedEndTime.Text = estimateDateTime.ToString();
     240                    }
     241                    /* END approximation of end time */
     242
    227243                    ((P2PManagerPresentation)QuickWatchPresentation).entries.Clear();
    228244                    listNode = globalTop10List.First;
     
    237253                        entry.Value = "" + Math.Round(listNode.Value.value, 3);
    238254                        entry.Key = listNode.Value.key;
    239                         entry.Text = enc.GetString(listNode.Value.decryption);
     255                        entry.Text = enc.GetString(listNode.Value.decryption, 0, this.bytesToUseForDecryption);
    240256
    241257                        ((P2PManagerPresentation)QuickWatchPresentation).entries.Add(entry);
     
    447463            }
    448464
     465            this.bytesToUseForDecryption = this.settings.BytesToUse;
     466
    449467            this.p2pManager.StartManager(this.settings.TopicName, this.settings.SendAliveMessageInterval * 1000);
    450468
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManager_KeyPatternSettings.cs

    r1137 r1166  
    158158            }
    159159        }
     160
     161        private int bytesToUse = 128; // in hundred-thousand
     162        [TaskPane("BytesToUse", "Choose the bytes to use for the decryption process and displaying decryption results"
     163            , null, 4, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 32, 1024)]
     164        public int BytesToUse
     165        {
     166            get
     167            {
     168                return this.bytesToUse;
     169            }
     170            set
     171            {
     172                if (value != this.bytesToUse)
     173                {
     174                    if (value == null || value == 0 || value < 128)
     175                    {
     176                        this.bytesToUse = 128;
     177                    }
     178                    else if (this.bytesToUse > 1024)
     179                    {
     180                        this.bytesToUse = 1024;
     181                    }
     182                    else
     183                    {
     184                        this.bytesToUse = value;
     185                    }
     186                    OnPropertyChanged("BytesToUse");
     187                }
     188            }
     189        }
    160190        #region INotifyPropertyChanged Members
    161191
Note: See TracChangeset for help on using the changeset viewer.