Changeset 872


Ignore:
Timestamp:
Nov 19, 2009, 6:03:03 PM (12 years ago)
Author:
arnold
Message:

Important updates for P2PBase, P2PPublisher and P2PSubscriber.

Location:
trunk/CrypPlugins
Files:
3 added
48 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/PeerToPeerBase/IP2PControl.cs

    r862 r872  
    8383        bool DHTremove(string sKey);
    8484
    85         string GetPeerID(out string sPeerName);
     85        PeerId GetPeerID(out string sPeerName);
    8686        //byte[] GetPeerID(out string sPeerName);
    8787
    88         void SendToPeer(string sData, byte[] sDestinationPeerAddress);
    89         void SendToPeer(string sData, string sDestinationPeerAddress);
    90         void SendToPeer(PubSubMessageType msgType, string sDestinationAddress);
     88        void SendToPeer(string sData, PeerId destinationAddress);
     89        //void SendToPeer(string sData, byte[] sDestinationPeerAddress);
     90        //void SendToPeer(string sData, string sDestinationPeerAddress);
     91        void SendToPeer(PubSubMessageType msgType, PeerId sDestinationAddress);
     92        void SendToPeer(string sData, byte[] destinationAddress);
     93        //void SendToPeer(PubSubMessageType msgType, string sDestinationAddress);
    9194
    9295        PubSubMessageType GetMsgType(string byteData);
     96        string ConvertIdToString(byte[] byteId);
    9397
    9498        event P2PBase.P2PMessageReceived OnPeerReceivedMsg;
  • trunk/CrypPlugins/PeerToPeerBase/P2PPeer.cs

    r862 r872  
    2525using Cryptool.PluginBase.IO;
    2626
    27 
    28 /*
    29  * TODO:
    30  * - Build a stable P2PPeer Version (only valid when initialized!)
    31  * - Integrate struct PeerId into functions and other classes,
    32  *   particularly P2PPublisherBase
    33  */
    3427namespace Cryptool.Plugins.PeerToPeer
    3528{
     
    7366
    7467        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    75         private void p2pBase_OnP2PMessageReceived(string sSourceAddr, string sData)
     68        private void p2pBase_OnP2PMessageReceived(PeerId sourceAddr, string sData)
    7669        {
    7770            if (OnPeerMessageReceived != null)
    78                 OnPeerMessageReceived(sSourceAddr, sData);
     71                OnPeerMessageReceived(sourceAddr, sData);
    7972        }
    8073
     
    196189        /// </summary>
    197190        private bool peerStarted = false;
     191        /// <summary>
     192        /// Status flag for starting and stopping peer only once.
     193        /// </summary>
     194        public bool PeerStarted
     195        {
     196            get { return this.peerStarted; }
     197            private set { this.peerStarted = value; }
     198        }
    198199
    199200        public void StartPeer()
    200201        {
    201             if (!this.peerStarted)
     202            if (!this.PeerStarted)
    202203            {
    203204                if (this.p2pBase == null)
     
    213214                    (P2PLinkManagerType)this.settings.P2PLinkMngrType, (P2PBootstrapperType)this.settings.P2PBSType,
    214215                    (P2POverlayType)this.settings.P2POverlType, (P2PDHTType)this.settings.P2PDhtType);
    215                 this.peerStarted = this.p2pBase.SynchStart();
    216 
    217                 if (this.peerStarted)
     216                this.PeerStarted = this.p2pBase.SynchStart();
     217
     218                if (this.PeerStarted)
    218219                {
    219220                    this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
     
    228229            else
    229230            {
    230                 GuiLogMessage("Peer is already started!", NotificationLevel.Warning);
     231                GuiLogMessage("Peer is already started!", NotificationLevel.Info);
    231232            }
    232233        }
     
    234235        public void StopPeer()
    235236        {
    236             if (this.peerStarted && this.p2pBase != null)
     237            if (this.PeerStarted && this.p2pBase != null)
    237238            {
    238239                this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Connecting);
    239240
    240                 this.peerStarted = !this.p2pBase.SynchStop();
    241 
    242                 if (this.peerStarted)
     241                this.PeerStarted = !this.p2pBase.SynchStop();
     242
     243                if (this.PeerStarted)
    243244                {
    244245                    this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.Online);
    245                     GuiLogMessage("Peer stopped: " + !this.peerStarted, NotificationLevel.Warning);
     246                    GuiLogMessage("Peer stopped: " + !this.PeerStarted, NotificationLevel.Warning);
    246247                }
    247248                else
    248249                {
    249250                    this.settings.PeerStatusChanged(P2PPeerSettings.PeerStatus.NotConnected);
    250                     GuiLogMessage("Peer stopped: " + !this.peerStarted, NotificationLevel.Info);
     251                    GuiLogMessage("Peer stopped: " + !this.PeerStarted, NotificationLevel.Info);
    251252                }
    252253            }
    253254            else
    254255            {
    255                 GuiLogMessage("Peer is already stopped!", NotificationLevel.Warning);
     256                GuiLogMessage("Peer is already stopped!", NotificationLevel.Info);
    256257            }
    257258        }
     
    267268    public class P2PPeerMaster : IP2PControl
    268269    {
     270        private AutoResetEvent systemJoined;
    269271        private P2PPeer p2pPeer;
    270         private string sPeerID;
     272        private PeerId peerID;
    271273        private string sPeerName;
    272274
    273         /* Required because comparing a byte-array is inefficient */
    274         // TODO: Previously unused!
    275         public struct PeerId
    276         {
    277             string stringId;
    278             byte[] byteId;
    279         }
    280 
    281275        public P2PPeerMaster(P2PPeer p2pPeer)
    282276        {
    283277            this.p2pPeer = p2pPeer;
    284             //if (this.p2pPeer.p2pBase == null && this.p2pPeer.p2pBase.Initialized)
    285             //{
    286             //    throw (new Exception("P2PBase isn't completely initialized!"));
    287             //}
    288             // to forward event from overlay/dht MessageReceived-Event from P2PBase
     278            this.systemJoined = new AutoResetEvent(false);
     279
     280            this.p2pPeer.p2pBase.OnSystemJoined += new P2PBase.SystemJoined(p2pBase_OnSystemJoined);
    289281            this.p2pPeer.OnPeerMessageReceived += new P2PBase.P2PMessageReceived(p2pPeer_OnPeerMessageReceived);
    290282            this.OnStatusChanged += new IControlStatusChangedEventHandler(P2PPeerMaster_OnStatusChanged);
     
    292284
    293285        #region Events and Event-Handling
     286       
     287        private void p2pBase_OnSystemJoined()
     288        {
     289            systemJoined.Set();
     290        }
    294291
    295292        // to forward event from overlay/dht MessageReceived-Event from P2PBase
    296293        public event P2PBase.P2PMessageReceived OnPeerReceivedMsg;
    297         private void p2pPeer_OnPeerMessageReceived(string sSourceAddr, string sData)
     294        private void p2pPeer_OnPeerMessageReceived(PeerId sourceAddr, string sData)
    298295        {
    299296            if (OnPeerReceivedMsg != null)
    300                 OnPeerReceivedMsg(sSourceAddr, sData);
     297                OnPeerReceivedMsg(sourceAddr, sData);
    301298        }
    302299
     
    310307        #endregion
    311308
     309        /// <summary>
     310        /// workaround method. If the PAP functions are used, but the PAP system isn't
     311        /// started yet. This could happen because of the plugin hierarchy and
     312        /// when a p2p-using plugin uses PAP functions in the PreExecution method,
     313        /// this could run into a race condition (peer plugin not computed by the CT-system
     314        /// yet, but p2p-using plugin is already executed)
     315        /// </summary>
     316        /// <returns></returns>
     317        private bool SystemJoinedCompletely()
     318        {
     319            if (!this.p2pPeer.PeerStarted)
     320            {
     321                this.p2pPeer.StartPeer();
     322                this.systemJoined.WaitOne();
     323            }
     324            return true;
     325        }
     326
    312327        #region IP2PControl Members
    313328
    314329        public bool DHTstore(string sKey, byte[] byteValue)
    315330        {
    316             return this.p2pPeer.p2pBase.SynchStore(sKey, byteValue);
     331            if(SystemJoinedCompletely())
     332                return this.p2pPeer.p2pBase.SynchStore(sKey, byteValue);
     333            return false;
    317334        }
    318335
    319336        public bool DHTstore(string sKey, string sValue)
    320337        {
    321             return this.p2pPeer.p2pBase.SynchStore(sKey, sValue);
     338            if (SystemJoinedCompletely())
     339                return this.p2pPeer.p2pBase.SynchStore(sKey, sValue);
     340            return false;
    322341        }
    323342
    324343        public byte[] DHTload(string sKey)
    325344        {
    326             return this.p2pPeer.p2pBase.SynchRetrieve(sKey);
     345            if (SystemJoinedCompletely())
     346                return this.p2pPeer.p2pBase.SynchRetrieve(sKey);
     347            return null;
    327348        }
    328349
    329350        public bool DHTremove(string sKey)
    330351        {
    331             return this.p2pPeer.p2pBase.SynchRemove(sKey);
     352            if (SystemJoinedCompletely())
     353                return this.p2pPeer.p2pBase.SynchRemove(sKey);
     354            return false;
    332355        }
    333356
     
    337360        /// <param name="sPeerName">returns the Peer Name</param>
    338361        /// <returns>returns the Peer ID</returns>
    339         public string GetPeerID(out string sPeerName)
    340         {
    341             if (this.sPeerID == null)
    342             {
    343                 this.sPeerID = this.p2pPeer.p2pBase.GetPeerID(out this.sPeerName);
     362        public PeerId GetPeerID(out string sPeerName)
     363        {
     364            if (SystemJoinedCompletely())
     365            {
     366                if (this.peerID == null)
     367                {
     368                    this.peerID = this.p2pPeer.p2pBase.GetPeerID(out this.sPeerName);
     369                }
     370                sPeerName = this.sPeerName;
     371                return this.peerID;
    344372            }
    345373            sPeerName = this.sPeerName;
    346             return this.sPeerID;
    347         }
    348 
    349         public void SendToPeer(string sData, string sDestinationPeerAddress)
    350         {
    351             this.p2pPeer.p2pBase.SendToPeer(sData, sDestinationPeerAddress);
    352         }
    353         public void SendToPeer(string sData, byte[] byteDestinationPeerAddress)
    354         {
    355             this.p2pPeer.p2pBase.SendToPeer(sData, byteDestinationPeerAddress);
    356         }
    357         public void SendToPeer(PubSubMessageType msgType, string sDestinationAddress)
    358         {
    359             this.p2pPeer.p2pBase.SendToPeer(msgType, sDestinationAddress);
     374            return null;
     375        }
     376
     377        public void SendToPeer(string sData, PeerId destinationAddress)
     378        {
     379            if (SystemJoinedCompletely())
     380                this.p2pPeer.p2pBase.SendToPeer(sData, destinationAddress);
     381        }
     382        public void SendToPeer(PubSubMessageType msgType, PeerId destinationAddress)
     383        {
     384            if (SystemJoinedCompletely())
     385                this.p2pPeer.p2pBase.SendToPeer(msgType, destinationAddress);
     386        }
     387        public void SendToPeer(string sData, byte[] destinationAddress)
     388        {
     389            if (SystemJoinedCompletely())
     390                this.p2pPeer.p2pBase.SendToPeer(sData, destinationAddress);
    360391        }
    361392
     
    380411        }
    381412
     413        public string ConvertIdToString(byte[] byteId)
     414        {
     415            string sRet = String.Empty;
     416            for (int i = 0; i < byteId.Length; i++)
     417            {
     418                //sRet += UTF8Encoding.UTF8.GetString(byteId[i]) + ":";
     419                sRet += Convert.ToString(byteId[i]) + ":";
     420            }
     421            return sRet;
     422        }
     423
    382424        #endregion
    383425    }
  • trunk/CrypPlugins/PeerToPeerBase/P2PPeerSettings.cs

    r862 r872  
    4848        #region Start- and Stop-Buttons incl. functionality
    4949
    50         public bool StartingPeer
    51         {
    52             set
    53             {
    54                 if (value)
    55                 {
    56                     BtnStart();
    57                 }
    58             }
    59         }
    60 
    6150        [TaskPane("Start", "Initializes and starts Peer", null, 2, false, DisplayLevel.Beginner, ControlType.Button)]
    6251        public void BtnStart()
     
    206195        public enum PeerStatus
    207196        {
     197            NotConnected = 0,
    208198            Connecting = 1,
    209199            Online = 2,
    210             Error = 3,
    211             NotConnected = 0
     200            Error = 3
    212201        }
    213202
  • trunk/CrypPlugins/PeerToPeerBase/PeerToPeerBase.cs

    r862 r872  
    7979        public event SystemLeft OnSystemLeft;
    8080
    81         public delegate void P2PMessageReceived(string sSourceAddr, string sData);
     81        public delegate void P2PMessageReceived(PeerId sourceAddr, string sData);
    8282        public event P2PMessageReceived OnP2PMessageReceived;
    8383
     
    103103        #region Variables
    104104
    105         private bool initialized = false;
    106         public bool Initialized
    107         {
    108             get { return this.initialized; }
    109             set { this.initialized = value; }
     105        private bool started = false;
     106        /// <summary>
     107        /// True if system was successfully joined, false if system is COMPLETELY left
     108        /// </summary>
     109        public bool Started
     110        {
     111            get { return this.started; }
     112            private set { this.started = value; }
    110113        }
    111114
     
    186189            #endregion
    187190
    188             this.dht.Initialize(sUserName, sWorldName, this.overlay, this.bootstrapper, this.linkmanager, null);
    189 
    190191            this.dht.MessageReceived += new EventHandler<MessageReceived>(OnDHT_MessageReceived);
    191192            this.overlay.MessageReceived += new EventHandler<OverlayMessageEventArgs>(overlay_MessageReceived);
    192193            this.dht.SystemJoined += new EventHandler(OnDHT_SystemJoined);
    193194            this.dht.SystemLeft += new EventHandler(OnDHT_SystemLeft);
     195
     196            //this.dht.Initialize(sUserName, sWorldName, this.overlay, this.bootstrapper, this.linkmanager, null);
     197            this.dht.Initialize(sUserName, "", sWorldName, this.overlay, this.bootstrapper, this.linkmanager, null);
    194198        }
    195199
     
    266270        /// <param name="sPeerName">out: additional peer information UserName on LinkManager</param>
    267271        /// <returns>PeerID as a String</returns>
    268         public string GetPeerID(out string sPeerName)
     272        public PeerId GetPeerID(out string sPeerName)
    269273        {
    270274            sPeerName = this.linkmanager.UserName;
    271             return this.overlay.LocalAddress.ToString();
    272             // return this.overlay.LocalAddress.ToByteArray();
     275            PeerId pid = new PeerId(this.overlay.LocalAddress.ToString(), this.overlay.LocalAddress.ToByteArray());
     276            return pid;
    273277        }
    274278
     
    288292        }
    289293
    290         public void SendToPeer(string sData, string sDestinationPeerId)
    291         {
    292             // necessary because the overlay.GetAddress(string)-method of PAP is very buggy.
    293             // It doesn't cast the string- to a Byte-Address, but returns the own address...
    294             string[] sSplitted = sDestinationPeerId.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
    295             byte[] byteDestinationAddress = new byte[sSplitted.Length];
    296             for (int i = 0; i < byteDestinationAddress.Length; i++)
    297             {
    298                 byteDestinationAddress[i] = System.Convert.ToByte(sSplitted[i]);
    299             }
    300             SendToPeer(sData, byteDestinationAddress);
    301         }
    302 
    303         public void SendToPeer(PubSubMessageType msgType, string sDestinationAddress)
    304         {
    305             SendToPeer(((int)msgType).ToString(), sDestinationAddress);
     294        public void SendToPeer(PubSubMessageType msgType, byte[] byteDestinationPeerName)
     295        {
     296            SendToPeer(((int)msgType).ToString(), byteDestinationPeerName);
     297        }
     298
     299        public void SendToPeer(string sData, PeerId destinationPeerId)
     300        {
     301            SendToPeer(sData, destinationPeerId.byteId);
     302        }
     303
     304        public void SendToPeer(PubSubMessageType msgType, PeerId destinationAddress)
     305        {
     306            SendToPeer(((int)msgType).ToString(), destinationAddress.byteId);
    306307        }
    307308
     
    313314                OnSystemJoined();
    314315            this.systemJoined.Set();
    315             Initialized = true;
     316            Started = true;
    316317        }
    317318
     
    323324            this.dht = null;
    324325            this.systemLeft.Set();
    325             Initialized = false;
     326            Started = false;
    326327        }
    327328
     
    329330        {
    330331            if (OnP2PMessageReceived != null)
    331                 OnP2PMessageReceived(e.Message.Source.ToString(), e.Message.Data.PopUTF8String());
     332            {
     333                PeerId pid = new PeerId(e.Message.Source.ToString(), e.Message.Source.ToByteArray());
     334                OnP2PMessageReceived(pid, e.Message.Data.PopUTF8String());
     335            }
    332336        }
    333337
     
    335339        {
    336340            if (OnP2PMessageReceived != null)
    337                 OnP2PMessageReceived(e.Source.ToString(), e.Data.PopUTF8String());
     341            {
     342                PeerId pid = new PeerId(e.Source.ToString(), e.Source.ToByteArray());
     343                OnP2PMessageReceived(pid, e.Data.PopUTF8String());
     344            }
    338345        }
    339346
     
    620627        }
    621628    }
     629
     630    public class PeerId
     631    {
     632        public string stringId;
     633        public byte[] byteId;
     634
     635        public PeerId(string sPid, byte[] byPid)
     636        {
     637            this.stringId = sPid;
     638            this.byteId = byPid;
     639        }
     640
     641        public void Dispose()
     642        {
     643            this.byteId = null;
     644            this.stringId = String.Empty;
     645        }
     646
     647        // not used at present...
     648        public bool Equals(PeerId otherPeerId)
     649        {
     650            if (this.stringId == otherPeerId.stringId)
     651                return true;
     652            else
     653                return false;
     654        }
     655
     656        public string ToString()
     657        {
     658            return this.stringId;
     659        }
     660
     661        public byte[] ToByteArray()
     662        {
     663            return this.byteId;
     664        }
     665    }
    622666}
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisher.cs

    r862 r872  
    2525using System.ComponentModel;
    2626
    27 /*
    28  * TODO:
    29  * - FUTURE: dual data management of subscriber list (on local peer and in DHT)
    30  */
    31 
    3227namespace Cryptool.Plugins.PeerToPeer
    3328{
     
    4035    {
    4136        private P2PPublisherSettings settings;
    42         private IP2PControl p2pMaster;
     37        private IP2PControl p2pControl;
    4338        private P2PPublisherBase p2pPublisher;
    4439
     
    6257            if (e.PropertyName == "SendAliveMessageInterval")
    6358            {
    64                 this.p2pMaster.DHTstore(settings.TopicName + "Settings",
    65                     System.BitConverter.GetBytes(this.settings.SendAliveMessageInterval));
     59                this.p2pControl.DHTstore(settings.TopicName + "Settings",
     60                    System.BitConverter.GetBytes(this.settings.SendAliveMessageInterval * 1000));
    6661            }
    6762            // if TaskName has changed, clear the Lists, because the Subscribers must reconfirm registering
     
    9994        /// </summary>
    10095        [PropertyInfo(Direction.ControlMaster,"P2P Slave","Input the P2P-Peer-PlugIn","",true,false,DisplayLevel.Beginner,QuickWatchFormat.Text,null)]
    101         public IP2PControl P2PMaster
     96        public IP2PControl P2PControl
    10297        {
    10398            get
    10499            {
    105                 return this.p2pMaster;
     100                return this.p2pControl;
    106101            }
    107102            set
    108103            {
    109                 if (this.p2pMaster != null)
     104                if (this.p2pControl != null)
    110105                {
    111                     this.p2pMaster.OnPeerReceivedMsg -= p2pMaster_OnPeerReceivedMsg;
    112                     this.p2pMaster.OnStatusChanged -= P2PMaster_OnStatusChanged;
     106                    this.p2pControl.OnStatusChanged -= P2PControl_OnStatusChanged;
    113107                }
    114108                if (value != null)
    115109                {
    116                     this.p2pMaster = (P2PPeerMaster)value;
    117                     this.p2pMaster.OnStatusChanged += new IControlStatusChangedEventHandler(P2PMaster_OnStatusChanged);
    118                     this.p2pMaster.OnPeerReceivedMsg += new P2PBase.P2PMessageReceived(p2pMaster_OnPeerReceivedMsg);
    119                     OnPropertyChanged("P2PMaster");
     110                    this.p2pControl = (P2PPeerMaster)value;
     111                    this.p2pControl.OnStatusChanged += new IControlStatusChangedEventHandler(P2PControl_OnStatusChanged);
     112                    OnPropertyChanged("P2PControl");
    120113                }
    121114                else
    122115                {
    123                     this.p2pMaster = null;
     116                    this.p2pControl = null;
    124117                }
    125118            }
    126119        }
    127120
    128         private void P2PMaster_OnStatusChanged(IControl sender, bool readyForExecution)
     121        private void P2PControl_OnStatusChanged(IControl sender, bool readyForExecution)
    129122        {
    130123            //throw new NotImplementedException();
     
    179172        {
    180173            // if no P2P Slave PlugIn is connected with this PlugIn --> No execution!
    181             if (P2PMaster == null)
     174            if (P2PControl == null)
    182175            {
    183176                GuiLogMessage("No P2P_Peer connected with this PlugIn!", NotificationLevel.Error);
     
    187180            if (this.p2pPublisher == null)
    188181            {
    189                 this.p2pPublisher = new P2PPublisherBase(this.P2PMaster);
     182                this.p2pPublisher = new P2PPublisherBase(this.P2PControl);
    190183                this.p2pPublisher.OnGuiMessage += new P2PPublisherBase.GuiMessage(p2pPublisher_OnGuiMessage);
    191184                this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
     
    219212        public void Stop()
    220213        {
    221             if(this.p2pPublisher != null)
     214            if(this.p2pPublisher != null && this.p2pPublisher.Started)
    222215                this.p2pPublisher.Stop(PubSubMessageType.Unregister);
    223216        }
     
    229222        public void Dispose()
    230223        {
    231         }
    232 
    233         #endregion
    234 
    235         private void p2pMaster_OnPeerReceivedMsg(string sSourceAddr, string sData)
    236         {
    237             //this.p2pPublisher.MessageReceived(sSourceAddr, sData);
    238         }
     224            if (this.p2pPublisher != null && this.p2pPublisher.Started)
     225            {
     226                this.p2pPublisher.Stop(PubSubMessageType.Unregister);
     227            }
     228        }
     229
     230        #endregion
    239231
    240232        private void p2pPublisher_OnGuiMessage(string sData, NotificationLevel notificationLevel)
     
    265257
    266258        #endregion
    267 
    268         //#region Publisher methods
    269 
    270         //private string topic = String.Empty;
    271         //private string sDHTSettingsPostfix = "Settings";
    272         //private SubscriberManagement subManagement;
    273         //private Timer timerWaitingForAliveMsg;
    274         //private string sPeerName;
    275         //private long aliveMessageInterval;
    276 
    277         //private bool StartPublisher(string sTopic, long aliveMessageInterval)
    278         //{
    279         //    this.topic = sTopic;
    280         //    aliveMessageInterval = aliveMessageInterval * 1000;
    281         //    this.subManagement = new SubscriberManagement(aliveMessageInterval);
    282         //    this.subManagement.OnSubscriberRemoved += new SubscriberManagement.SubscriberRemoved(subManagement_OnSubscriberRemoved);
    283 
    284         //    string sActualPeerName;
    285 
    286         //    // publish own PeerID to the DHT Entry with the key "TaskName", so every subscriber
    287         //    // can retrieve the name and send a register-message to the publisher
    288         //    string sPeerId = P2PMaster.GetPeerID(out sPeerName);
    289         //    //byte[] bytePeerId = P2PMaster.GetPeerID(out sActualPeerName);
    290 
    291         //    sActualPeerName = sPeerId;
    292 
    293         //    // before storing the publishers ID in the DHT, proof whether there already exist an entry
    294         //    byte[] byRead = P2PMaster.DHTload(sTopic);
    295         //    string sRead;
    296         //    // if byRead is not null, the DHT entry was already written
    297         //    if (byRead != null)
    298         //    {
    299         //        sRead = UTF8Encoding.UTF8.GetString(byRead);
    300         //        // if sRead equals sPeerId this Publisher with the same topic had written
    301         //        // this entry - no problem! Otherwise abort Starting the publisher!
    302         //        if (sRead != sPeerId)
    303         //        {
    304         //            GuiLogMessage("Can't store Publisher in the DHT because the Entry was already occupied.", NotificationLevel.Error);
    305         //            return false;
    306         //        }
    307         //    }
    308         //    bool bolTopicStored = P2PMaster.DHTstore(sTopic, sPeerId);
    309         //    bool bolSettingsStored = P2PMaster.DHTstore(sTopic + this.sDHTSettingsPostfix,
    310         //        System.BitConverter.GetBytes(aliveMessageInterval));
    311 
    312         //    if (!bolTopicStored || !bolSettingsStored)
    313         //    {
    314         //        GuiLogMessage("Storing Publishers ID or Publishers Settings wasn't possible.", NotificationLevel.Error);
    315         //        return false;
    316         //    }
    317 
    318         //    GuiLogMessage("Peer ID '" + sPeerId + "' is published to DHT -Entry-Key '" + this.settings.TopicName + "'", NotificationLevel.Info);
    319         //    return true;
    320         //}
    321 
    322         //private void MessageReceived(string sSourceAddr, string sData)
    323         //{
    324         //    PubSubMessageType msgType = this.P2PMaster.GetMsgType(sData);
    325 
    326         //    if (msgType != PubSubMessageType.NULL)
    327         //    {
    328         //        switch (msgType)
    329         //        {
    330         //            case PubSubMessageType.Register:
    331         //                if (this.subManagement.Add(sSourceAddr))
    332         //                {
    333         //                    GuiLogMessage("REGISTERED: Peer with ID " + sSourceAddr, NotificationLevel.Info);
    334         //                    this.P2PMaster.SendToPeer(PubSubMessageType.RegisteringAccepted, sSourceAddr);
    335         //                }
    336         //                else
    337         //                {
    338         //                    GuiLogMessage("ALREADY REGISTERED peer with ID " + sSourceAddr, NotificationLevel.Info);
    339         //                }
    340         //                break;
    341         //            case PubSubMessageType.Unregister:
    342         //                if (this.subManagement.Remove(sSourceAddr))
    343         //                    GuiLogMessage("REMOVED subscriber " + sSourceAddr + " because it had sent an unregister message", NotificationLevel.Info);
    344         //                else
    345         //                    GuiLogMessage("ALREADY REMOVED or had not registered anytime. ID " + sSourceAddr, NotificationLevel.Info);
    346         //                break;
    347         //            case PubSubMessageType.Alive:
    348         //            case PubSubMessageType.Pong:
    349         //                if (this.subManagement.Update(sSourceAddr))
    350         //                {
    351         //                    GuiLogMessage("RECEIVED: " + msgType.ToString() + " Message from " + sSourceAddr, NotificationLevel.Info);
    352         //                }
    353         //                else
    354         //                {
    355         //                    GuiLogMessage("UPDATE FAILED for " + sSourceAddr + " because it hasn't registered first. " + msgType.ToString(), NotificationLevel.Info);
    356         //                }
    357         //                break;
    358         //            case PubSubMessageType.Ping:
    359         //                this.P2PMaster.SendToPeer(PubSubMessageType.Pong, sSourceAddr);
    360         //                GuiLogMessage("REPLIED to a ping message from subscriber " + sSourceAddr, NotificationLevel.Info);
    361         //                break;
    362         //            case PubSubMessageType.Solution:
    363         //                // Send solution msg to all subscriber peers and delete subList
    364         //                StopPublisher(msgType);
    365         //                break;
    366         //            default:
    367         //                throw (new NotImplementedException());
    368         //        } // end switch
    369         //        if (timerWaitingForAliveMsg == null)
    370         //            timerWaitingForAliveMsg = new Timer(OnWaitingForAliveMsg, null, this.settings.SendAliveMessageInterval * 1000,
    371         //                this.settings.SendAliveMessageInterval * 1000);
    372         //    }
    373         //    // Received Data aren't PubSubMessageTypes or rather no action-relevant messages
    374         //    else
    375         //    {
    376         //        GuiLogMessage("RECEIVED message from non subscribed peer: " + sData.Trim() + ", ID: " + sSourceAddr, NotificationLevel.Warning);
    377         //    }
    378         //}
    379 
    380         //private void Publish(string sText)
    381         //{
    382         //    Dictionary<string, DateTime> lstSubscribers = this.subManagement.GetAllSubscribers();
    383 
    384         //    PubSubMessageType msgType = this.P2PMaster.GetMsgType(sText);
    385         //    if (msgType == PubSubMessageType.NULL)
    386         //    {
    387         //        foreach (string sSubscriber in lstSubscribers.Keys)
    388         //        {
    389         //            this.P2PMaster.SendToPeer(sText, sSubscriber);
    390         //        }
    391         //    }
    392         //    else
    393         //    {
    394         //        foreach (string sSubscriber in lstSubscribers.Keys)
    395         //        {
    396         //            this.P2PMaster.SendToPeer(msgType, sSubscriber);
    397         //        }
    398         //    }
    399         //}
    400 
    401         ///// <summary>
    402         ///// if peers are outdated (alive message doesn't arrive in the given interval)
    403         ///// ping them to give them a second chance
    404         ///// </summary>
    405         ///// <param name="state"></param>
    406         //private void OnWaitingForAliveMsg(object state)
    407         //{
    408         //    List<string> lstOutdatedSubscribers = this.subManagement.CheckVitality();
    409         //    foreach (string outdatedSubscriber in lstOutdatedSubscribers)
    410         //    {
    411         //        P2PMaster.SendToPeer(PubSubMessageType.Ping, outdatedSubscriber);
    412         //        GuiLogMessage("PING outdated peer " + outdatedSubscriber, NotificationLevel.Info);
    413         //    }
    414         //}
    415 
    416         //private void subManagement_OnSubscriberRemoved(string sPeerId)
    417         //{
    418         //    GuiLogMessage("REMOVED subscriber " + sPeerId, NotificationLevel.Info);
    419         //}
    420 
    421         //private void StopPublisher(PubSubMessageType msgType)
    422         //{
    423         //    if(this.P2PMaster != null)
    424         //        // send unregister message to all subscribers
    425         //        Publish(((int)msgType).ToString());
    426         //    if (this.P2PMaster != null)
    427         //    {
    428         //        this.P2PMaster.DHTremove(this.topic);
    429         //        this.P2PMaster.DHTremove(this.topic + this.sDHTSettingsPostfix);
    430         //    }
    431         //    if (this.timerWaitingForAliveMsg != null)
    432         //    {
    433         //        this.timerWaitingForAliveMsg.Dispose();
    434         //        this.timerWaitingForAliveMsg = null;
    435         //    }
    436         //}
    437 
    438         //#endregion
    439259    }
    440260
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriber.cs

    r862 r872  
    2525using System.ComponentModel;
    2626
    27 /*
    28  * IDEAS:
    29  * - Publisher takes subscriber list out of the DHT and registered
    30  *   itself with all subscribers pro-active (handle Register-Msg in Subscriber!)
    31  *
    32  * TODO:
    33  * - Handle "publisher-changed" case (reconfirm registration, etc.)
    34  */
    35 
    3627namespace Cryptool.Plugins.PeerToPeer
    3728{
     
    4334    public class P2PSubscriber : IInput
    4435    {
    45         #region Variables
    46 
    47         private string sDHTSettingsPostfix = "Settings";
    48         private long sendAliveMessageInterval;
    49         private long checkPublishersAvailability;
    50 
    5136        private P2PSubscriberSettings settings;
    52         private IP2PControl p2pMaster;
    53         /// <summary>
    54         /// If the DHT Entry of the given Task is empty, continous try to
    55         /// find a meanwhile inscribed Publishers PeerID
    56         /// </summary>
    57         private Timer timerRegisteringNotPossible;
    58         /// <summary>
    59         /// For informing the publisher pro-active, that this subscriber
    60         /// is still interested in this Task.
    61         /// </summary>
    62         private Timer timerSendingAliveMsg;
    63         /// <summary>
    64         /// checking liveness, availability and/or changes (new peer) of the Publisher
    65         /// </summary>
    66         private Timer timerCheckPubAvailability;
    67         /// <summary>
    68         /// this timer gets started when the availability of the publisher,
    69         /// at which the subscriber had registered, is checked. If the timer
    70         /// callback is called and no Pong-message was received, the probability
    71         /// that the Publisher is down is high!
    72         /// </summary>
    73         private Timer timeoutForPublishersPong;
    74         /// <summary>
    75         /// After register message is sent to publisher, this timer gets started.
    76         /// If the publisher doesn't response with a RegisteringAccepted-Message,
    77         /// the probability that the publisher is down is high!
    78         /// </summary>
    79         private Timer timeoutForPublishersRegAccept;
    80         /// <summary>
    81         /// PeerID of the actual publisher. This ID is will be checked continious
    82         /// on liveliness and/or updated if Publisher had changed.
    83         /// </summary>
    84         private string actualPublisher;
    85 
    86         #endregion
     37        private IP2PControl p2pControl;
     38        private P2PSubscriberBase p2pSubscriber;
    8739
    8840        #region In and Output
     
    9143        /// Catches the completely configurated, initialized and joined P2P object from the P2PPeer-Slave-PlugIn.
    9244        /// </summary>
    93         [PropertyInfo(Direction.ControlMaster,"P2P Slave","Input the P2P-Peer-PlugIn","",true,false,DisplayLevel.Beginner,QuickWatchFormat.Text,null)]
    94         public IP2PControl P2PMaster
     45        [PropertyInfo(Direction.ControlMaster, "P2P Slave", "Input the P2P-Peer-PlugIn", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
     46        public IP2PControl P2PControl
    9547        {
    9648            get
    9749            {
    98                 return this.p2pMaster;
     50                return this.p2pControl;
    9951            }
    10052            set
    10153            {
    102                 if (this.p2pMaster != null)
    103                 {
    104                     this.p2pMaster.OnPeerReceivedMsg -= P2PMaster_OnPeerReceivedMsg;
    105                     this.p2pMaster.OnStatusChanged -= P2PMaster_OnStatusChanged;
     54                if (this.p2pControl != null)
     55                {
     56                    this.p2pControl.OnStatusChanged -= P2PControl_OnStatusChanged;
    10657                }
    10758                if (value != null)
    10859                {
    109                     this.p2pMaster = (P2PPeerMaster)value;
    110                     this.p2pMaster.OnPeerReceivedMsg += new P2PBase.P2PMessageReceived(P2PMaster_OnPeerReceivedMsg);
    111                     this.p2pMaster.OnStatusChanged += new IControlStatusChangedEventHandler(P2PMaster_OnStatusChanged);
    112                     OnPropertyChanged("P2PMaster");
     60                    this.p2pControl = (P2PPeerMaster)value;
     61                    this.p2pControl.OnStatusChanged += new IControlStatusChangedEventHandler(P2PControl_OnStatusChanged);
     62                    OnPropertyChanged("P2PControl");
    11363                }
    11464                else
    11565                {
    116                     this.p2pMaster = null;
     66                    this.p2pControl = null;
    11767                }
    11868            }
     
    13989        #endregion
    14090
    141         private void P2PMaster_OnPeerReceivedMsg(string sSourceAddr, string sData)
    142         {
    143             MessageReceived(sSourceAddr, sData);
    144         }
    145 
    146         private void P2PMaster_OnStatusChanged(IControl sender, bool readyForExecution)
     91        private void P2PControl_OnStatusChanged(IControl sender, bool readyForExecution)
    14792        {
    14893            //throw new NotImplementedException();
     
    160105
    161106        #region Standard functionality
     107
    162108        public P2PSubscriber()
    163109        {
     
    176122            if (e.PropertyName == "BtnUnregister")
    177123            {
    178                 StopActiveWork();
    179                 GuiLogMessage("Subscriber unregistered from Publisher!", NotificationLevel.Info);
     124                if (this.p2pSubscriber != null)
     125                {
     126                    this.p2pSubscriber.Stop();
     127                    GuiLogMessage("Subscriber unregistered from Publisher!", NotificationLevel.Info);
     128                }
     129                else
     130                {
     131                    GuiLogMessage("Publisher isn't initialized, so this action isn't possible.", NotificationLevel.Info);
     132                }
    180133            }
    181134            if (e.PropertyName == "BtnRegister")
    182135            {
    183                 Register();
     136                RegisterSubscriber();
    184137                GuiLogMessage("Subscriber registers with Publisher!", NotificationLevel.Info);
    185138            }
    186139            if (e.PropertyName == "BtnSolutionFound")
    187140            {
    188                 SendMessage(actualPublisher, PubSubMessageType.Solution);
    189                 GuiLogMessage("Solution found message sent to Publisher.", NotificationLevel.Info);
     141                if (this.p2pSubscriber != null)
     142                {
     143                    this.p2pSubscriber.SolutionFound();
     144                    GuiLogMessage("Solution found message sent to Publisher.", NotificationLevel.Info);
     145                }
     146                else
     147                {
     148                    GuiLogMessage("Publisher isn't initialized, so this action isn't possible.", NotificationLevel.Info);
     149                }
    190150            }
    191151        }
     
    220180        public void Pause()
    221181        {
    222             StopActiveWork();
    223182        }
    224183
    225184        public void Stop()
    226185        {
    227             StopActiveWork();
     186            if(this.p2pSubscriber != null)
     187                this.p2pSubscriber.Stop();
    228188        }
    229189
     
    240200        {
    241201            // if no P2P Slave PlugIn is connected with this PlugIn --> No execution!
    242             if (P2PMaster == null)
     202            if (P2PControl == null)
    243203            {
    244204                GuiLogMessage("No P2P_Peer connected with this PlugIn!", NotificationLevel.Error);
     
    247207            if (this.settings.TopicName != null)
    248208            {
    249                 Register();
     209                RegisterSubscriber();
    250210            }
    251211            else
     
    255215        }
    256216
     217        private void RegisterSubscriber()
     218        {
     219            if (this.p2pSubscriber == null)
     220            {
     221                this.p2pSubscriber = new P2PSubscriberBase(this.P2PControl);
     222                this.p2pSubscriber.OnGuiMessage += new P2PSubscriberBase.GuiMessage(p2pSubscriber_OnGuiMessage);
     223                this.p2pSubscriber.OnTextArrivedFromPublisher += new P2PSubscriberBase.TextArrivedFromPublisher(p2pSubscriber_OnTextArrivedFromPublisher);
     224                this.p2pSubscriber.Register(this.settings.TopicName, (long)(this.settings.CheckPublishersAvailability * 1000),
     225                    (long)(this.settings.PublishersReplyTimespan * 1000));
     226            }
     227            else
     228            {
     229                this.p2pSubscriber.Register(this.settings.TopicName, (long)(this.settings.CheckPublishersAvailability * 1000),
     230                    (long)(this.settings.PublishersReplyTimespan * 1000));
     231            }
     232        }
     233
     234        void p2pSubscriber_OnTextArrivedFromPublisher(string sData, PeerId pid)
     235        {
     236            this.Outputvalue = sData;
     237        }
     238
     239        void p2pSubscriber_OnGuiMessage(string sData, NotificationLevel notificationLevel)
     240        {
     241            GuiLogMessage(sData, notificationLevel);
     242        }
     243
    257244        #region INotifyPropertyChanged Members
    258245
     
    276263        }
    277264
    278         #endregion
    279 
    280         #region Subscriber methods
    281 
    282         /// <summary>
    283         /// if true, check whether a new Publisher is the actual one
    284         /// and renew Settings
    285         /// </summary>
    286         private bool bolStopped = true;
    287 
    288         private void Register()
    289         {
    290             string sPubId = CheckPublisherAvailability();
    291             // if DHT Entry for Task is empty, there exist no Publisher at present.
    292             // The method PublisherIsAlive starts a Timer for this case to continous proof Publisher-DHT-Entry
    293             if (sPubId != null)
    294             {
    295                 SendMessage(sPubId, PubSubMessageType.Register);
    296                 long interval = this.settings.PublishersReplyTimespan * 1000;
    297                 if (this.timeoutForPublishersRegAccept == null)
    298                     this.timeoutForPublishersRegAccept = new Timer(OnTimeoutRegisteringAccepted, null, interval, interval);
    299                 this.bolStopped = false;
    300             }
    301         }
    302 
    303         private void MessageReceived(string sSourceAddr, string sData)
    304         {
    305             if (sSourceAddr != actualPublisher)
    306             {
    307                 GuiLogMessage("RECEIVED message from third party peer (not the publisher!): " + sData.Trim() + ", ID: " + sSourceAddr, NotificationLevel.Info);
    308                 return;
    309             }
    310 
    311             PubSubMessageType msgType = this.P2PMaster.GetMsgType(sData);
    312 
    313             switch (msgType)
    314             {
    315                 case PubSubMessageType.RegisteringAccepted:
    316                     GuiLogMessage("REGISTERING ACCEPTED received from publisher!", NotificationLevel.Info);
    317                     if (this.timeoutForPublishersRegAccept != null)
    318                     {
    319                         this.timeoutForPublishersRegAccept.Dispose();
    320                         this.timeoutForPublishersRegAccept = null;
    321                     }
    322                     break;
    323                 case PubSubMessageType.Ping:
    324                     SendMessage(sSourceAddr, PubSubMessageType.Pong);
    325                     GuiLogMessage("REPLIED to a ping message from " + sSourceAddr, NotificationLevel.Info);
    326                     break;
    327                 case PubSubMessageType.Register:
    328                 case PubSubMessageType.Unregister:
    329                     /* can't work the right way, because at present the
    330                      * publisher can't remove information of the DHT
    331                      * (point of entry for subscribers) */
    332                     GuiLogMessage(msgType.ToString().ToUpper() + " received from PUBLISHER.", NotificationLevel.Warning);
    333                     // continuously try to get a unregister and than re-register with publisher
    334                     StopActiveWork();
    335                     Register();
    336                     break;
    337                 case PubSubMessageType.Solution:
    338                     StopActiveWork();
    339                     GuiLogMessage("Another Subscriber had found the solution!",NotificationLevel.Info);
    340                     break;
    341                 case PubSubMessageType.Stop:
    342                     StopActiveWork();
    343                     GuiLogMessage("STOP received from publisher. Subscriber is stopped!", NotificationLevel.Warning);
    344                     break;
    345                 case PubSubMessageType.Pong:
    346                     if (this.timeoutForPublishersPong != null)
    347                     {
    348                         this.timeoutForPublishersPong.Dispose();
    349                         this.timeoutForPublishersPong = null;
    350                     }
    351                     break;
    352                 // if the received Data couldn't be casted to enum,
    353                 // it must be text-data
    354                 case PubSubMessageType.NULL:
    355                     GuiLogMessage("RECEIVED: Message from '" + sSourceAddr
    356                     + "' with data: '" + sData + "'", NotificationLevel.Info);
    357                     Outputvalue = sData;
    358                     break;
    359                 case PubSubMessageType.Alive:
    360                 default:
    361                     // not possible at the moment
    362                     break;
    363             }
    364         }
    365 
    366         private void SendMessage(string pubPeerId, PubSubMessageType msgType)
    367         {
    368             if (timerSendingAliveMsg == null && !this.bolStopped)
    369                 timerSendingAliveMsg = new Timer(OnSendAliveMessage, null, sendAliveMessageInterval, sendAliveMessageInterval);
    370 
    371             switch (msgType)
    372             {
    373                 case PubSubMessageType.Register:
    374                     // stop "RegisteringNotPossibleTimer
    375                     if (timerRegisteringNotPossible != null)
    376                     {
    377                         timerRegisteringNotPossible.Dispose();
    378                         timerRegisteringNotPossible = null;
    379                     }
    380                     break;
    381                 case PubSubMessageType.Alive:
    382                 case PubSubMessageType.Ping:
    383                 case PubSubMessageType.Pong:
    384                 case PubSubMessageType.Unregister:
    385                     break;
    386                 case PubSubMessageType.Solution:
    387                     StopActiveWork();
    388                     break;
    389                 default:
    390                     GuiLogMessage("No Message sent, because MessageType wasn't supported: " + msgType.ToString(),NotificationLevel.Warning);
    391                     return;
    392             }
    393             this.P2PMaster.SendToPeer(msgType, pubPeerId);
    394 
    395             // don't show every single alive message
    396             if(msgType != PubSubMessageType.Alive)
    397                 GuiLogMessage(msgType.ToString() + " message sent to Publisher", NotificationLevel.Info);
    398         }
    399 
    400         // registering isn't possible if no publisher has stored
    401         // his ID in the DHT Entry with the Key TaskName
    402         private void OnRegisteringNotPossible(object state)
    403         {
    404             string sPubId = CheckPublisherAvailability();
    405             // if DHT Entry for Task is empty, there exist no Publisher at present.
    406             // The method PublisherIsAlive starts a Timer for this case to continous proof Publisher-DHT-Entry
    407             if (sPubId != null)
    408                 SendMessage(sPubId, PubSubMessageType.Register);
    409         }
    410 
    411         private void OnSendAliveMessage(object state)
    412         {
    413             SendMessage(actualPublisher, PubSubMessageType.Alive);
    414         }
    415 
    416         private string CheckPublisherAvailability()
    417         {
    418             byte[] bytePubId = P2PMaster.DHTload(this.settings.TopicName);
    419             if (bytePubId == null)
    420             {
    421                 if (timerRegisteringNotPossible == null && !this.bolStopped)
    422                 {
    423                     // if DHT value doesn't exist at this moment, wait for 10 seconds and try again
    424                     timerRegisteringNotPossible = new Timer(OnRegisteringNotPossible, null, 10000, 10000);
    425                 }
    426                 return null;
    427             }
    428 
    429             byte[] byteISettings = P2PMaster.DHTload(this.settings.TopicName + this.sDHTSettingsPostfix);
    430             if (byteISettings == null)
    431             {
    432                 GuiLogMessage("Can't find settings from Publisher for the Subscriber.", NotificationLevel.Error);
    433                 return null;
    434             }
    435             sendAliveMessageInterval = System.BitConverter.ToInt32(byteISettings, 0);
    436 
    437             string sPubId = UTF8Encoding.UTF8.GetString(bytePubId);
    438             GuiLogMessage("RECEIVED: Publishers' peer name '" + sPubId + "', Alive-Msg-Interval: " + sendAliveMessageInterval / 1000 + " sec!", NotificationLevel.Info);
    439 
    440             if (actualPublisher == null) //first time initialization
    441                 actualPublisher = sPubId;
    442 
    443             checkPublishersAvailability = this.settings.CheckPublishersAvailability * 1000;
    444 
    445             // setting timer to check periodical the availability of the publishing peer
    446             if (timerCheckPubAvailability == null && !this.bolStopped)
    447                 timerCheckPubAvailability = new Timer(OnCheckPubAvailability, null, checkPublishersAvailability, checkPublishersAvailability);
    448 
    449             return sPubId;
    450         }
    451 
    452         private void OnCheckPubAvailability(object state)
    453         {
    454             string sNewPubId = CheckPublisherAvailability();
    455 
    456             if (sNewPubId == null)
    457             {
    458                 GuiLogMessage("Publisher wasn't found in DHT or settings didn't stored on the right way.", NotificationLevel.Warning);
    459                 return;
    460             }
    461             if (sNewPubId != actualPublisher)
    462             {
    463                 //Handle case, when publisher changed or isn't active at present (don't reply on response)
    464                 GuiLogMessage("CHANGED: Publisher from '" + actualPublisher
    465                     + "' to '" + sNewPubId + "'!", NotificationLevel.Info);
    466                 actualPublisher = sNewPubId;
    467                 // because the publisher has changed, send a new register msg
    468                 SendMessage(actualPublisher, PubSubMessageType.Register);
    469             }
    470             else
    471             {
    472                 // Timer will be only stopped, when OnMessageReceived-Event received
    473                 // a Pong-Response from the publisher!
    474                 SendMessage(actualPublisher, PubSubMessageType.Ping);
    475                 if (timeoutForPublishersPong == null)
    476                 {
    477                     long interval = this.settings.PublishersReplyTimespan * 1000;
    478                     timeoutForPublishersPong = new Timer(OnTimeoutPublishersPong, null, interval, interval);
    479                 }
    480             }
    481         }
    482 
    483         /// <summary>
    484         /// This callback only get fired, when the publisher didn't sent a response on the register message.
    485         /// </summary>
    486         /// <param name="state"></param>
    487         private void OnTimeoutRegisteringAccepted(object state)
    488         {
    489             GuiLogMessage("TIMEOUT: Waiting for registering accepted message from publisher!", NotificationLevel.Warning);
    490             // TODO: anything
    491         }
    492 
    493         /// <summary>
    494         /// This callback only get fired, when the publisher didn't sent a response on the ping message.
    495         /// </summary>
    496         /// <param name="state"></param>
    497         private void OnTimeoutPublishersPong(object state)
    498         {
    499             GuiLogMessage("Publisher didn't answer on Ping in the given time span!", NotificationLevel.Warning);
    500             timeoutForPublishersPong.Dispose();
    501             timeoutForPublishersPong = null;
    502             // try to get an active publisher and re-register
    503             CheckPublisherAvailability();
    504         }
    505 
    506         /// <summary>
    507         /// Will stop all timers, so Subscriber ends with sending
    508         /// Register-, Alive- and Pong-messages. Furthermore an
    509         /// unregister message will be send to the publisher
    510         /// </summary>
    511         private void StopActiveWork()
    512         {
    513             this.bolStopped = true;
    514             if(actualPublisher != null)
    515                 SendMessage(actualPublisher,PubSubMessageType.Unregister);
    516 
    517             #region stopping all timers, if they are still active
    518             if (this.timerSendingAliveMsg != null)
    519             {
    520                 this.timerSendingAliveMsg.Dispose();
    521                 this.timerSendingAliveMsg = null;
    522             }
    523             if (this.timerRegisteringNotPossible != null)
    524             {
    525                 this.timerRegisteringNotPossible.Dispose();
    526                 this.timerRegisteringNotPossible = null;
    527             }
    528             if (this.timerCheckPubAvailability != null)
    529             {
    530                 this.timerCheckPubAvailability.Dispose();
    531                 this.timerCheckPubAvailability = null;
    532             }
    533             if (this.timeoutForPublishersRegAccept != null)
    534             {
    535                 this.timeoutForPublishersRegAccept.Dispose();
    536                 this.timeoutForPublishersRegAccept = null;
    537             }
    538             if (this.timeoutForPublishersPong != null)
    539             {
    540                 this.timeoutForPublishersPong.Dispose();
    541                 this.timeoutForPublishersPong = null;
    542             }
    543             #endregion
    544         }
    545265        #endregion
    546266    }
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberSettings.cs

    r862 r872  
    107107        }
    108108
    109         private int publishersReplyTimespan = 2;
     109        private int publishersReplyTimespan = 5;
    110110        [TaskPane("Publisher Reply Timespan (in sec)", "When checking publishers availability, ping message is sent. The publisher must answer with a pong message in the timespan!", "Intervals", 0, false, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 2, 60)]
    111111        public int PublishersReplyTimespan
  • trunk/CrypPlugins/PeerToPeerSubscriber/PeerToPeerSubscriber.csproj

    r836 r872  
    4242      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    4343    </Reference>
     44    <Reference Include="System.Drawing" />
     45    <Reference Include="System.Windows.Forms" />
    4446    <Reference Include="System.Xml.Linq">
    4547      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    5658  <ItemGroup>
    5759    <Compile Include="P2PSubscriber.cs" />
     60    <Compile Include="P2PSubscriberBase.cs" />
    5861    <Compile Include="P2PSubscriberSettings.cs" />
    5962    <Compile Include="Properties\AssemblyInfo.cs" />
Note: See TracChangeset for help on using the changeset viewer.