Changeset 1139


Ignore:
Timestamp:
Feb 11, 2010, 8:54:10 PM (12 years ago)
Author:
arnold
Message:

1) Killed the LayoutUpdated-Event in WPF because it consumed 60-90% of the cpu load...
2) Changes Threading.Timer to Timers.Timer in P2PSubscriberBase.

Location:
trunk
Files:
1 added
1 deleted
9 edited

Legend:

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

    r1137 r1139  
    152152        public bool StartProcessing(byte[] job, out BigInteger jobId)
    153153        {
    154             jobId = 0; //out parameter
     154            jobId = null; //out parameter
    155155            if (job != null)
    156156            {
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManagerPresentation.xaml.cs

    r1137 r1139  
    2727        {
    2828            InitializeComponent();
    29             SizeChanged += new SizeChangedEventHandler(P2PManagerPresentation_SizeChanged);
     29            this.SizeChanged += new SizeChangedEventHandler(P2PManagerPresentation_SizeChanged);
    3030            this.DataContext = entries;
    31             this.LayoutUpdated += new EventHandler(P2PManagerPresentation_LayoutUpdated);
     31            // when you uncomment this line, you burn 70% of the whole CPU time for Resizing this view...
     32            //this.LayoutUpdated += new EventHandler(P2PManagerPresentation_LayoutUpdated);
     33            this.Expander_JobStatus.Expanded += new RoutedEventHandler(Expander_JobStatus_Expanded);
     34            this.Expander_List.Expanded += new RoutedEventHandler(Expander_List_Expanded);
     35            this.Expander_WorkerInfo.Expanded += new RoutedEventHandler(Expander_WorkerInfo_Expanded);
     36            //this.ListView.DataContextChanged += new DependencyPropertyChangedEventHandler(ListView_DataContextChanged);
     37            //this.ListView.SizeChanged += new SizeChangedEventHandler(ListView_SizeChanged);
     38            this.ListView.SourceUpdated += new EventHandler<DataTransferEventArgs>(ListView_SourceUpdated);
     39        }
     40
     41        void Grid_LayoutUpdated(object sender, EventArgs e)
     42        {
     43            FunnyResize();
     44        }
     45
     46        void Canvas_LayoutUpdated(object sender, EventArgs e)
     47        {
     48            FunnyResize();
     49        }
     50
     51        void ListView_SourceUpdated(object sender, DataTransferEventArgs e)
     52        {
     53            FunnyResize();
     54        }
     55
     56        void ListView_SizeChanged(object sender, SizeChangedEventArgs e)
     57        {
     58            FunnyResize();
     59        }
     60
     61        void ListView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
     62        {
     63            FunnyResize();
     64        }
     65
     66        void Expander_WorkerInfo_Expanded(object sender, RoutedEventArgs e)
     67        {
     68            FunnyResize();
     69        }
     70
     71        void Expander_List_Expanded(object sender, RoutedEventArgs e)
     72        {
     73            FunnyResize();
     74        }
     75
     76        void Expander_JobStatus_Expanded(object sender, RoutedEventArgs e)
     77        {
     78            FunnyResize();
    3279        }
    3380
  • trunk/CrypPlugins/PeerToPeerManager_NEW/P2PManager_KeyPattern.cs

    r1137 r1139  
    277277            }
    278278
    279             if (e.PropertyName == "TopicName")
    280             {
    281                 GuiLogMessage("Topic Name has changed, so all subscribers must reconfirm registering!", NotificationLevel.Warning);
    282                 // stop active publisher and tell all subscribers that topic name isn't valid anymore
    283                 Stop();
    284                 //this.p2pManager.Stop(PubSubMessageType.Unregister);
    285                 // start publisher for the changed topic
    286                 process(this.EncryptionControl);
    287                 //this.p2pManager.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
    288             }
     279            if (this.p2pControl == null)
     280                return;
    289281            if (e.PropertyName == "BtnUnregister")
    290282            {
    291                 Stop();
    292                 //this.p2pManager.Stop(PubSubMessageType.Unregister);
    293                 GuiLogMessage("Unregister button pressed, Publisher has stopped!", NotificationLevel.Info);
     283                if (this.p2pManager != null && this.p2pManager.Started)
     284                {
     285                    Stop();
     286                    //this.p2pManager.Stop(PubSubMessageType.Unregister);
     287                    GuiLogMessage("Unregister button pressed, Publisher has stopped!", NotificationLevel.Info);
     288                }
    294289            }
    295290            if (e.PropertyName == "BtnRegister")
    296291            {
    297                 this.process(this.EncryptionControl);
    298                 GuiLogMessage("Register button pressed, Publisher has been started!", NotificationLevel.Info);
     292                if (this.p2pManager == null || !this.p2pManager.Started)
     293                {
     294                    this.process(this.EncryptionControl);
     295                    GuiLogMessage("Register button pressed, Publisher has been started!", NotificationLevel.Info);
     296                }
    299297            }
    300298            if (e.PropertyName == "BtnSolutionFound")
    301299            {
    302                 Stop();
    303                 //this.p2pManager.Stop(PubSubMessageType.Solution);
    304                 GuiLogMessage("TEST: Emulate Solution-Found-message", NotificationLevel.Info);
     300                if (this.p2pManager != null && this.p2pManager.Started)
     301                {
     302                    Stop();
     303                    //this.p2pManager.Stop(PubSubMessageType.Solution);
     304                    GuiLogMessage("TEST: Emulate Solution-Found-message", NotificationLevel.Info);
     305                }
    305306            }
    306307        }
     
    333334                this.p2pManager.Stop(PubSubMessageType.Unregister);
    334335                this.settings.MngStatusChanged(P2PManager_KeyPatternSettings.MngStatus.Neutral);
     336                this.p2pManager.OnGuiMessage -= p2pManager_OnGuiMessage;
     337                this.p2pManager.OnProcessProgress -= p2pManager_OnProcessProgress;
     338                this.p2pManager.OnNewJobAllocated -= p2pManager_OnNewJobAllocated;
     339                this.p2pManager.OnNoMoreJobsLeft -= p2pManager_OnNoMoreJobsLeft;
     340                this.p2pManager.OnResultReceived -= p2pManager_OnResultReceived;
     341                // set Manager to null, so after restarting the Workspace,
     342                // a new Distributable stop will be initialized with (maybe)
     343                // changed settings
     344                this.p2pManager = null;
    335345            }
    336346        }
     
    392402                byte[] byteEncryptedData = null;
    393403                CryptoolStream newEncryptedData = new CryptoolStream();
    394                 newEncryptedData.OpenRead(this.DecryptedData.FileName);
    395                 if (newEncryptedData.CanRead)
    396                 {
     404                try
     405                {
     406                    newEncryptedData.OpenRead(this.DecryptedData.FileName);
    397407                    // Convert CryptoolStream to an byte Array and store it in the DHT
    398408                    if (newEncryptedData.Length > Int32.MaxValue)
     
    403413                        throw (new Exception("Read Data are shorter than byteArrayLen"));
    404414                }
    405                 else
    406                     throw (new Exception("Fatal error while reading the CryptoolStream."));
    407 
     415                catch (Exception ex)
     416                {
     417                    throw (new Exception("Fatal error while reading the CryptoolStream. Exception: " + ex.ToString()));
     418                }
     419                finally
     420                {
     421                    newEncryptedData.Close();
     422                    newEncryptedData.Dispose();
     423                }
     424                             
    408425                string pattern = this.encryptionControl.getKeyPattern();
    409426                KeyPattern kp = new KeyPattern(pattern);
     
    417434                    return;
    418435                }
    419 
    420436
    421437                // create a new DistributableJob instance
     
    434450
    435451            this.settings.MngStatusChanged(P2PManager_KeyPatternSettings.MngStatus.Working);
    436             /*End Testspace*/
    437452        }
    438453
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisher.cs

    r1137 r1139  
    5454        private void settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
    5555        {
    56             if (this.p2pPublisher == null || !this.p2pPublisher.Started)
     56            if (this.p2pControl == null || this.p2pPublisher == null)
    5757                return;
    58 
    5958
    6059            // storing settings for subscribers in the DHT, so they can load them there
     
    7574            if (e.PropertyName == "BtnUnregister")
    7675            {
    77                 this.p2pPublisher.Stop(PubSubMessageType.Unregister);
    78                 GuiLogMessage("Unregister button pressed, Publisher has stopped!", NotificationLevel.Info);
     76                if (this.p2pPublisher.Started)
     77                {
     78                    this.p2pPublisher.Stop(PubSubMessageType.Unregister);
     79                    GuiLogMessage("Unregister button pressed, Publisher has stopped!", NotificationLevel.Info);
     80                }
    7981            }
    8082            if (e.PropertyName == "BtnRegister")
    8183            {
    82                 this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
    83                 GuiLogMessage("Register button pressed, Publisher has been started!", NotificationLevel.Info);
     84                if (!this.p2pPublisher.Started)
     85                {
     86                    this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
     87                    GuiLogMessage("Register button pressed, Publisher has been started!", NotificationLevel.Info);
     88                }
    8489            }
    8590            if (e.PropertyName == "BtnSolutionFound")
    8691            {
    87                 this.p2pPublisher.Stop(PubSubMessageType.Solution);
    88                 GuiLogMessage("TEST: Emulate Solution-Found-message", NotificationLevel.Info);
     92                if (this.p2pPublisher.Started)
     93                {
     94                    this.p2pPublisher.Stop(PubSubMessageType.Solution);
     95                    GuiLogMessage("TEST: Emulate Solution-Found-message", NotificationLevel.Info);
     96                }
    8997            }
    9098            if (e.PropertyName == "BtnSerDeser")
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriber.cs

    r1068 r1139  
    185185        {
    186186            if(this.p2pSubscriber != null)
    187                 this.p2pSubscriber.Stop(PubSubMessageType.Unregister);
     187                this.p2pSubscriber.Stop(PubSubMessageType.Stop);
    188188        }
    189189
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberBase.cs

    r1137 r1139  
    55using Cryptool.PluginBase.Control;
    66using Cryptool.PluginBase;
    7 using System.Threading;
     7using System.Timers;
    88
    99/*
     
    106106        {
    107107            this.p2pControl = p2pControl;
     108
     109            this.timeoutForPublishersPong = new Timer();
     110            this.timeoutForPublishersRegAccept = new Timer();
     111            this.timerCheckPubAvailability = new Timer();
     112            this.timerRegisteringNotPossible = new Timer();
     113            this.timerSendingAliveMsg = new Timer();
    108114        }
    109115
    110116        public void Start(string sTopic, long checkPublishersAvailability, long publishersReplyTimespan)
    111117        {
     118            /* Initialize all timers */
     119            double pubTimeResponseTimeout = Convert.ToDouble(publishersReplyTimespan);
     120
     121            this.timeoutForPublishersPong.Interval = pubTimeResponseTimeout;
     122            this.timeoutForPublishersPong.Elapsed += new ElapsedEventHandler(OnTimeoutPublishersPong);
     123
     124            this.timeoutForPublishersRegAccept.Interval = pubTimeResponseTimeout;
     125            this.timeoutForPublishersRegAccept.Elapsed += new ElapsedEventHandler(OnTimeoutRegisteringAccepted);
     126
     127            this.timerCheckPubAvailability.Interval = Convert.ToDouble(checkPublishersAvailability);
     128            this.timerCheckPubAvailability.Elapsed += new ElapsedEventHandler(OnCheckPubAvailability);
     129
     130            this.timerRegisteringNotPossible.Interval = Convert.ToDouble(10000);
     131            this.timerRegisteringNotPossible.Elapsed += new ElapsedEventHandler(OnRegisteringNotPossible);
     132
    112133            this.sTopic = sTopic;
    113134            this.checkPublishersAvailability = checkPublishersAvailability;
     
    162183                case PubSubMessageType.RegisteringAccepted:
    163184                    GuiLogging("REGISTERING ACCEPTED received from publisher!", NotificationLevel.Info);
    164                     if (this.timeoutForPublishersRegAccept != null)
    165                     {
    166                         this.timeoutForPublishersRegAccept.Dispose();
    167                         this.timeoutForPublishersRegAccept = null;
    168                     }
     185                    this.timeoutForPublishersRegAccept.Stop();
    169186                    break;
    170187                case PubSubMessageType.Ping:
     
    188205                    break;
    189206                case PubSubMessageType.Pong:
    190                     if (this.timeoutForPublishersPong != null)
    191                     {
    192                         this.timeoutForPublishersPong.Dispose();
    193                         this.timeoutForPublishersPong = null;
    194                     }
     207                    this.timeoutForPublishersPong.Stop();
    195208                    break;
    196209                case PubSubMessageType.Alive:
     
    199212                    break;
    200213            }
     214            // workaround, because Timers.Timer doesn't contains a "Reset" method
     215            this.timerCheckPubAvailability.Enabled = false;
     216            this.timerCheckPubAvailability.Enabled = false;
    201217        }
    202218
     
    228244        private void SendMessage(PeerId pubPeerId, PubSubMessageType msgType)
    229245        {
    230             if (timerSendingAliveMsg == null && !this.bolStopped)
    231                 timerSendingAliveMsg = new Timer(OnSendAliveMessage, null, sendAliveMessageInterval, sendAliveMessageInterval);
    232 
    233246            switch (msgType)
    234247            {
    235248                case PubSubMessageType.Register:
    236249                    // stop "RegisteringNotPossibleTimer
    237                     if (timerRegisteringNotPossible != null)
    238                     {
    239                         timerRegisteringNotPossible.Dispose();
    240                         timerRegisteringNotPossible = null;
    241                     }
     250                    this.timerRegisteringNotPossible.Stop();
    242251                    // start waiting interval for RegAccept Message
    243                     if (this.timeoutForPublishersRegAccept == null)
    244                         this.timeoutForPublishersRegAccept = new Timer(OnTimeoutRegisteringAccepted, null, this.publisherReplyTimespan, this.publisherReplyTimespan);
     252                    this.timeoutForPublishersRegAccept.Stop();
    245253                    break;
    246254                case PubSubMessageType.Alive:
     
    259267                    return;
    260268            }
     269            // it doesn't care which message type was sent, but when it was sent to the publisher, reset this AliveMsg Timer
     270            if (pubPeerId == actualPublisher)
     271            {
     272                this.timerSendingAliveMsg.Enabled = false;
     273                this.timerSendingAliveMsg.Enabled = true;
     274            }
     275
    261276            this.p2pControl.SendToPeer(msgType, pubPeerId);
    262277
     
    266281        // registering isn't possible if no publisher has stored
    267282        // his ID in the DHT Entry with the Key TaskName
    268         private void OnRegisteringNotPossible(object state)
     283        private void OnRegisteringNotPossible(object sender, ElapsedEventArgs e)
    269284        {
    270285            Register();
     
    289304            if (pid == null)
    290305            {
    291                 if (timerRegisteringNotPossible == null && !this.bolStopped)
    292                 {
    293                     // if DHT value doesn't exist at this moment, wait for 10 seconds and try again
    294                     timerRegisteringNotPossible = new Timer(OnRegisteringNotPossible, null, 10000, 10000);
    295                 }
     306                this.timerRegisteringNotPossible.Start();
    296307                GuiLogging("Publisher wasn't found in DHT or settings didn't stored on the right way.", NotificationLevel.Debug);
    297308                return null;
     
    305316                return null;
    306317            }
     318            this.timerSendingAliveMsg.Interval = Convert.ToDouble(sendAliveMessageInterval);
     319            this.timerSendingAliveMsg.Start();
    307320
    308321            if (actualPublisher == null) //first time initialization
     
    314327            GuiLogging("RECEIVED: Publishers' peer ID '" + pid + "', Alive-Msg-Interval: " + sendAliveMessageInterval / 1000 + " sec!", NotificationLevel.Debug);
    315328
     329            this.timerCheckPubAvailability.Start();
    316330            // setting timer to check periodical the availability of the publishing peer
    317             if (timerCheckPubAvailability == null && !this.bolStopped)
    318                 timerCheckPubAvailability = new Timer(OnCheckPubAvailability, null, this.checkPublishersAvailability, this.checkPublishersAvailability);
    319331
    320332            return pid;
     
    327339        /// </summary>
    328340        /// <param name="state"></param>
    329         private void OnCheckPubAvailability(object state)
     341        private void OnCheckPubAvailability(object sender, ElapsedEventArgs e)
    330342        {
    331343            PeerId newPubId = CheckPublishersAvailability();
     
    336348                // a Pong-Response from the publisher!
    337349                SendMessage(actualPublisher, PubSubMessageType.Ping);
    338                 if (timeoutForPublishersPong == null)
    339                 {
    340                     timeoutForPublishersPong = new Timer(OnTimeoutPublishersPong, null, this.publisherReplyTimespan, this.publisherReplyTimespan);
    341                 }
     350                this.timeoutForPublishersPong.Start();
    342351            }
    343352        }
     
    347356        /// </summary>
    348357        /// <param name="state"></param>
    349         private void OnTimeoutRegisteringAccepted(object state)
     358        private void OnTimeoutRegisteringAccepted(object sender, ElapsedEventArgs e)
    350359        {
    351360            GuiLogging("TIMEOUT: Waiting for registering accepted message from publisher!", NotificationLevel.Debug);
     
    358367        /// </summary>
    359368        /// <param name="state"></param>
    360         private void OnTimeoutPublishersPong(object state)
     369        private void OnTimeoutPublishersPong(object sender, ElapsedEventArgs e)
    361370        {
    362371            GuiLogging("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Info);
    363             if (timeoutForPublishersPong != null)
    364             {
    365                 timeoutForPublishersPong.Dispose();
    366                 timeoutForPublishersPong = null;
    367             }
     372            this.timeoutForPublishersPong.Stop();
    368373            // try to get an active publisher and re-register
    369374            CheckPublishersAvailability();
     
    377382        public void Stop(PubSubMessageType msgType)
    378383        {
    379             this.bolStopped = true;
    380384            if (actualPublisher != null && msgType != PubSubMessageType.NULL)
    381385                SendMessage(actualPublisher, msgType);
    382386
    383387            #region stopping all timers, if they are still active
    384             if (this.timerSendingAliveMsg != null)
    385             {
    386                 this.timerSendingAliveMsg.Dispose();
    387                 this.timerSendingAliveMsg = null;
    388             }
    389             if (this.timerRegisteringNotPossible != null)
    390             {
    391                 this.timerRegisteringNotPossible.Dispose();
    392                 this.timerRegisteringNotPossible = null;
    393             }
    394             if (this.timerCheckPubAvailability != null)
    395             {
    396                 this.timerCheckPubAvailability.Dispose();
    397                 this.timerCheckPubAvailability = null;
    398             }
    399             if (this.timeoutForPublishersRegAccept != null)
    400             {
    401                 this.timeoutForPublishersRegAccept.Dispose();
    402                 this.timeoutForPublishersRegAccept = null;
    403             }
    404             if (this.timeoutForPublishersPong != null)
    405             {
    406                 this.timeoutForPublishersPong.Dispose();
    407                 this.timeoutForPublishersPong = null;
     388
     389            this.timeoutForPublishersPong.Stop();
     390            this.timeoutForPublishersRegAccept.Stop();
     391            this.timerSendingAliveMsg.Stop();
     392            this.timerCheckPubAvailability.Start();
     393
     394            //when Sub received a UnReg message, it haven't stop
     395            //the registering not possible worker, to connect to
     396            //a new incoming Publisher
     397            if (msgType == PubSubMessageType.Stop)
     398            {
     399                this.bolStopped = true;
     400
     401                this.timerRegisteringNotPossible.Stop();
     402
     403                this.Started = false;
     404                this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
     405                this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
     406                GuiLogging("Subscriber/Worker is completely stopped", NotificationLevel.Debug);
     407            }
     408            else
     409            {
     410                GuiLogging("Publisher/Manager had left the network, waiting for its comeback or takeover by a new Publisher/Manager.", NotificationLevel.Info);
    408411            }
    409412            #endregion
    410413            GuiLogging("All Timers were stopped successfully", NotificationLevel.Debug);
    411 
    412             this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
    413             this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
    414 
    415             this.Started = false;
    416             GuiLogging("Subscriber is completely stopped", NotificationLevel.Debug);
    417414        }
    418415
     
    424421    }
    425422}
    426 
    427 
    428 //using System;
    429 //using System.Collections.Generic;
    430 //using System.Linq;
    431 //using System.Text;
    432 //using Cryptool.PluginBase.Control;
    433 //using Cryptool.PluginBase;
    434 //using System.Threading;
    435 
    436 ///*
    437 // * All Subscriber functions work problem-free!
    438 // *
    439 // * IDEAS:
    440 // * - Publisher takes subscriber list out of the DHT and registered
    441 // *   itself with all subscribers pro-active (handle Register-Msg in Subscriber!)
    442 // */
    443 
    444 //namespace Cryptool.Plugins.PeerToPeer
    445 //{
    446 //    public class P2PSubscriberBase
    447 //    {
    448 //        public delegate void GuiMessage(string sData, NotificationLevel notificationLevel);
    449 //        public event GuiMessage OnGuiMessage;
    450 //        public delegate void TextArrivedFromPublisher(byte[] data, PeerId pid);
    451 //        public event TextArrivedFromPublisher OnTextArrivedFromPublisher;
    452 //        public delegate void ReceivedStopFromPublisher(PubSubMessageType stopType, string sData);
    453 //        /// <summary>
    454 //        /// fired when Manager sent "stop" message to the worker.
    455 //        /// </summary>
    456 //        public event ReceivedStopFromPublisher OnReceivedStopMessageFromPublisher;
    457 
    458 //        #region Variables
    459 
    460 //        protected IP2PControl p2pControl;
    461 //        private long sendAliveMessageInterval;
    462 //        private long checkPublishersAvailability;
    463 //        private long publisherReplyTimespan;
    464 //        private string sTopic;
    465 
    466 //        /// <summary>
    467 //        /// If the DHT Entry of the given Task is empty, continous try to
    468 //        /// find a meanwhile inscribed Publishers PeerID
    469 //        /// </summary>
    470 //        private Timer timerRegisteringNotPossible;
    471 //        /// <summary>
    472 //        /// For informing the publisher pro-active, that this subscriber
    473 //        /// is still interested in this Task.
    474 //        /// </summary>
    475 //        private Timer timerSendingAliveMsg;
    476 //        /// <summary>
    477 //        /// checking liveness, availability and/or changes (new peer) of the Publisher
    478 //        /// </summary>
    479 //        private Timer timerCheckPubAvailability;
    480 //        /// <summary>
    481 //        /// this timer gets started when the availability of the publisher,
    482 //        /// at which the subscriber had registered, is checked. If the timer
    483 //        /// callback is called and no Pong-message was received, the probability
    484 //        /// that the Publisher is down is high!
    485 //        /// </summary>
    486 //        private Timer timeoutForPublishersPong;
    487 //        /// <summary>
    488 //        /// After register message is sent to publisher, this timer gets started.
    489 //        /// If the publisher doesn't response with a RegisteringAccepted-Message,
    490 //        /// the probability that the publisher is down is high!
    491 //        /// </summary>
    492 //        private Timer timeoutForPublishersRegAccept;
    493 //        /// <summary>
    494 //        /// PeerID of the actual publisher. This ID is will be checked continious
    495 //        /// on liveliness and/or updated if Publisher had changed.
    496 //        /// </summary>
    497 //        private PeerId actualPublisher;
    498 //        /// <summary>
    499 //        /// PeerID of the actual publisher. This ID is will be checked continious
    500 //        /// on liveliness and/or updated if Publisher had changed
    501 //        /// </summary>
    502 //        public PeerId ActualPublisher
    503 //        {
    504 //            get { return this.actualPublisher; }
    505 //        }
    506 
    507 //        /// <summary>
    508 //        /// if true, check whether a new Publisher is the actual one
    509 //        /// and renew Settings
    510 //        /// </summary>
    511 //        private bool bolStopped = true;
    512 
    513 //        private bool started = false;
    514 //        /// <summary>
    515 //        /// Status flag which contains the state of the Subscriber
    516 //        /// </summary>
    517 //        public bool Started
    518 //        {
    519 //            get { return this.started;  }
    520 //            private set { this.started = value;  }
    521 //        }
    522 
    523 //        #endregion
    524 
    525 //        /* BEGIN: Only for experimental cases */
    526 
    527 //        public void SolutionFound(byte[] solutionData)
    528 //        {
    529 //            SendMessage(actualPublisher, PubSubMessageType.Solution);
    530 //            this.p2pControl.SendToPeer(solutionData, actualPublisher);
    531 //        }
    532 
    533 //        /* END: Only for experimental cases - 2010.02.07  */
    534 
    535 //        /* BEGIN: Added for P2PJobAdmin */
    536 //        public P2PSubscriberBase()
    537 //        {
    538 //        }
    539 
    540 //        public void Start(IP2PControl p2pControl, string sTopic, long checkPublishersAvailability, long publishersReplyTimespan)
    541 //        {
    542 //            this.p2pControl = p2pControl;
    543 //            Start(sTopic, checkPublishersAvailability, publisherReplyTimespan);
    544 //        }
    545 //        /* END: Added for P2PJobAdmin - 2010.02.07 */
    546 
    547 //        public P2PSubscriberBase(IP2PControl p2pControl)
    548 //        {
    549 //            this.p2pControl = p2pControl;
    550 //        }     
    551 
    552 //        public void Start(string sTopic, long checkPublishersAvailability, long publishersReplyTimespan)
    553 //        {
    554 //            this.sTopic = sTopic;
    555 //            this.checkPublishersAvailability = checkPublishersAvailability;
    556 //            this.publisherReplyTimespan = publishersReplyTimespan;
    557 //            Register();
    558 //        }
    559 
    560 //        private void Register()
    561 //        {
    562 //            // Unfortunately you have to register this events every time, because this events will be deregistered, when
    563 //            // Publisher/Manager sends a Unregister/Stop-Message... There isn't any possibility to check,
    564 //            // whether the Events are already registered (if(dings != null) or anything else).
    565 //            this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
    566 //            this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
    567 //            this.p2pControl.OnPayloadMessageReceived += new P2PPayloadMessageReceived(p2pControl_OnPayloadMessageReceived);
    568 //            this.p2pControl.OnSystemMessageReceived += new P2PSystemMessageReceived(p2pControl_OnSystemMessageReceived);
    569 
    570 //            // because CheckPublishersAvailability checks this value, set it for the first time here...
    571 //            // if bolStopped = true, the Timer for Checking Publishers liveliness doesn't start
    572 //            this.bolStopped = false;
    573 //            PeerId pubId = CheckPublishersAvailability();
    574 //            // if DHT Entry for the task is empty, no Publisher exists at present.
    575 //            // The method CheckPublishersAvailability starts a Timer for this case to continous proof Publisher-DHT-Entry
    576 //            if (pubId == null)
    577 //            {
    578 //                this.Started = false;
    579 //                // if PubId is null, the Publisher isn't started!
    580 //                this.bolStopped = true;
    581 //                GuiLogging("No publisher for registering found.", NotificationLevel.Info);
    582 //                return;
    583 //            }
    584 
    585 //            // when the actual publisher differs from the new detected publisher, change it
    586 //            if (pubId != null && (actualPublisher != null && actualPublisher != pubId))
    587 //            {
    588 //                GuiLogging("Publisher has been changed from ID '" + actualPublisher + "' to '" + pubId + "'", NotificationLevel.Debug);
    589 //                actualPublisher = pubId;
    590 //            }
    591 //            SendMessage(pubId, PubSubMessageType.Register);
    592 //            this.started = true;
    593 //        }
    594 
    595 //        private void p2pControl_OnSystemMessageReceived(PeerId sender, PubSubMessageType msgType)
    596 //        {
    597 //            if (sender != actualPublisher)
    598 //            {
    599 //                GuiLogging("RECEIVED message from third party peer (not the publisher!): " + msgType.ToString() + ", ID: " + sender, NotificationLevel.Debug);
    600 //                return;
    601 //            }
    602 //            switch (msgType)
    603 //            {
    604 //                case PubSubMessageType.RegisteringAccepted:
    605 //                    GuiLogging("REGISTERING ACCEPTED received from publisher!", NotificationLevel.Info);
    606 //                    if (this.timeoutForPublishersRegAccept != null)
    607 //                    {
    608 //                        this.timeoutForPublishersRegAccept.Dispose();
    609 //                        this.timeoutForPublishersRegAccept = null;
    610 //                    }
    611 //                    break;
    612 //                case PubSubMessageType.Ping:
    613 //                    SendMessage(sender, PubSubMessageType.Pong);
    614 //                    GuiLogging("REPLIED to a ping message from " + sender, NotificationLevel.Debug);
    615 //                    break;
    616 //                case PubSubMessageType.Register:
    617 //                case PubSubMessageType.Unregister:
    618 //                    GuiLogging(msgType.ToString().ToUpper() + " received from PUBLISHER.", NotificationLevel.Debug);
    619 //                    // continuously try to get a unregister and than re-register with publisher
    620 //                    Stop(msgType);
    621 //                    Register();
    622 //                    break;
    623 //                case PubSubMessageType.Solution:
    624 //                    Stop(msgType);
    625 //                    GuiLogging("Another Subscriber had found the solution!", NotificationLevel.Info);
    626 //                    break;
    627 //                case PubSubMessageType.Stop:
    628 //                    Stop(msgType);
    629 //                    GuiLogging("STOP received from publisher. Subscriber is stopped!", NotificationLevel.Warning);
    630 //                    break;
    631 //                case PubSubMessageType.Pong:
    632 //                    if (this.timeoutForPublishersPong != null)
    633 //                    {
    634 //                        this.timeoutForPublishersPong.Dispose();
    635 //                        this.timeoutForPublishersPong = null;
    636 //                    }
    637 //                    break;
    638 //                case PubSubMessageType.Alive:
    639 //                default:
    640 //                    // not possible at the moment
    641 //                    break;
    642 //            }
    643 //        }
    644 
    645 //        private void p2pControl_OnPayloadMessageReceived(PeerId sender, byte[] data)
    646 //        {
    647 //            if (sender != actualPublisher)
    648 //            {
    649 //                GuiLogging("RECEIVED message from third party peer (not the publisher!): " + UTF8Encoding.UTF8.GetString(data) + ", ID: " + sender, NotificationLevel.Debug);
    650 //                return;
    651 //            }
    652 //            // functionality swapped for better inheritance
    653 //            HandleIncomingData(sender, data);
    654 //        }
    655 
    656 //        /// <summary>
    657 //        /// Incoming data will be printed in the information field and the OnTextArrivedEvent will be thrown
    658 //        /// </summary>
    659 //        /// <param name="senderId"></param>
    660 //        /// <param name="sData"></param>
    661 //        protected virtual void HandleIncomingData(PeerId senderId, byte[] data)
    662 //        {
    663 //            GuiLogging("RECEIVED: Message from '" + senderId
    664 //                    + "' with data: '" + UTF8Encoding.UTF8.GetString(data) + "'", NotificationLevel.Debug);
    665 
    666 //            if (OnTextArrivedFromPublisher != null)
    667 //                OnTextArrivedFromPublisher(data, senderId);
    668 //        }
    669 
    670 //        private void SendMessage(PeerId pubPeerId, PubSubMessageType msgType)
    671 //        {
    672 //            if (timerSendingAliveMsg == null && !this.bolStopped)
    673 //                timerSendingAliveMsg = new Timer(OnSendAliveMessage, null, sendAliveMessageInterval, sendAliveMessageInterval);
    674 
    675 //            switch (msgType)
    676 //            {
    677 //                case PubSubMessageType.Register:
    678 //                    // stop "RegisteringNotPossibleTimer
    679 //                    if (timerRegisteringNotPossible != null)
    680 //                    {
    681 //                        timerRegisteringNotPossible.Dispose();
    682 //                        timerRegisteringNotPossible = null;
    683 //                    }
    684 //                    // start waiting interval for RegAccept Message
    685 //                    if (this.timeoutForPublishersRegAccept == null)
    686 //                        this.timeoutForPublishersRegAccept = new Timer(OnTimeoutRegisteringAccepted, null, this.publisherReplyTimespan, this.publisherReplyTimespan);
    687 //                    break;
    688 //                case PubSubMessageType.Alive:
    689 //                case PubSubMessageType.Ping:
    690 //                case PubSubMessageType.Pong:
    691 //                case PubSubMessageType.Unregister:
    692 //                case PubSubMessageType.Stop:
    693 //                case PubSubMessageType.Solution:
    694 //                    break;
    695 //                //case PubSubMessageType.Solution:
    696 //                //    // when i send Solution to the Stop method, we will run into a recursive loop between SendMessage and Stop!
    697 //                //    Stop(PubSubMessageType.NULL);
    698 //                //    break;
    699 //                default:
    700 //                    GuiLogging("No Message sent, because MessageType wasn't supported: " + msgType.ToString(), NotificationLevel.Warning);
    701 //                    return;
    702 //            }
    703 //            this.p2pControl.SendToPeer(msgType, pubPeerId);
    704 
    705 //            GuiLogging(msgType.ToString() + " message sent to Publisher", NotificationLevel.Debug);
    706 //        }
    707 
    708 //        // registering isn't possible if no publisher has stored
    709 //        // its ID in the DHT Entry with the Key TaskName
    710 //        private void OnRegisteringNotPossible(object state)
    711 //        {
    712 //            Register();
    713 //        }
    714 
    715 //        private void OnSendAliveMessage(object state)
    716 //        {
    717 //            SendMessage(actualPublisher, PubSubMessageType.Alive);
    718 //        }
    719 
    720 //        /// <summary>
    721 //        /// Returns the actual Publishers ID or null, when a publisher wasn't found in the DHT. In the second case,
    722 //        /// a Timer will be started, to check periodically the DHT entry.
    723 //        /// When the publishers entry changed the Publishers ID, a Register-message will be send to the new Publisher.
    724 //        /// The Timer for periodically checking the Publishers availability is also started here.
    725 //        /// </summary>
    726 //        /// <returns>the actual Publishers ID or null, when a publisher wasn't found in the DHT</returns>
    727 //        private PeerId CheckPublishersAvailability()
    728 //        {
    729 //            PeerId pid = DHT_CommonManagement.GetTopicsPublisherId(ref this.p2pControl, this.sTopic);
    730 
    731 //            if (pid == null)
    732 //            {
    733 //                if (timerRegisteringNotPossible == null && !this.bolStopped)
    734 //                {
    735 //                    // if DHT value doesn't exist at this moment, wait for 10 seconds and try again
    736 //                    timerRegisteringNotPossible = new Timer(OnRegisteringNotPossible, null, 10000, 10000);
    737 //                }
    738 //                GuiLogging("Publisher wasn't found in DHT or settings didn't stored on the right way.", NotificationLevel.Debug);
    739 //                return null;
    740 //            }
    741 
    742 //            sendAliveMessageInterval = DHT_CommonManagement.GetAliveMessageInterval(ref this.p2pControl, this.sTopic);
    743 
    744 //            if (sendAliveMessageInterval == 0)
    745 //            {
    746 //                GuiLogging("Can't find AliveMsg-Settings from Publisher for the Subscriber.", NotificationLevel.Error);
    747 //                return null;
    748 //            }
    749 
    750 //            if (actualPublisher == null) //first time initialization
    751 //            {
    752 //                actualPublisher = pid;
    753 //                GuiLogging("First time received publishers ID.", NotificationLevel.Debug);
    754 //            }
    755 //            //else if (actualPublisher != pid)
    756 //            //{
    757 //            //    GuiLogging("Publisher has been changed from ID '" + actualPublisher + "' to '" + pubId + "'", NotificationLevel.Debug);
    758 //            //    SendMessage(pubId, PubSubMessageType.Register);
    759 //            //    actualPublisher = pid;
    760 //            //}
    761 
    762 //            GuiLogging("RECEIVED: Publishers' peer ID '" + pid + "', Alive-Msg-Interval: " + sendAliveMessageInterval / 1000 + " sec!", NotificationLevel.Debug);
    763 
    764 //            // setting timer to check periodical the availability of the publishing peer
    765 //            if (timerCheckPubAvailability == null && !this.bolStopped)
    766 //                timerCheckPubAvailability = new Timer(OnCheckPubAvailability, null, this.checkPublishersAvailability, this.checkPublishersAvailability);
    767 
    768 //            return pid;
    769 //        }
    770 
    771 //        /// <summary>
    772 //        /// Callback for timerCheckPubAvailability (adjustable parameter
    773 //        /// in settings, usually every 60 seconds). If another Peer
    774 //        /// takes over Publishing the Task, this will be handled in this callback, too.
    775 //        /// </summary>
    776 //        /// <param name="state"></param>
    777 //        private void OnCheckPubAvailability(object state)
    778 //        {
    779 //            PeerId newPubId = CheckPublishersAvailability();
    780 
    781 //            if (newPubId == actualPublisher)
    782 //            {
    783 //                // Timer will be only stopped, when OnMessageReceived-Event received
    784 //                // a Pong-Response from the publisher!
    785 //                SendMessage(actualPublisher, PubSubMessageType.Ping);
    786 //                if (timeoutForPublishersPong == null)
    787 //                {
    788 //                    timeoutForPublishersPong = new Timer(OnTimeoutPublishersPong, null, this.publisherReplyTimespan, this.publisherReplyTimespan);
    789 //                }
    790 //            }
    791 //            if (newPubId != actualPublisher)
    792 //                Register();
    793 //        }
    794 
    795 //        /// <summary>
    796 //        /// This callback is only fired, when the publisher didn't sent a response on the register message.
    797 //        /// </summary>
    798 //        /// <param name="state"></param>
    799 //        private void OnTimeoutRegisteringAccepted(object state)
    800 //        {
    801 //            GuiLogging("TIMEOUT: Waiting for registering accepted message from publisher!", NotificationLevel.Debug);
    802 //            // try to register again
    803 //            Register();
    804 //        }
    805 
    806 //        /// <summary>
    807 //        /// This callback os only fired, when the publisher didn't sent a response on the ping message.
    808 //        /// </summary>
    809 //        /// <param name="state"></param>
    810 //        private void OnTimeoutPublishersPong(object state)
    811 //        {
    812 //            GuiLogging("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Warning);
    813 //            if (timeoutForPublishersPong != null)
    814 //            {
    815 //                timeoutForPublishersPong.Dispose();
    816 //                timeoutForPublishersPong = null;
    817 //            }
    818 //            // try to get an active publisher and re-register
    819 //            CheckPublishersAvailability();
    820 //        }
    821 
    822 //        /// <summary>
    823 //        /// Will stop all timers, so Subscriber ends with sending
    824 //        /// Register-, Alive- and Pong-messages. Furthermore an
    825 //        /// unregister message will be send to the publisher
    826 //        /// </summary>
    827 //        public void Stop(PubSubMessageType msgType)
    828 //        {
    829 //            this.bolStopped = true;
    830 //            if (actualPublisher != null && msgType != PubSubMessageType.NULL)
    831 //                SendMessage(actualPublisher, msgType);
    832 
    833 //            #region stopping all timers, if they are still active
    834 //            if (this.timerSendingAliveMsg != null)
    835 //            {
    836 //                this.timerSendingAliveMsg.Dispose();
    837 //                this.timerSendingAliveMsg = null;
    838 //            }
    839 //            if (this.timerRegisteringNotPossible != null)
    840 //            {
    841 //                this.timerRegisteringNotPossible.Dispose();
    842 //                this.timerRegisteringNotPossible = null;
    843 //            }
    844 //            if (this.timerCheckPubAvailability != null)
    845 //            {
    846 //                this.timerCheckPubAvailability.Dispose();
    847 //                this.timerCheckPubAvailability = null;
    848 //            }
    849 //            if (this.timeoutForPublishersRegAccept != null)
    850 //            {
    851 //                this.timeoutForPublishersRegAccept.Dispose();
    852 //                this.timeoutForPublishersRegAccept = null;
    853 //            }
    854 //            if (this.timeoutForPublishersPong != null)
    855 //            {
    856 //                this.timeoutForPublishersPong.Dispose();
    857 //                this.timeoutForPublishersPong = null;
    858 //            }
    859 //            #endregion
    860 //            GuiLogging("All Timers were stopped successfully", NotificationLevel.Debug);
    861 
    862 //            this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
    863 //            this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
    864 
    865 //            this.Started = false;
    866 //            GuiLogging("Subscriber is completely stopped",NotificationLevel.Debug);
    867 //        }
    868 
    869 //        protected void GuiLogging(string sText, NotificationLevel notLev)
    870 //        {
    871 //            if (OnGuiMessage != null)
    872 //                OnGuiMessage(sText, notLev);
    873 //        }
    874 //    }
    875 //}
  • trunk/CrypPlugins/PeerToPeerWorker_NEW/IControlWorker.cs

    r1137 r1139  
    3737        /// <summary>
    3838        /// tries to deserialize byte representation of a job. If this is possible,
    39         /// JobAccepted event will be thrown, otherwise JobDeclined event will be thrown
     39        /// JobAccepted event will be thrown, otherwise JobDeclined event will be thrown.
     40        /// Catch OnProcessingStarted-Event to get result of this operation!
    4041        /// </summary>
    4142        /// <param name="job">byte representation of a job</param>
    42         /// <returns>true, if deserialization was possible and jobType was accepted, otherwise false</returns>
    4343        bool StartProcessing(byte[] job, out BigInteger jobId);
    4444        void StopProcessing();
  • trunk/CrypPlugins/PeerToPeerWorker_NEW/P2PJobAdmin.cs

    r1137 r1139  
    193193            if (this.jobAdminBase != null && this.jobAdminBase.Started)
    194194            {
    195                 this.jobAdminBase.StopWorkerControl(PubSubMessageType.Unregister);
     195                this.jobAdminBase.StopWorkerControl(PubSubMessageType.Stop);
    196196            }
    197197        }
     
    205205            if (this.jobAdminBase != null && this.jobAdminBase.Started)
    206206            {
    207                 this.jobAdminBase.StopWorkerControl(PubSubMessageType.Unregister);
     207                this.jobAdminBase.StopWorkerControl(PubSubMessageType.Stop);
    208208            }
    209209        }
Note: See TracChangeset for help on using the changeset viewer.