Changeset 1698


Ignore:
Timestamp:
Jun 24, 2010, 1:15:16 PM (11 years ago)
Author:
Paul Lelgemann
Message:

o Refactoring in CrypP2P
o AES: NullReference in AES-Plugin fixed
o Small fixes in KeySearcher, StorageKeyGenerator uses IV and truncates input data

Location:
trunk
Files:
9 edited

Legend:

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

    r1616 r1698  
    2323    public class ConnectionManager
    2424    {
     25        #region Delegates
     26
    2527        public delegate void P2PConnectionStateChangeEventHandler(object sender, bool newState);
    26         public event P2PConnectionStateChangeEventHandler OnP2PConnectionStateChangeOccurred;
    2728
    28         private readonly object _connectLock = new object();
    29         private readonly P2PBase _p2PBase;
     29        #endregion
    3030
    31         public bool IsConnecting { get; internal set; }
     31        private readonly object connectLock = new object();
     32        private readonly P2PBase p2PBase;
    3233
    3334        public ConnectionManager(P2PBase p2PBase)
    3435        {
    35             _p2PBase = p2PBase;
     36            this.p2PBase = p2PBase;
    3637        }
     38
     39        public bool IsConnecting { get; internal set; }
     40        public event P2PConnectionStateChangeEventHandler OnP2PConnectionStateChangeOccurred;
    3741
    3842        public void Connect()
    3943        {
    40             lock (_connectLock)
     44            lock (connectLock)
    4145            {
    42                 if (_p2PBase.IsConnected || IsConnecting)
     46                if (p2PBase.IsConnected || IsConnecting)
    4347                {
    44                     P2PManager.GuiLogMessage("Cannot connect, already connected or connecting.", NotificationLevel.Warning);
     48                    P2PManager.GuiLogMessage("Cannot connect, already connected or connecting.",
     49                                             NotificationLevel.Warning);
    4550                    return;
    4651                }
     
    5661
    5762            P2PManager.GuiLogMessage("Dispatching connect request with ConnectionWorker.", NotificationLevel.Debug);
    58             new ConnectionWorker(_p2PBase, this).Start();
     63            new ConnectionWorker(p2PBase, this).Start();
    5964        }
    6065
    6166        public void Disconnect()
    6267        {
    63             lock (_connectLock)
     68            lock (connectLock)
    6469            {
    65                 if (!_p2PBase.IsConnected || IsConnecting)
     70                if (!p2PBase.IsConnected || IsConnecting)
    6671                {
    67                     P2PManager.GuiLogMessage("Cannot disconnect, no connection or connection attempt active.", NotificationLevel.Warning);
     72                    P2PManager.GuiLogMessage("Cannot disconnect, no connection or connection attempt active.",
     73                                             NotificationLevel.Warning);
    6874                    return;
    6975                }
    70                
     76
    7177                IsConnecting = true;
    7278            }
    7379
    7480            P2PManager.GuiLogMessage("Dispatching disconnect request with ConnectionWorker.", NotificationLevel.Debug);
    75             new ConnectionWorker(_p2PBase, this).Start();
     81            new ConnectionWorker(p2PBase, this).Start();
    7682        }
    7783
     
    8692            if (String.IsNullOrEmpty(P2PSettings.Default.PeerName))
    8793            {
    88                 P2PManager.GuiLogMessage("Peer-to-peer not fully configured: world name missing.", NotificationLevel.Error);
     94                P2PManager.GuiLogMessage("Peer-to-peer not fully configured: world name missing.",
     95                                         NotificationLevel.Error);
    8996                return false;
    9097            }
     
    97104            if (OnP2PConnectionStateChangeOccurred != null)
    98105            {
    99                 OnP2PConnectionStateChangeOccurred(this, _p2PBase.IsConnected);
     106                OnP2PConnectionStateChangeOccurred(this, p2PBase.IsConnected);
    100107            }
    101108        }
  • trunk/CrypP2P/Internal/P2PBase.cs

    r1696 r1698  
    5151        #region Variables
    5252
    53         private readonly AutoResetEvent _systemJoined;
    54         private readonly AutoResetEvent _systemLeft;
    55         private IBootstrapper _bootstrapper;
    56         private IP2PLinkManager _linkmanager;
    57         private P2POverlay _overlay;
     53        private readonly AutoResetEvent systemJoined;
     54        private readonly AutoResetEvent systemLeft;
     55        private IBootstrapper bootstrapper;
     56        private IP2PLinkManager linkmanager;
     57        private P2POverlay overlay;
    5858        internal IDHT Dht;
    5959        internal IVersionedDHT VersionedDht;
     
    8989            IsInitialized = false;
    9090
    91             _systemJoined = new AutoResetEvent(false);
    92             _systemLeft = new AutoResetEvent(false);
     91            systemJoined = new AutoResetEvent(false);
     92            systemLeft = new AutoResetEvent(false);
    9393        }
    9494
     
    108108
    109109                    // NAT-Traversal stuff needs a different Snal-Version
    110                     _linkmanager = new Snal(scheduler);
     110                    linkmanager = new Snal(scheduler);
    111111
    112112                    var settings = new PeersAtPlay.P2PLink.SnalNG.Settings();
     
    136136                    }
    137137
    138                     _linkmanager.Settings = settings;
    139                     _linkmanager.ApplicationType = ApplicationType.CrypTool;
     138                    linkmanager.Settings = settings;
     139                    linkmanager.ApplicationType = ApplicationType.CrypTool;
    140140
    141141                    break;
     
    148148                case P2PBootstrapperType.LocalMachineBootstrapper:
    149149                    // LocalMachineBootstrapper = only local connection (runs only on one machine)
    150                     _bootstrapper = new LocalMachineBootstrapper();
     150                    bootstrapper = new LocalMachineBootstrapper();
    151151                    break;
    152152                case P2PBootstrapperType.IrcBootstrapper:
     
    155155                    PeersAtPlay.P2POverlay.Bootstrapper.IrcBootstrapperV2.Settings.UsePeerCache = false;
    156156
    157                     _bootstrapper = new IrcBootstrapper(scheduler);
     157                    bootstrapper = new IrcBootstrapper(scheduler);
    158158                    break;
    159159                default:
     
    164164            {
    165165                case P2PArchitecture.FullMesh:
    166                     _overlay = new FullMeshOverlay(scheduler);
     166                    overlay = new FullMeshOverlay(scheduler);
    167167                    Dht = new FullMeshDHT(scheduler);
    168168                    break;
    169169                case P2PArchitecture.Chord:
    170                     _overlay = new ChordNGCore(scheduler);
    171                     Dht = (IDHT) _overlay;
     170                    overlay = new ChordNGCore(scheduler);
     171                    Dht = (IDHT) overlay;
    172172                    break;
    173173                default:
     
    175175            }
    176176
    177             _overlay.MessageReceived += OverlayMessageReceived;
     177            overlay.MessageReceived += OverlayMessageReceived;
    178178            Dht.SystemJoined += OnDhtSystemJoined;
    179179            Dht.SystemLeft += OnDhtSystemLeft;
     
    183183            P2PManager.GuiLogMessage("Initializing DHT with world name " + P2PSettings.Default.WorldName,
    184184                                                NotificationLevel.Info);
    185             Dht.Initialize(P2PSettings.Default.PeerName, string.Empty, P2PSettings.Default.WorldName, _overlay,
    186                             _bootstrapper,
    187                             _linkmanager, null);
     185            Dht.Initialize(P2PSettings.Default.PeerName, string.Empty, P2PSettings.Default.WorldName, overlay,
     186                            bootstrapper,
     187                            linkmanager, null);
    188188
    189189            IsInitialized = true;
     
    215215
    216216            // Wait for event SystemJoined. When it's invoked, the peer completely joined the P2P system
    217             _systemJoined.WaitOne();
     217            systemJoined.WaitOne();
    218218            P2PManager.GuiLogMessage("System join process ended.", NotificationLevel.Debug);
    219219
     
    242242
    243243            // wait till systemLeft Event is invoked
    244             _systemLeft.WaitOne();
     244            systemLeft.WaitOne();
    245245
    246246            return true;
     
    258258        public PeerId GetPeerId(out string sPeerName)
    259259        {
    260             sPeerName = _linkmanager.UserName;
    261             return new PeerId(_overlay.LocalAddress);
     260            sPeerName = linkmanager.UserName;
     261            return new PeerId(overlay.LocalAddress);
    262262        }
    263263
     
    270270        {
    271271            LogToMonitor("GetPeerID: Converting byte[] to PeerId-Object");
    272             return new PeerId(_overlay.GetAddress(byteId));
     272            return new PeerId(overlay.GetAddress(byteId));
    273273        }
    274274
     
    277277        {
    278278            // get stack size of the pap use-data and add own use data (for optimizing Stack size)
    279             var realStackSize = _overlay.GetHeaderSize() + data.Length;
     279            var realStackSize = overlay.GetHeaderSize() + data.Length;
    280280
    281281            var stackData = new ByteStack(realStackSize);
    282282            stackData.Push(data);
    283283
    284             var destinationAddr = _overlay.GetAddress(destinationPeer);
     284            var destinationAddr = overlay.GetAddress(destinationPeer);
    285285            var overlayMsg = new OverlayMessage(MessageReceiverType.P2PBase,
    286                                                 _overlay.LocalAddress, destinationAddr, stackData);
    287 
    288             _overlay.Send(overlayMsg);
     286                                                overlay.LocalAddress, destinationAddr, stackData);
     287
     288            overlay.Send(overlayMsg);
    289289        }
    290290
     
    319319                OnSystemJoined();
    320320
    321             _systemJoined.Set();
     321            systemJoined.Set();
    322322            IsConnected = true;
    323323        }
     
    333333            // Allow new connection to start and check for waiting / blocked tasks
    334334            // TODO reset running ConnectionWorkers?
    335             _systemLeft.Set();
    336             _systemJoined.Set();
     335            systemLeft.Set();
     336            systemJoined.Set();
    337337
    338338            LogToMonitor("CrypP2P left the system.");
  • trunk/CrypP2P/Internal/RequestType.cs

    r1665 r1698  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 
    6 namespace Cryptool.P2P.Internal
     1namespace Cryptool.P2P.Internal
    72{
    83    public enum RequestType
  • trunk/CrypP2P/Worker/ConnectionWorker.cs

    r1616 r1698  
    1515*/
    1616
    17 using System;
    1817using System.ComponentModel;
    1918using Cryptool.P2P.Helper;
     
    2524    internal class ConnectionWorker : WorkerBase
    2625    {
    27         private readonly P2PBase _p2PBase;
    28         private readonly ConnectionManager _connectionManager;
     26        private readonly P2PBase p2PBase;
     27        private readonly ConnectionManager connectionManager;
    2928
    3029        public ConnectionWorker(P2PBase p2PBase, ConnectionManager connectionManager)
    3130        {
    32             _p2PBase = p2PBase;
    33             _connectionManager = connectionManager;
     31            this.p2PBase = p2PBase;
     32            this.connectionManager = connectionManager;
    3433        }
    3534
     
    3736        {
    3837            P2PManager.GuiLogMessage(
    39                 _p2PBase.IsConnected
     38                p2PBase.IsConnected
    4039                    ? "Connection to P2P network established."
    4140                    : "Connection to P2P network terminated.", NotificationLevel.Info);
    42             _connectionManager.IsConnecting = false;
    43             _connectionManager.FireConnectionStatusChange();
     41            connectionManager.IsConnecting = false;
     42            connectionManager.FireConnectionStatusChange();
    4443        }
    4544
    4645        protected override void PerformWork(object sender, DoWorkEventArgs e)
    4746        {
    48             if (!_p2PBase.IsConnected)
     47            if (!p2PBase.IsConnected)
    4948            {
    5049                P2PManager.GuiLogMessage("Connecting to P2P network...", NotificationLevel.Info);
     
    5857                }
    5958
    60                 _p2PBase.Initialize();
    61                 _p2PBase.SynchStart();
     59                p2PBase.Initialize();
     60                p2PBase.SynchStart();
    6261            }
    6362            else
    6463            {
    6564                P2PManager.GuiLogMessage("Disconnecting from P2P network...", NotificationLevel.Info);
    66                 _p2PBase.SynchStop();
     65                p2PBase.SynchStop();
    6766            }
    6867        }
  • trunk/CrypPlugins/AES/AES.cs

    r1259 r1698  
    121121                CryptoolStream cs = new CryptoolStream();
    122122                listCryptoolStreamsOut.Add(cs);
     123
     124                  if (outputStream.FileName == null)
     125                  {
     126                      return null;
     127                  }
     128
    123129                cs.OpenRead(this.outputStream.FileName);
    124130                return cs;
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1682 r1698  
    33using System.Text;
    44using Cryptool.P2P;
     5using Cryptool.P2P.Internal;
    56using Cryptool.PluginBase.Analysis;
    67using Cryptool.PluginBase;
     
    3435        /// </summary>
    3536        private int maxThread;
    36         private Mutex maxThreadMutex = new Mutex();
     37        private readonly Mutex maxThreadMutex = new Mutex();
    3738
    3839        private KeyQualityHelper keyQualityHelper;
    39         private P2PQuickWatchPresentation p2PQuickWatchPresentation;
    40         private LocalQuickWatchPresentation localQuickWatchPresentation;
    41 
    42         private KeyPattern.KeyPattern pattern = null;
     40        private readonly P2PQuickWatchPresentation p2PQuickWatchPresentation;
     41        private readonly LocalQuickWatchPresentation localQuickWatchPresentation;
     42
     43        private KeyPattern.KeyPattern pattern;
    4344        public KeyPattern.KeyPattern Pattern
    4445        {
     
    614615            GuiLogMessage("Launching p2p based bruteforce logic...", NotificationLevel.Info);
    615616            ValidateConnectionToPeerToPeerSystem();
    616             distributedBruteForceManager = new DistributedBruteForceManager(this, pattern, settings, keyQualityHelper,
    617                                                                      p2PQuickWatchPresentation);
    618             distributedBruteForceManager.Execute();
     617
     618            try
     619            {
     620                distributedBruteForceManager = new DistributedBruteForceManager(this, pattern, settings,
     621                                                                                keyQualityHelper,
     622                                                                                p2PQuickWatchPresentation);
     623                distributedBruteForceManager.Execute();
     624            }
     625            catch (NotConnectedException)
     626            {
     627                GuiLogMessage("P2P not connected.", NotificationLevel.Error);
     628            }
    619629        }
    620630
  • trunk/CrypPlugins/KeySearcher/P2P/DistributedBruteForceManager.cs

    r1693 r1698  
    3939            }
    4040
     41            StopWatch = new Stopwatch();
     42            status = new StatusContainer();
     43            status.IsCurrentProgressIndeterminate = true;
     44
    4145            keyGenerator = new StorageKeyGenerator(keySearcher, settings);
    4246            patternPool = new KeyPatternPool(keyPattern, new BigInteger(Math.Pow(2, settings.ChunkSize)));
    43             status = new StatusContainer();
    4447            StatisticsGenerator = new StatisticsGenerator(status, quickWatch, keySearcher, settings, this);
    45             keyPoolTree = new KeyPoolTree(patternPool, this.keySearcher, keyQualityHelper, keyGenerator, status, StatisticsGenerator);
    46             StopWatch = new Stopwatch();
    47 
    4848            quickWatch.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(UpdateStatusContainerInQuickWatch));
    4949
     50            keyPoolTree = new KeyPoolTree(patternPool, this.keySearcher, keyQualityHelper, keyGenerator, status, StatisticsGenerator);
     51           
    5052            keySearcher.GuiLogMessage(
    5153                "Total amount of patterns: " + patternPool.Length + ", each containing " + patternPool.PartSize +
     
    5860            while (!keySearcher.stop)
    5961            {
     62                status.IsCurrentProgressIndeterminate = true;
     63
    6064                try
    6165                {
     
    6872                catch (AlreadyCalculatedException)
    6973                {
    70                     keySearcher.GuiLogMessage("Node was already calculated.", NotificationLevel.Warning);
     74                    keySearcher.GuiLogMessage("Node was already calculated.", NotificationLevel.Info);
    7175                    keyPoolTree.Reset();
    7276                    continue;
     
    7983                        "Pattern #" + currentLeaf.PatternId() +
    8084                        " was reserved before it could be reserved for this CrypTool instance.",
    81                         NotificationLevel.Warning);
     85                        NotificationLevel.Info);
    8286                    keyPoolTree.Reset();
    8387                    continue;
     
    118122                    keySearcher.GuiLogMessage("Reservation removed by another node (while calculating). " +
    119123                                              "To avoid a state in limbo, proceeding to first available leaf...",
    120                                               NotificationLevel.Warning);
     124                                              NotificationLevel.Info);
    121125                    keyPoolTree.Reset();
    122126                    continue;
     
    124128                catch (UpdateFailedException e)
    125129                {
    126                     keySearcher.GuiLogMessage("Could not store results: " + e.Message, NotificationLevel.Warning);
     130                    keySearcher.GuiLogMessage("Could not store results: " + e.Message, NotificationLevel.Info);
    127131                    keyPoolTree.Reset();
    128132                    continue;
     
    135139                keySearcher.showProgress(keySearcher.costList, 1, 1, 1);
    136140                keySearcher.GuiLogMessage("Calculation complete.", NotificationLevel.Info);
    137                 status.ProgressOfCurrentChunk = 0;
    138                 status.IsSearchingForReservedNodes = false;
     141               
    139142            }
     143
     144            status.ProgressOfCurrentChunk = 0;
     145            status.IsSearchingForReservedNodes = false;
     146            status.IsCurrentProgressIndeterminate = false;
    140147        }
    141148
  • trunk/CrypPlugins/KeySearcher/P2P/Storage/StorageKeyGenerator.cs

    r1674 r1698  
    1414            this.keySearcher = keySearcher;
    1515            this.settings = settings;
    16            
    1716        }
    1817
    1918        public String Generate()
    2019        {
     20            var bytesToUse = keySearcher.CostMaster.getBytesToUse();
    2121            var rawIdentifier = "P2PJOB";
    2222            rawIdentifier += settings.ChunkSize + settings.Key;
    2323            rawIdentifier += keySearcher.ControlMaster.GetType();
    2424            rawIdentifier += keySearcher.CostMaster.GetType();
    25             rawIdentifier += keySearcher.CostMaster.getBytesToUse();
     25            rawIdentifier += bytesToUse;
    2626            rawIdentifier += keySearcher.CostMaster.getRelationOperator();
    27             rawIdentifier += Encoding.ASCII.GetString(keySearcher.EncryptedData);
     27
     28            if (keySearcher.InitVector != null)
     29            {
     30                rawIdentifier += Encoding.ASCII.GetString(keySearcher.InitVector);
     31            }
     32
     33            var inputData = Encoding.ASCII.GetString(keySearcher.EncryptedData);
     34            if (inputData.Length > bytesToUse)
     35            {
     36                inputData = inputData.Substring(0, bytesToUse);
     37            }
     38
     39            rawIdentifier += inputData;
    2840
    2941            var hashAlgorithm = new SHA1CryptoServiceProvider();
  • trunk/CrypPlugins/KeySearcher/Presentation/Controls/P2PQuickWatchPresentation.xaml

    r1682 r1698  
    5555                                                <Label Content="Remaining time:" Height="28" HorizontalAlignment="Left" Margin="0,6,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" />
    5656                                                <Label Content="{Binding RemainingTime, FallbackValue=-}" Height="28" HorizontalAlignment="Left" Margin="120,6,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.Row="1" />
    57                                                 <ProgressBar Value="{Binding ProgressOfCurrentChunk, FallbackValue=0}" IsIndeterminate="{Binding IsCrrentProgressIndeterminate, FallbackValue=false}" Grid.ColumnSpan="2" Grid.Row="2" Height="24" HorizontalAlignment="Left" Margin="0,6,0,0" VerticalAlignment="Top" Width="400" Maximum="1" />
     57                                                <ProgressBar Value="{Binding ProgressOfCurrentChunk, FallbackValue=0}" IsIndeterminate="{Binding IsCurrentProgressIndeterminate, FallbackValue=false}" Grid.ColumnSpan="2" Grid.Row="2" Height="24" HorizontalAlignment="Left" Margin="0,6,0,0" VerticalAlignment="Top" Width="400" Maximum="1" />
    5858                                        </Grid>
    5959                                </Border>
Note: See TracChangeset for help on using the changeset viewer.