Changeset 1125


Ignore:
Timestamp:
Feb 2, 2010, 12:16:44 PM (12 years ago)
Author:
arnold
Message:

P2P: Certification tested, new KeyPatternPool integrated

Location:
trunk/CrypPlugins
Files:
2 edited

Legend:

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

    r1098 r1125  
    107107            {
    108108                for (int i = 0; i < data.Length; i++)
    109                             {
     109                {
    110110                    myQueue.Enqueue(data[i]);
    111                             }
     111                }
    112112            }
    113113
  • trunk/CrypPlugins/PeerToPeerManager/P2PManagerBase.cs

    r1098 r1125  
    4040
    4141        #region Variables
    42 
     42     
    4343        private const int MAX_IN_TOP_LIST = 10;
    4444
     
    7979        /// Stack of all left key spaces of the given Key Pattern
    8080        /// </summary>
    81         private Stack<KeyPattern> leftKeyPatterns;
     81        private KeyPatternPool leftKeyPatterns;
     82        //Stack<KeyPattern> leftKeyPatterns;
     83
    8284        /// <summary>
    8385        /// Key = PeerId, Value = Pattern (key space of key pattern)
     
    98100            : base(p2pControl)
    99101        {
    100             this.leftKeyPatterns = new Stack<KeyPattern>();
     102            //this.leftKeyPatterns = new Stack<KeyPattern>();
    101103            this.allocatedPatterns = new Dictionary<PeerId, KeyPattern>();
    102104            this.patternResults = new Dictionary<KeyPattern, LinkedList<KeySearcher.KeySearcher.ValueKey>>();
     
    173175                    GuiLogging("Deserializing result canceled: '" + UTF8Encoding.UTF8.GetString(patternResult) + "'.", NotificationLevel.Error);
    174176                }
    175                 if (this.leftKeyPatterns.Count == 0)
     177                if (this.leftKeyPatterns.Count() == 0)
    176178                {
    177179                    if (OnFinishedDistributingPatterns != null)
     
    198200            }   
    199201            // check if patterns are left
    200             if (this.leftKeyPatterns.Count != 0)
     202            if (this.leftKeyPatterns.Count() != 0)
    201203                DispersePatterns();
    202204            else
     
    224226        {
    225227            int iCycle = 0;
    226             int iFreePatternAmount = leftKeyPatterns.Count;
     228            int iFreePatternAmount = (int)this.leftKeyPatterns.Count().LongValue();
    227229
    228230            // gets only the free workers, which had register at this manager
     
    265267            GetProgressInformation();
    266268
    267             GuiLogging(iCycle.ToString() + " pattern(s) dispersed. Patterns left: " + this.leftKeyPatterns.Count.ToString(), NotificationLevel.Info);
     269            GuiLogging(iCycle.ToString() + " pattern(s) dispersed. Patterns left: " + this.leftKeyPatterns.Count().LongValue().ToString(), NotificationLevel.Info);
    268270            return iCycle;
    269271        }
     
    275277        private double GetProgressInformation()
    276278        {
    277             double leftPatterns = this.leftKeyPatterns.Count;
     279            double leftPatterns = (double)this.leftKeyPatterns.Count().LongValue();
    278280            double finishedPatterns = this.patternResults.Count;
    279281            double patternsInProcess = this.allocatedPatterns.Count;
     
    338340            GuiLogging("Begin building a KeyPatternPool with KeyPatternPartSize " + this.KeyPatternPartSize.ToString(), NotificationLevel.Debug);
    339341
    340            
    341             /* TODO: Implement Stack instead of Queue later
    342              * At present: workaround this shit */
    343 
    344             //List<KeyPattern> arrKeyPatternPool = keyPattern.makeKeySearcherPool(this.KeyPatternPartSize);
    345             //GuiLogging("Enqueue " + arrKeyPatternPool.Count + " KeyPattern-Parts to the JobList.", NotificationLevel.Debug);
    346             //foreach (KeyPattern keyPatternPart in arrKeyPatternPool)
     342            /* BEGIN: Use new KeyPatternPool */
     343            this.leftKeyPatterns = new KeyPatternPool(keyPattern, this.KeyPatternPartSize);
     344            GuiLogging("Enqueue " + this.leftKeyPatterns.Count().LongValue().ToString() + " KeyPattern-Parts to the JobList.", NotificationLevel.Debug);
     345            /* END: Use new KeyPatternPool */
     346
     347            /* BEGIN: Workaround till Count and Contains is fixed by S.Rech */
     348            //KeyPatternPool keyPatternPool = new KeyPatternPool(keyPatternPool, this.KeyPatternPartSize);
     349            //KeyPattern tempPattern = keyPatternPool.Pop();
     350            //while (tempPattern != null)
    347351            //{
    348             //    this.leftKeyPatterns.Enqueue(keyPatternPart);
     352            //    this.leftKeyPatterns.Push(tempPattern);
     353            //    tempPattern = keyPatternPool.Pop();
    349354            //}
    350 
    351             leftKeyPatterns = keyPattern.makeKeySearcherPool(this.keyPatternPartSize);
    352             GuiLogging("Enqueue " + leftKeyPatterns.Count + " KeyPattern-Parts to the JobList.", NotificationLevel.Debug);
    353             //int keyCount = keyPatternPool.Count;
    354             //for (int j = 0; j < keyCount; j++)
    355             //{
    356             //    KeyPattern newPattern = keyPatternPool.Pop();
    357             //    if (newPattern != null)
    358             //        this.leftKeyPatterns.Enqueue(newPattern);
    359             //    else
    360             //        break;
    361             //}
    362            
    363             /* ************************************** */
    364             /* BEGIN: Only for debugging reasons - to delete */     
    365             //StreamWriter debugWriter = DebugToFile.GetDebugStreamWriter();
    366             //int i = 0;
    367             //foreach (KeyPattern patternPart in this.leftKeyPatterns.ToList<KeyPattern>())
    368             //{
    369             //    debugWriter.WriteLine(i + "\t" + patternPart.ToString());
    370             //    i++;
    371             //}
    372             //debugWriter.Dispose();
    373 
    374             /* END: Only for debugging reasons - to delete */
    375             /* ************************************** */
    376 
     355            //GuiLogging("Enqueue " + this.leftKeyPatterns.Count + " KeyPattern-Parts to the JobList.", NotificationLevel.Debug);
     356            /* END: Workaround till Count and Contains is fixed by S.Rech */
    377357
    378358            #region Storing EncryptedData and InitializationVector in DHT
     359
    379360            bool encryptedTextStored = DHT_CommonManagement.SetEncryptedData(ref this.p2pControl, sTopic, encryptedData);
    380361            bool initVectorStored = DHT_CommonManagement.SetInitializationVector(ref this.p2pControl, sTopic, initVector);
    381 
    382             //CryptoolStream newEncryptedData = new CryptoolStream();
    383             //newEncryptedData.OpenRead(encryptedData.FileName);
    384             //if (newEncryptedData.CanRead)
    385             //{
    386             //    // Convert CryptoolStream to an byte Array and store it in the DHT
    387             //    if (newEncryptedData.Length > Int32.MaxValue)
    388             //        throw (new Exception("Encrypted Data are too long for this PlugIn. The maximum size of Data is " + Int32.MaxValue + "!"));
    389             //    byte[] byteEncryptedData = new byte[newEncryptedData.Length];
    390             //    int k = newEncryptedData.Read(byteEncryptedData, 0, (int)newEncryptedData.Length - 1);
    391             //    encryptedTextStored = this.p2pControl.DHTstore(sTopic + DHT_ENCRYPTED_TEXT, byteEncryptedData);
    392             //}
    393             //else
    394             //{
    395             //    GuiLogging("Reading CryptoolStream wasn't possible.", NotificationLevel.Error);
    396             //    return false;
    397             //}
    398             //// Convert  to an byte Array and store Initialization Vector it in the DHT
    399             //initVectorStored = this.p2pControl.DHTstore(sTopic + DHT_INIT_VECTOR, initVector);
    400362
    401363            GuiLogging("DHT: Encrypted data stored: '" + encryptedTextStored + "', Initialization vector stored: '" + initVectorStored + "'", NotificationLevel.Debug);
     
    489451        public int LeftPatterns
    490452        {
    491             get { return this.leftKeyPatterns.Count; }
     453            get { return (int)this.leftKeyPatterns.Count().LongValue(); }
    492454        }
    493455        public int FinishedPatterns
Note: See TracChangeset for help on using the changeset viewer.