Changeset 1579 for trunk/CrypP2P


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/CrypP2P
Files:
5 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>
Note: See TracChangeset for help on using the changeset viewer.