Ignore:
Timestamp:
Dec 12, 2009, 2:07:52 PM (12 years ago)
Author:
arnold
Message:

executable, but non-optimized P2PManager/Worker System

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberBase.cs

    r971 r980  
    101101        {
    102102            this.p2pControl = p2pControl;
    103             this.p2pControl.OnPeerReceivedMsg +=new P2PBase.P2PMessageReceived(MessageReceived);
    104103        }
    105104
    106105        public void Register(string sTopic, long checkPublishersAvailability, long publishersReplyTimespan)
    107106        {
     107            this.p2pControl.OnPeerReceivedMsg += new P2PBase.P2PMessageReceived(MessageReceived);
     108
    108109            this.sTopic = sTopic;
    109110            this.checkPublishersAvailability = checkPublishersAvailability;
     
    135136            if (sourceAddr.stringId != actualPublisher.stringId)
    136137            {
    137                 GuiLogging("RECEIVED message from third party peer (not the publisher!): " + sData.Trim() + ", ID: " + sourceAddr.stringId, NotificationLevel.Info);
     138                GuiLogging("RECEIVED message from third party peer (not the publisher!): " + sData.Trim() + ", ID: " + sourceAddr.stringId, NotificationLevel.Debug);
    138139                return;
    139140            }
     
    153154                case PubSubMessageType.Ping:
    154155                    SendMessage(sourceAddr, PubSubMessageType.Pong);
    155                     GuiLogging("REPLIED to a ping message from " + sourceAddr, NotificationLevel.Info);
     156                    GuiLogging("REPLIED to a ping message from " + sourceAddr, NotificationLevel.Debug);
    156157                    break;
    157158                case PubSubMessageType.Register:
     
    181182                case PubSubMessageType.NULL:
    182183                    // functionality swapped for better inheritance
    183                     HandleIncomingData(sourceAddr, sData);
    184 
     184                    Thread handlingOtherIncomingData = new Thread(new ParameterizedThreadStart(HandleIncomingData));
     185                    handlingOtherIncomingData.Start(new IncomingData(sourceAddr, sData));
    185186                    break;
    186187                case PubSubMessageType.Alive:
     
    191192        }
    192193
     194        // helper class to realize the necessary two parameters for the threading method HandleIncomingMethod
     195        private class IncomingData
     196        {
     197            public PeerId sourceAddr = null;
     198            public string sData = null;
     199
     200            public IncomingData(PeerId sourceAddr, string sData)
     201            {
     202                this.sourceAddr = sourceAddr;
     203                this.sData = sData;
     204            }
     205        }
     206
     207        private void HandleIncomingData(object incomData)
     208        {
     209            if (incomData is IncomingData)
     210            {
     211                IncomingData incomingData = incomData as IncomingData;
     212                HandleIncomingData(incomingData.sourceAddr, incomingData.sData);
     213            }
     214            else
     215            {
     216                throw (new Exception("Wrong object type in HandleIncomingData"));
     217            }
     218        }
     219
    193220        /// <summary>
    194221        /// Incoming data will be printed in the information field and the OnTextArrivedEvent will be thrown
     
    199226        {
    200227            GuiLogging("RECEIVED: Message from '" + senderId.stringId
    201                     + "' with data: '" + sData + "'", NotificationLevel.Info);
     228                    + "' with data: '" + sData + "'", NotificationLevel.Debug);
    202229
    203230            if (OnTextArrivedFromPublisher != null)
     
    224251                case PubSubMessageType.Pong:
    225252                case PubSubMessageType.Unregister:
    226                     break;
     253                case PubSubMessageType.Stop:
     254
    227255                case PubSubMessageType.Solution:
    228                     // when i send Solution to the Stop method, we will run into a recursive loop between SendMessage and Stop!
    229                     Stop(PubSubMessageType.NULL);
    230                     break;
     256                    break;
     257                //case PubSubMessageType.Solution:
     258                //    // when i send Solution to the Stop method, we will run into a recursive loop between SendMessage and Stop!
     259                //    Stop(PubSubMessageType.NULL);
     260                //    break;
    231261                default:
    232262                    GuiLogging("No Message sent, because MessageType wasn't supported: " + msgType.ToString(), NotificationLevel.Warning);
     
    237267            // don't show every single alive message
    238268            if (msgType != PubSubMessageType.Alive)
    239                 GuiLogging(msgType.ToString() + " message sent to Publisher", NotificationLevel.Info);
     269                GuiLogging(msgType.ToString() + " message sent to Publisher", NotificationLevel.Debug);
    240270        }
    241271
     
    348378        {
    349379            GuiLogging("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Warning);
    350             timeoutForPublishersPong.Dispose();
    351             timeoutForPublishersPong = null;
     380            if (timeoutForPublishersPong != null)
     381            {
     382                timeoutForPublishersPong.Dispose();
     383                timeoutForPublishersPong = null;
     384            }
    352385            // try to get an active publisher and re-register
    353386            CheckPublisherAvailability();
     
    393426            #endregion
    394427
     428            this.p2pControl.OnPeerReceivedMsg -= MessageReceived;
     429
    395430            this.Started = false;
    396431        }
Note: See TracChangeset for help on using the changeset viewer.