Changeset 1166


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
Files:
11 edited

Legend:

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

    r1162 r1166  
    177177            get
    178178            {
    179                 int[] a = null, b = null, c = null;
    180                 return ControlMaster.getKeyFromString(top1ValueKey.key, ref a, ref b, ref c);
     179                if (top1ValueKey.key != null) //added by Arnold - 2010.02.22
     180                {
     181                    int[] a = null, b = null, c = null;
     182                    return ControlMaster.getKeyFromString(top1ValueKey.key, ref a, ref b, ref c);
     183                }
     184                else
     185                    return null;
    181186            }
    182187        }
  • 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
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisherBase.cs

    r1144 r1166  
    275275                    {
    276276                        GuiLogging("ALREADY REGISTERED peer with ID " + sender, NotificationLevel.Info);
     277                        // this case only occurs, when some messages run into a misunderstanding,
     278                        // but reply with a RegAccepted Msg, so the sender won't send new Reg Msgs
     279                        // periodically.
     280                        this.p2pControl.SendToPeer(PubSubMessageType.RegisteringAccepted, sender);
    277281                    }
    278282                    break;
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberBase.cs

    r1144 r1166  
    171171                    GuiLogging("Found a Publisher/Manager with ID '" + pid.ToString() + ", so register with it.", NotificationLevel.Info);
    172172                    SendMessage(pid, PubSubMessageType.Register);
    173                     timeoutForPublishersRegAccept.Start();
     173                    this.timeoutForPublishersRegAccept.Start();
    174174                }
    175175                else if (actualPublisher == pid)
     
    186186                        + "' to '" + pid.ToString() + "'. Register with the new Publisher/Manager.", NotificationLevel.Info);
    187187                    SendMessage(pid, PubSubMessageType.Register);
    188                     timeoutForPublishersRegAccept.Start();
     188                    this.timeoutForPublishersRegAccept.Start();
    189189                }
    190190                this.actualPublisher = pid;
     
    315315        {
    316316            CheckPublishersAvailability2();
    317 
    318             //PeerId newPubId = CheckPublishersAvailability();
    319 
    320             //if (newPubId == actualPublisher)
    321             //{
    322             //    // Timer will be only stopped, when OnMessageReceived-Event received
    323             //    // a Pong-Response from the publisher!
    324             //    SendMessage(actualPublisher, PubSubMessageType.Ping);
    325             //    this.timeoutForPublishersPong.Start();
    326             //}
    327317        }
    328318
     
    335325            GuiLogging("TIMEOUT: Waiting for registering accepted message from publisher!", NotificationLevel.Debug);
    336326            // try to register again
    337            
    338             //Register();
    339327            CheckPublishersAvailability2();
    340328        }
     
    350338            // try to get an active publisher and re-register
    351339
    352             //CheckPublishersAvailability();
    353340            CheckPublishersAvailability2();
    354341        }
     
    401388    }
    402389}
    403 
    404 
    405 
    406 //private void Register()
    407 //        {
    408 //            // because CheckPublishersAvailability checks this value, set it for the first time here...
    409 //            // if bolStopped = true, the Timer for Checking Publishers liveliness doesn't start
    410 //            this.bolStopped = false;
    411 //            PeerId pubId = CheckPublishersAvailability();
    412 //            // if DHT Entry for the task is empty, no Publisher exists at present.
    413 //            // The method CheckPublishersAvailability starts a Timer for this case to continous proof Publisher-DHT-Entry
    414 //            if (pubId == null)
    415 //            {
    416 //                this.Started = false;
    417 //                // if PubId is null, the Publisher isn't started!
    418 //                this.bolStopped = true;
    419 //                GuiLogging("No publisher for registering found.", NotificationLevel.Info);
    420 //                return;
    421 //            }
    422 
    423 //            // when the actual publisher differs from the new detected publisher, change it
    424 //            if (pubId != null && (actualPublisher != null && actualPublisher != pubId))
    425 //            {
    426 //                GuiLogging("Publisher has been changed from ID '" + actualPublisher + "' to '" + pubId + "'", NotificationLevel.Debug);
    427 //                actualPublisher = pubId;
    428 //            }
    429 //            SendMessage(pubId, PubSubMessageType.Register);
    430 //            this.timeoutForPublishersRegAccept.Start();
    431 //            this.started = true;
    432 //        }
    433 
    434 //        /// <summary>
    435 //        /// Returns the actual Publishers ID or null, when a publisher wasn't found in the DHT. In the second case,
    436 //        /// a Timer will be started, to check periodically the DHT entry.
    437 //        /// When the publishers entry changed the Publishers ID, a Register-message will be send to the new Publisher.
    438 //        /// The Timer for periodically checking the Publishers availability is also started here.
    439 //        /// </summary>
    440 //        /// <returns>the actual Publishers ID or null, when a publisher wasn't found in the DHT</returns>
    441 //        private PeerId CheckPublishersAvailability()
    442 //        {
    443 //            PeerId pid = DHT_CommonManagement.GetTopicsPublisherId(ref this.p2pControl, this.sTopic);
    444 
    445 //            if (pid == null)
    446 //            {
    447 //                // do nothing, because every time this method will be invoked by
    448 //                // the timerCheckPubAvailability-Event, the DHT entry will be checked
    449 //                GuiLogging("Publisher wasn't found in DHT or settings didn't stored on the right way.", NotificationLevel.Debug);
    450 //                return null;
    451 //            }
    452 
    453 //            sendAliveMessageInterval = DHT_CommonManagement.GetAliveMessageInterval(ref this.p2pControl, this.sTopic);
    454 
    455 //            if (sendAliveMessageInterval == 0)
    456 //            {
    457 //                GuiLogging("Can't find AliveMsg-Settings from Publisher for the Subscriber.", NotificationLevel.Error);
    458 //                return null;
    459 //            }
    460 //            this.timerSendingAliveMsg.Interval = Convert.ToDouble(sendAliveMessageInterval);
    461 //            this.timerSendingAliveMsg.Start();
    462 
    463 //            if (actualPublisher == null) //first time initialization
    464 //            {
    465 //                actualPublisher = pid;
    466 //                GuiLogging("First time received publishers ID.", NotificationLevel.Debug);
    467 //            }
    468 
    469 //            GuiLogging("RECEIVED: Publishers' peer ID '" + pid + "', Alive-Msg-Interval: " + sendAliveMessageInterval / 1000 + " sec!", NotificationLevel.Debug);
    470 
    471 //            this.timerCheckPubAvailability.Start();
    472 //            // setting timer to check periodical the availability of the publishing peer
    473 
    474 //            return pid;
    475 //        }
  • trunk/CrypPlugins/PeerToPeerWorker_NEW/P2PJobAdminBase.cs

    r1144 r1166  
    112112        public void StopWorkerControl(PubSubMessageType msgType)
    113113        {
     114            this.IsWorking = false;
     115
    114116            if (base.Started)
    115117            {
Note: See TracChangeset for help on using the changeset viewer.