Changeset 1129


Ignore:
Timestamp:
Feb 2, 2010, 6:09:57 PM (12 years ago)
Author:
arnold
Message:

P2PBase: SuperNode-Killing fixed (so P@P-DLLs were updated)
P2PPublisher: Publisher-Exchange now possible, particularly when "old" Publisher takes a "french leave"
P2PJobs: New Architecture for future use of a generic Manager/Worker-infrastructure
KeySearcher: KeyPattern and KeyPatternPool now inherit from P2PJobs (IJobPart, IJobStack)

Location:
trunk
Files:
8 added
47 edited

Legend:

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

    r1117 r1129  
    2121using Cryptool.PluginBase.Miscellaneous;
    2222using System.Collections;
     23using Cryptool.Plugins.PeerToPeer.Jobs;
    2324
    2425namespace KeySearcher
    2526{
    26     public class KeyPattern
     27    public class KeyPattern : IJobPart<KeyPattern>
    2728    {
    2829        private string pattern;
  • trunk/CrypPlugins/KeySearcher/KeyPatternPool.cs

    r1122 r1129  
    55using Cryptool.PluginBase.Miscellaneous;
    66using System.Collections;
     7using Cryptool.Plugins.PeerToPeer.Jobs;
    78
    89namespace KeySearcher
     
    1213     * It tries to split the pattern in such a way, that the parts have nearly the given partsize.
    1314     **/
    14     public class KeyPatternPool
     15    public class KeyPatternPool : IJobStack<KeyPattern>
    1516    {
    1617        private BigInteger partsize;
     
    152153        }
    153154
    154         public BigInteger Count()
     155        public long Count()
    155156        {
    156             return TotalAmount() - counter;
     157            return (TotalAmount() - counter).LongValue();
    157158        }
    158159
  • trunk/CrypPlugins/KeySearcher/KeySearcher.csproj

    r1117 r1129  
    7474      <Name>CrypPluginBase</Name>
    7575    </ProjectReference>
     76    <ProjectReference Include="..\PeerToPeerJobs\PeerToPeerJobs.csproj">
     77      <Project>{F1258427-AFDF-4DF7-ABF1-758A2325F505}</Project>
     78      <Name>PeerToPeerJobs</Name>
     79    </ProjectReference>
    7680  </ItemGroup>
    7781  <ItemGroup>
  • trunk/CrypPlugins/PeerToPeerBase/DHT_CommonManagement.cs

    r1098 r1129  
    1111    {
    1212        private static Encoding enc = Encoding.UTF8;
     13        private static string PublishersTimeStamp = "PubTimeStamp";
    1314        private static string AliveMsg = "AliveMsg";
    1415        private static string EncryptedData = "EncryptedText";
     
    157158            bool id = p2pControl.DHTremove(sTopicName);
    158159            bool alive = p2pControl.DHTremove(sTopicName + AliveMsg);
     160            bool timestamp = p2pControl.DHTremove(sTopicName + PublishersTimeStamp);
     161            //if timestamp wasn't removed successfully, that's no problem!
    159162            return (id && alive);
    160163        }
     
    172175            return (encrypt && init);
    173176        }
     177
     178        // new stuff - Arnie 2010.02.02
     179       
     180        ///// <summary>
     181        ///// Sets or updates the TimeStamp for the actual Publisher
     182        ///// </summary>
     183        ///// <param name="p2pControl">necessary P2PControl to use DHT operation(s)</param>
     184        ///// <param name="sTopicName">the topic name on which all Peers are registered</param>
     185        ///// <returns>true, if storing succeeds, otherwise false</returns>
     186        //public static bool SetPublishersTimeStamp(ref IP2PControl p2pControl, string sTopicName)
     187        //{
     188        //    byte[] timeStamp = enc.GetBytes(DateTime.Now.ToString());
     189        //    bool store = p2pControl.DHTstore(sTopicName + PublishersTimeStamp, timeStamp);
     190        //}
     191
     192        ///// <summary>
     193        /////  Gets the TimeStamp for the actual Publisher, if it's stored in the DHT (when a Publisher
     194        /////  is active, this value have to be occupied). Otherwise, when no Publisher is active, returns null.
     195        /////  If the DHT value is occupied, but parsing to DateTime wasn't possible, an Exception will be thrown
     196        ///// </summary>
     197        ///// <param name="p2pControl">necessary P2PControl to use DHT operation(s)</param>
     198        ///// <param name="sTopicName">the topic name on which all Peers are registered</param>
     199        ///// <returns>DateTime, if DHT entry is occupied, otherwise false.</returns>
     200        //public static DateTime GetPublishersTimeStamp(ref IP2PControl p2pControl, string sTopicName)
     201        //{
     202        //    DateTime retTimeStamp = null;
     203        //    byte[] timeStamp = p2pControl.DHTload(sTopicName + PublishersTimeStamp);
     204        //    //when timeStamp is null, DHT entry isn't occupied --> No Publisher is active at present
     205        //    if (timeStamp != null)
     206        //    {
     207        //        string sTimeStamp = enc.GetString(timeStamp);
     208        //        // if parsing isn't possible though DHT entry is occupied, throw an exception
     209        //        if (!DateTime.TryParse(sTimeStamp, out retTimeStamp))
     210        //        {
     211        //            throw (new Exception("Parsing the DHT entry '" + sTopicName + PublishersTimeStamp
     212        //                + "' to DateTime wasn't possible. Value: '" + sTimeStamp + "'"));
     213        //        }
     214        //    }
     215        //    return retTimeStamp;
     216        //}
    174217    }
    175218}
     219
  • trunk/CrypPlugins/PeerToPeerBase/PeerToPeerBase.cs

    r1115 r1129  
    165165            {
    166166                case P2PLinkManagerType.Snal:
    167                     if (bsType == P2PBootstrapperType.LocalMachineBootstrapper)
    168                         throw (new Exception("It's mindless to activate NAT traversal, but use the LocalMachineBootstrapper."));
    169 
    170167                    LogToMonitor("Init LinkMgr: Using NAT Traversal stuff");
    171168                    // NAT-Traversal stuff needs a different Snal-Version
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisher.cs

    r1107 r1129  
    186186            }
    187187
     188            // when Workspace has stopped and has been started again
     189            if (this.p2pPublisher != null && !this.p2pPublisher.Started)
     190            {
     191                this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
     192            }
     193
    188194            if (this.p2pPublisher == null)
    189195            {
     
    192198                this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
    193199            }
    194             if (this.p2pPublisher != null && !this.p2pPublisher.Started) // when Workspace has stopped and has been started again
    195             {
    196                 this.p2pPublisher.Start(this.settings.TopicName, (long)this.settings.SendAliveMessageInterval);
    197             }
    198200        }
    199201
  • trunk/CrypPlugins/PeerToPeerPublisher/P2PPublisherBase.cs

    r1115 r1129  
    4242        }
    4343
     44        // Publisher-exchange extension - Arnie 2010.02.02
     45        /// <summary>
     46        /// Interval for waiting for other Publishers Pong in milliseconds!
     47        /// </summary>
     48        const long INTERVAL_WAITING_FOR_OTHER_PUBS_PONG = 10000;
     49        Timer waitingForOtherPublishersPong;
     50        /// <summary>
     51        /// if this value is set, you are between the TimeSpan of checking liveness of the other peer.
     52        /// If Timespan runs out without receiving a Pong-Msg from the other Publisher, assume its functionality
     53        /// </summary>
     54        PeerId otherPublisherPeer = null;
     55        bool otherPublisherHadResponded = false;
     56
    4457        #endregion
    4558
     
    8598            if (byRead != null)
    8699            {
    87                 // this entry? Then no problem! Otherwise abort Starting the publisher!
     100                // if a different Publisher was found at the DHT entry, send a ping msg
     101                // and wait for Pong-Response. When this won't arrive in the given TimeSpan,
     102                // assume the Publishing functionality
    88103                if (byRead != myPeerId)
    89                 {
    90                     GuiLogging("Can't store Publisher in the DHT because the Entry was already occupied.", NotificationLevel.Error);
    91                     return false;
     104                {   
     105                    if (this.waitingForOtherPublishersPong == null)
     106                    {
     107                        this.otherPublisherHadResponded = false;
     108                        this.otherPublisherPeer = byRead;
     109                        this.waitingForOtherPublishersPong = new Timer(OnWaitingForOtherPublishersPong,
     110                            null, INTERVAL_WAITING_FOR_OTHER_PUBS_PONG, INTERVAL_WAITING_FOR_OTHER_PUBS_PONG);
     111
     112                        this.p2pControl.SendToPeer(PubSubMessageType.Ping, byRead);
     113
     114                        GuiLogging("Another Publisher was found. Waiting for Pong-Response for "
     115                            + INTERVAL_WAITING_FOR_OTHER_PUBS_PONG / 1000 + " seconds. When it won't response "
     116                            + "assume its functionality.", NotificationLevel.Debug);
     117                        return false;
     118                    }
     119                    else
     120                    {
     121                        // if this code will be executed, there's an error in this class logic
     122                        GuiLogging("Can't store Publisher in the DHT because the Entry was already occupied.", NotificationLevel.Error);
     123                        return false;
     124                    }
    92125                }
    93126            }
     
    158191                this.timerWaitingForAliveMsg = null;
    159192            }
     193            // Publisher-exchange extension - Arnie 2010.02.02
     194            if (this.waitingForOtherPublishersPong != null)
     195            {
     196                this.waitingForOtherPublishersPong.Dispose();
     197                this.waitingForOtherPublishersPong = null;
     198            }
    160199
    161200            GuiLogging("Deregister message-received-events", NotificationLevel.Debug);
     
    174213        protected virtual void p2pControl_OnSystemMessageReceived(PeerId sender, PubSubMessageType msgType)
    175214        {
     215            if (sender == ownPeerId)
     216            {
     217                GuiLogging("Received Message from OWN Peer... Strange stuff.", NotificationLevel.Debug);
     218                return;
     219            }
     220
    176221            switch (msgType)
    177222            {
     
    195240                case PubSubMessageType.Alive:
    196241                case PubSubMessageType.Pong:
     242                    if (this.otherPublisherPeer != null && this.otherPublisherPeer == sender)
     243                    {
     244                        this.otherPublisherHadResponded = true;
     245                        this.otherPublisherPeer = null;
     246                    }
    197247                    break;
    198248                case PubSubMessageType.Ping:
     
    278328        #endregion
    279329
     330        // Publisher-exchange extension - Arnie 2010.02.02
     331        /// <summary>
     332        /// Callback function for waitingForOtherPublishersPong-object. Will be only executed, when a
     333        /// different Publisher-ID was found in the DHT, to check if the "old" Publisher is still
     334        /// alive!
     335        /// </summary>
     336        /// <param name="state"></param>
     337        private void OnWaitingForOtherPublishersPong(object state)
     338        {
     339            if (this.otherPublisherHadResponded)
     340            {
     341                GuiLogging("Can't assume functionality of an alive Publishers. So starting this workspace isn't possible!", NotificationLevel.Error);
     342            }
     343            else
     344            {
     345                if (this.waitingForOtherPublishersPong != null)
     346                {
     347                    this.waitingForOtherPublishersPong.Dispose();
     348                    this.waitingForOtherPublishersPong = null;
     349                }
     350                GuiLogging("First trial to assume old Publishers functionality.", NotificationLevel.Debug);
     351                // we have to delete all OLD Publishers entries to assume its functionality
     352                DHT_CommonManagement.DeleteAllPublishersEntries(ref this.p2pControl, this.topic);
     353                Start(this.topic, this.aliveMessageInterval);
     354            }
     355        }
     356
    280357        // Only for testing the (De-)Serialization of SubscribersManagement
    281358        public void TestSerialization()
  • trunk/CrypPlugins/PeerToPeerSubscriber/P2PSubscriberBase.cs

    r1115 r1129  
    116116            // Publisher/Manager sends a Unregister/Stop-Message... There isn't any possibility to check,
    117117            // whether the Events are already registered (if(dings != null) or anything else).
     118            this.p2pControl.OnPayloadMessageReceived -= p2pControl_OnPayloadMessageReceived;
     119            this.p2pControl.OnSystemMessageReceived -= p2pControl_OnSystemMessageReceived;
    118120            this.p2pControl.OnPayloadMessageReceived += new P2PPayloadMessageReceived(p2pControl_OnPayloadMessageReceived);
    119121            this.p2pControl.OnSystemMessageReceived += new P2PSystemMessageReceived(p2pControl_OnSystemMessageReceived);
     
    258260
    259261        // registering isn't possible if no publisher has stored
    260         // his ID in the DHT Entry with the Key TaskName
     262        // its ID in the DHT Entry with the Key TaskName
    261263        private void OnRegisteringNotPossible(object state)
    262264        {
     
    334336                }
    335337            }
     338            if (newPubId != actualPublisher)
     339                Register();
    336340        }
    337341
Note: See TracChangeset for help on using the changeset viewer.