Changeset 1579


Ignore:
Timestamp:
Jun 3, 2010, 3:46:05 PM (12 years ago)
Author:
Paul Lelgemann
Message:

+ P2PEditor: Timer-based refresh of the job list (configurable in seconds)
o CrypP2P: Restored bootstrapper to V2
+ P2PManager: Added asynchronous DHT message calls for completeness

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypP2P/Internal/P2PBase.cs

    r1578 r1579  
    1818using System.Text;
    1919using System.Threading;
     20using Cryptool.PluginBase;
    2021using Cryptool.Plugins.PeerToPeer.Internal;
    2122using Gears4Net;
     
    2627using PeersAtPlay.P2POverlay;
    2728using PeersAtPlay.P2POverlay.Bootstrapper;
    28 using PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapper;
     29using PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapperV2;
    2930using PeersAtPlay.P2POverlay.Bootstrapper.LocalMachineBootstrapper;
    3031using PeersAtPlay.P2POverlay.FullMeshOverlay;
     
    3233using PeersAtPlay.P2PStorage.FullMeshDHT;
    3334using PeersAtPlay.Util.Logging;
    34 using Settings = PeersAtPlay.P2PLink.SnalNG.Settings;
    3535
    3636/* TODO:
     
    5252        private readonly AutoResetEvent _systemLeft;
    5353        private IBootstrapper _bootstrapper;
    54         private IDHT _dht;
    5554        private IP2PLinkManager _linkmanager;
    5655        private P2POverlay _overlay;
    57         private IVersionedDHT _versionedDht;
     56        internal IDHT Dht;
     57        internal IVersionedDHT VersionedDht;
    5858
    5959        /// <summary>
     
    108108                    _linkmanager = new Snal(scheduler);
    109109
    110                     var settings = new Settings();
     110                    var settings = new PeersAtPlay.P2PLink.SnalNG.Settings();
    111111                    settings.LoadDefaults();
    112112                    settings.ConnectInternal = true;
    113                     settings.LocalReceivingPort = 0;
     113                    settings.LocalReceivingPort = P2PSettings.Default.LocalPort;
    114114                    settings.UseLocalAddressDetection = false;
    115115                    settings.AutoReconnect = false;
     
    138138                    PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapper.Settings.IncludeSymmetricInResponse = false;
    139139                    PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapper.Settings.SymmetricResponseDelay = 6000;
     140                   
     141                    PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapperV2.Settings.DelaySymmetricResponse = true;
     142                    PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapperV2.Settings.IncludeSymmetricResponse = false;
    140143
    141144                    _bootstrapper = new IrcBootstrapper(scheduler);
     
    158161            {
    159162                case P2PDHTType.FullMeshDHT:
    160                     _dht = new FullMeshDHT(scheduler);
     163                    Dht = new FullMeshDHT(scheduler);
    161164                    break;
    162165                default:
     
    165168
    166169            _overlay.MessageReceived += OverlayMessageReceived;
    167             _dht.SystemJoined += OnDhtSystemJoined;
    168             _dht.SystemLeft += OnDhtSystemLeft;
    169 
    170             _versionedDht = (IVersionedDHT) _dht;
    171 
    172             _dht.Initialize(P2PSettings.Default.PeerName, string.Empty, P2PSettings.Default.WorldName, _overlay,
     170            Dht.SystemJoined += OnDhtSystemJoined;
     171            Dht.SystemLeft += OnDhtSystemLeft;
     172
     173            VersionedDht = (IVersionedDHT) Dht;
     174
     175            Dht.Initialize(P2PSettings.Default.PeerName, string.Empty, P2PSettings.Default.WorldName, _overlay,
    173176                            _bootstrapper,
    174177                            _linkmanager, null);
     
    199202            }
    200203
    201             _dht.BeginStart(null);
     204            Dht.BeginStart(null);
    202205
    203206            // Wait for event SystemJoined. When it's invoked, the peer completely joined the P2P system
     
    213216        public bool SynchStop()
    214217        {
    215             if (_dht == null) return false;
    216 
    217             _dht.BeginStop(null);
     218            if (Dht == null) return false;
     219
     220            Dht.BeginStop(null);
    218221
    219222            // wait till systemLeft Event is invoked
     
    333336
    334337            var responseWait = new ResponseWait {WaitHandle = autoResetEvent, key = key, value = data};
    335             _versionedDht.Store(OnSynchStoreCompleted, key, data, responseWait);
     338            VersionedDht.Store(OnSynchStoreCompleted, key, data, responseWait);
    336339
    337340            // blocking till response
     
    387390            var autoResetEvent = new AutoResetEvent(false);
    388391            var responseWait = new ResponseWait {WaitHandle = autoResetEvent, key = key};
    389             _dht.Retrieve(OnSynchRetrieveCompleted, key, responseWait);
     392            Dht.Retrieve(OnSynchRetrieveCompleted, key, responseWait);
    390393
    391394            // blocking till response
     
    445448            var autoResetEvent = new AutoResetEvent(false);
    446449            var responseWait = new ResponseWait {WaitHandle = autoResetEvent, key = key};
    447             _versionedDht.Remove(OnSynchRemoveCompleted, key, responseWait);
     450            VersionedDht.Remove(OnSynchRemoveCompleted, key, responseWait);
    448451
    449452            // blocking till response
     
    486489        public void LogInternalState()
    487490        {
    488             if (_dht != null)
    489             {
    490                 _dht.LogInternalState();
     491            if (Dht != null)
     492            {
     493                Dht.LogInternalState();
    491494            }
    492495        }
  • trunk/CrypP2P/P2PManager.cs

    r1545 r1579  
    2222using Cryptool.PluginBase.Miscellaneous;
    2323using Cryptool.Plugins.PeerToPeer.Internal;
     24using PeersAtPlay;
     25using PeersAtPlay.P2PStorage.DHT;
     26using PeersAtPlay.Util.Threading;
    2427
    2528namespace Cryptool.P2P
     
    145148        #endregion Framework methods
    146149
    147         #region DHT operations
     150        #region DHT operations (blocking)
    148151
    149152        /// <summary>
     
    182185
    183186        /// <summary>
    184         /// Retrieves the latest version of a given in key from the DHT.
     187        /// Retrieves the latest version of a given in key from the DHT. This method will block until a response has been received.
    185188        /// </summary>
    186189        /// <param name="key">key to retrieve</param>
     
    196199
    197200        /// <summary>
    198         /// Removes a key and its data from the DHT.
     201        /// Removes a key and its data from the DHT. This method will block until a response has been received.
    199202        ///
    200203        /// The underlying DHT is versionend. Remove attempts will fail, if the latest version has not been retrieved before.
     
    211214        }
    212215
    213         #endregion DHT operations
     216        #endregion DHT operations (blocking)
     217
     218        #region DHT operations (non-blocking)
     219
     220        /// <summary>
     221        /// Stores the given data in the DHT.
     222        ///
     223        /// The underlying DHT is versionend. Store attempts will fail, if the latest version has not been retrieved before.
     224        /// </summary>
     225        /// <param name="callback">Callback for asynchronous call</param>
     226        /// <param name="key">key to write</param>
     227        /// <param name="data">data to write</param>
     228        /// <param name="asyncState">Arbitrary data, which will be included in the callback parameter</param>
     229        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
     230        /// <returns>Guid identifying the request</returns>
     231        public static Guid Store(AsyncCallback<StoreResult> callback, string key, byte[] data, object asyncState)
     232        {
     233            if (!Instance.IsP2PConnected())
     234                throw new NotConnectedException();
     235
     236            return Instance.P2PBase.VersionedDht.Store(callback, key, data, asyncState);
     237        }
     238
     239        /// <summary>
     240        /// Retrieves the latest version of a given in key from the DHT.
     241        /// </summary>
     242        /// <param name="callback">Callback for asynchronous call</param>
     243        /// <param name="key">key to retrieve</param>
     244        /// <param name="asyncState">Arbitrary data, which will be included in the callback parameter</param>
     245        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
     246        /// <returns>Guid identifying the request</returns>
     247        public static Guid Retrieve(AsyncCallback<RetrieveResult> callback, string key, object asyncState)
     248        {
     249            if (!Instance.IsP2PConnected())
     250                throw new NotConnectedException();
     251
     252            return Instance.P2PBase.Dht.Retrieve(callback, key, asyncState);
     253        }
     254
     255        /// <summary>
     256        /// Removes a key and its data from the DHT.
     257        ///
     258        /// The underlying DHT is versionend. Remove attempts will fail, if the latest version has not been retrieved before.
     259        /// </summary>
     260        /// <param name="callback">Callback for asynchronous call</param>
     261        /// <param name="key">key to remove</param>
     262        /// <param name="asyncState">Arbitrary data, which will be included in the callback parameter</param>
     263        /// <exception cref="NotConnectedException">Will be thrown if the P2P system is not connected</exception>
     264        /// <returns>Guid identifying the request</returns>
     265        public static Guid Remove(AsyncCallback<RemoveResult> callback, string key, object asyncState)
     266        {
     267            if (!Instance.IsP2PConnected())
     268                throw new NotConnectedException();
     269
     270            return Instance.P2PBase.VersionedDht.Remove(callback, key, asyncState);
     271        }
     272
     273        #endregion DHT operations (non-blocking)
    214274    }
    215275
  • trunk/CrypP2P/P2PSettings.Designer.cs

    r1527 r1579  
    131131            }
    132132        }
     133       
     134        [global::System.Configuration.UserScopedSettingAttribute()]
     135        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     136        [global::System.Configuration.DefaultSettingValueAttribute("0")]
     137        public int LocalPort {
     138            get {
     139                return ((int)(this["LocalPort"]));
     140            }
     141            set {
     142                this["LocalPort"] = value;
     143            }
     144        }
     145       
     146        [global::System.Configuration.UserScopedSettingAttribute()]
     147        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     148        [global::System.Configuration.DefaultSettingValueAttribute("10")]
     149        public int DistributedJobListRefreshInterval {
     150            get {
     151                return ((int)(this["DistributedJobListRefreshInterval"]));
     152            }
     153            set {
     154                this["DistributedJobListRefreshInterval"] = value;
     155            }
     156        }
    133157    }
    134158}
  • trunk/CrypP2P/P2PSettings.settings

    r1527 r1579  
    3030      <Value Profile="(Default)" />
    3131    </Setting>
     32    <Setting Name="LocalPort" Type="System.Int32" Scope="User">
     33      <Value Profile="(Default)">0</Value>
     34    </Setting>
     35    <Setting Name="DistributedJobListRefreshInterval" Type="System.Int32" Scope="User">
     36      <Value Profile="(Default)">10</Value>
     37    </Setting>
    3238  </Settings>
    3339</SettingsFile>
  • trunk/CrypP2P/app.config

    r1527 r1579  
    3535                <value />
    3636            </setting>
     37            <setting name="LocalPort" serializeAs="String">
     38                <value>0</value>
     39            </setting>
     40            <setting name="DistributedJobListRefreshInterval" serializeAs="String">
     41                <value>10</value>
     42            </setting>
    3743        </Cryptool.P2P.P2PSettings>
    3844    </userSettings>
  • trunk/CrypPlugins/P2PEditor/Distributed/DistributedJob.cs

    r1563 r1579  
    7979                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    8080        }
     81
     82        public override bool Equals(object obj)
     83        {
     84            if (obj == null || GetType() != obj.GetType())
     85            {
     86                return false;
     87            }
     88
     89            return Equals((DistributedJob) obj);
     90        }
     91
     92        public bool Equals(DistributedJob obj)
     93        {
     94            if (obj == null)
     95            {
     96                return false;
     97            }
     98
     99            return obj.JobGuid == JobGuid;
     100        }
     101
     102        public override int GetHashCode()
     103        {
     104            return JobGuid.GetHashCode();
     105        }
    81106    }
    82107}
  • trunk/CrypPlugins/P2PEditor/Distributed/JobListManager.cs

    r1563 r1579  
    8282
    8383            var currentJobList = JobList();
    84             currentJobList.RemoveAll(x => x.JobGuid == distributedJobToDelete.JobGuid);
     84            currentJobList.Remove(distributedJobToDelete);
    8585
    8686            var memoryStream = new MemoryStream();
  • trunk/CrypPlugins/P2PEditor/GUI/Controls/JobDisplay.xaml.cs

    r1563 r1579  
    22using System.Collections.Generic;
    33using System.ComponentModel;
     4using System.Timers;
    45using System.Windows;
    56using System.Windows.Input;
     
    2122                                                                                    typeof (JobDisplay));
    2223
     24        private Timer _refreshListTimer;
     25
    2326        public JobDisplay()
    2427        {
    2528            InitializeComponent();
     29            UpdateRefreshTimerSettings(P2PManager.Instance.IsP2PConnected());
     30
     31            P2PManager.OnP2PConnectionStateChangeOccurred += P2PManager_OnP2PConnectionStateChangeOccurred;
     32        }
     33
     34        void P2PManager_OnP2PConnectionStateChangeOccurred(object sender, bool newState)
     35        {
     36            UpdateRefreshTimerSettings(newState);
     37        }
     38
     39        private void UpdateRefreshTimerSettings(bool isConnected)
     40        {
     41            if (P2PSettings.Default.DistributedJobListRefreshInterval == 0)
     42            {
     43                return;
     44            }
     45
     46            if (_refreshListTimer == null)
     47            {
     48                _refreshListTimer = new Timer(P2PSettings.Default.DistributedJobListRefreshInterval * 1000);
     49                _refreshListTimer.Elapsed += RefreshListTimerElapsed;
     50            }
     51
     52            if (isConnected)
     53            {
     54                _refreshListTimer.Start();
     55            }
     56            else
     57            {
     58                _refreshListTimer.Stop();
     59            }
     60        }
     61
     62        void RefreshListTimerElapsed(object sender, ElapsedEventArgs e)
     63        {
     64            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateJobList));
    2665        }
    2766
     
    4281        {
    4382            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateJobList));
    44            
    4583        }
    4684
  • trunk/CrypPlugins/P2PEditor/GUI/P2PEditorPresentation.xaml.cs

    r1563 r1579  
    4242                                        typeof (
    4343                                            P2PEditorPresentation), new PropertyMetadata(false));
    44 
    4544
    4645        public P2PEditorPresentation(P2PEditor p2PEditor, JobListManager jobListManager)
  • trunk/CrypPlugins/P2PEditor/P2PEditorSettings.cs

    r1545 r1579  
    9494        }
    9595
    96         [TaskPane("connectOnStartup_caption", "onnectOnStartup_tooltip", null, 3, true, DisplayLevel.Experienced,
     96        [TaskPane("distributedJobListRefreshInterval_caption", "distributedJobListRefreshInterval_tooltip", null, 3, false, DisplayLevel.Experienced,
     97            ControlType.NumericUpDown, ValidationType.RangeInteger, 0, int.MaxValue)]
     98        public int DistributedJobListRefreshInterval
     99        {
     100            get { return _settings.DistributedJobListRefreshInterval; }
     101            set
     102            {
     103                if (value != _settings.DistributedJobListRefreshInterval)
     104                {
     105                    _settings.DistributedJobListRefreshInterval = value;
     106                    OnPropertyChanged("DistributedJobListRefreshInterval");
     107                    HasChanges = true;
     108                }
     109            }
     110        }
     111
     112        [TaskPane("connectOnStartup_caption", "onnectOnStartup_tooltip", null, 4, true, DisplayLevel.Experienced,
    97113            ControlType.CheckBox)]
    98114        public bool ConnectOnStartup
     
    111127
    112128        // TODO make button obsolete - stop button should be fine, but is currently not suited (see todo in P2PEditor:Stop())
    113         [TaskPane("stop_caption", "stop_tooltip", null, 4, true, DisplayLevel.Beginner, ControlType.Button)]
     129        [TaskPane("stop_caption", "stop_tooltip", null, 5, true, DisplayLevel.Beginner, ControlType.Button)]
    114130        public void BtnStop()
    115131        {
     
    122138
    123139        // TODO make button obsolete - find appropriate display method
    124         [TaskPane("log_connection_state_caption", "log_connection_state_tooltip", null, 5, true, DisplayLevel.Beginner,
     140        [TaskPane("log_connection_state_caption", "log_connection_state_tooltip", null, 6, true, DisplayLevel.Beginner,
    125141            ControlType.Button)]
    126142        public void BtnLogConnectionState()
     
    196212        }
    197213
    198         [TaskPane("log2monitor_caption", "log2monitor_tooltip", GroupExpert, 4, false, DisplayLevel.Expert,
     214        [TaskPane("localPort_caption", "localPort_tooltip", GroupExpert, 4, false, DisplayLevel.Expert,
     215            ControlType.NumericUpDown, ValidationType.RangeInteger, 0, 65535)]
     216        public int LocalPort
     217        {
     218            get { return _settings.LocalPort; }
     219            set
     220            {
     221                if (value != _settings.LocalPort)
     222                {
     223                    _settings.LocalPort = value;
     224                    OnPropertyChanged("LocalPort");
     225                    HasChanges = true;
     226                }
     227            }
     228        }
     229
     230        [TaskPane("log2monitor_caption", "log2monitor_tooltip", GroupExpert, 5, false, DisplayLevel.Expert,
    199231            ControlType.CheckBox)]
    200232        public bool Log2Monitor
  • trunk/CrypPlugins/P2PEditor/Resources/Attributes.Designer.cs

    r1527 r1579  
    116116       
    117117        /// <summary>
     118        ///   Looks up a localized string similar to Job list refresh interval (seconds).
     119        /// </summary>
     120        internal static string distributedJobListRefreshInterval_caption {
     121            get {
     122                return ResourceManager.GetString("distributedJobListRefreshInterval_caption", resourceCulture);
     123            }
     124        }
     125       
     126        /// <summary>
     127        ///   Looks up a localized string similar to Refreshes the the distributed job list in the given interval. A value of 0 will disable the automated process..
     128        /// </summary>
     129        internal static string distributedJobListRefreshInterval_tooltip {
     130            get {
     131                return ResourceManager.GetString("distributedJobListRefreshInterval_tooltip", resourceCulture);
     132            }
     133        }
     134       
     135        /// <summary>
    118136        ///   Looks up a localized string similar to LinkManager type.
    119137        /// </summary>
     
    130148            get {
    131149                return ResourceManager.GetString("linkmanager_tooltip", resourceCulture);
     150            }
     151        }
     152       
     153        /// <summary>
     154        ///   Looks up a localized string similar to Local port.
     155        /// </summary>
     156        internal static string localPort_caption {
     157            get {
     158                return ResourceManager.GetString("localPort_caption", resourceCulture);
     159            }
     160        }
     161       
     162        /// <summary>
     163        ///   Looks up a localized string similar to Local port used by the framework. If set to 0, the framework will choose a random port..
     164        /// </summary>
     165        internal static string localPort_tooltip {
     166            get {
     167                return ResourceManager.GetString("localPort_tooltip", resourceCulture);
    132168            }
    133169        }
  • trunk/CrypPlugins/P2PEditor/Resources/Attributes.resx

    r1527 r1579  
    136136    <value>DHT type</value>
    137137  </data>
     138  <data name="distributedJobListRefreshInterval_caption" xml:space="preserve">
     139    <value>Job list refresh interval (seconds)</value>
     140  </data>
     141  <data name="distributedJobListRefreshInterval_tooltip" xml:space="preserve">
     142    <value>Refreshes the the distributed job list in the given interval. A value of 0 will disable the automated process.</value>
     143  </data>
    138144  <data name="linkmanager_caption" xml:space="preserve">
    139145    <value>LinkManager type</value>
     
    142148    <value>LinkManager type</value>
    143149  </data>
     150  <data name="localPort_caption" xml:space="preserve">
     151    <value>Local port</value>
     152  </data>
     153  <data name="localPort_tooltip" xml:space="preserve">
     154    <value>Local port used by the framework. If set to 0, the framework will choose a random port.</value>
     155  </data>
    144156  <data name="log2monitor_caption" xml:space="preserve">
    145157    <value>Syslog</value>
Note: See TracChangeset for help on using the changeset viewer.