Changeset 1525


Ignore:
Timestamp:
May 28, 2010, 12:29:53 PM (12 years ago)
Author:
Sven Rech
Message:

quadratic sieve stuff

Location:
trunk/CrypPlugins/QuadraticSieve
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/QuadraticSieve/FactorManager.cs

    r1521 r1525  
    2727namespace Cryptool.Plugins.QuadraticSieve
    2828{
     29    [Serializable]
    2930    class FactorManager
    3031    {
    3132        private List<BigInteger> primeFactors = new List<BigInteger>();
    3233        private List<BigInteger> compositeFactors = new List<BigInteger>();
     34
     35        [NonSerialized]
    3336        private MethodInfo getPrimeFactorsMethod;
     37        [NonSerialized]
    3438        private MethodInfo getCompositeFactorsMethod;
    3539
  • trunk/CrypPlugins/QuadraticSieve/PeerToPeer.cs

    r1521 r1525  
    2626using System.Collections;
    2727using System.Threading;
     28using System.Windows.Threading;
     29using System.Runtime.Serialization.Formatters.Binary;
    2830
    2931namespace Cryptool.Plugins.QuadraticSieve
     
    3941        private Thread loadStoreThread;
    4042        private bool stopLoadStoreThread;
     43        private QuadraticSievePresentation quadraticSieveQuickWatchPresentation;
     44
     45        public PeerToPeer(QuadraticSievePresentation presentation)
     46        {
     47            quadraticSieveQuickWatchPresentation = presentation;
     48        }
    4149
    4250        private byte[] ReadYield(int index)
     
    6068
    6169            while (!stopLoadStoreThread)
    62             {
    63                 if (loadIndex >= loadEnd)   //if we already loaded the yields up to "loadEnd", we don't have too much to do anymore, so we can slow down :)
    64                     Thread.Sleep(1000);
    65 
     70            {               
    6671                if (storequeue.Count != 0)  //storing has priority
    6772                {
     
    6974                    P2PManager.Store(YieldIdentifier(head), yield);
    7075                    //TODO: If versioning sytem tells us, that there is already a newer entry here, we load this value, enqueue it in loadqueue and try again with head++
     76                    SetProgressYield(head, YieldStatus.Ours);
    7177                    head++;
    7278                    P2PManager.Store(HeadIdentifier(), head.ToString());
    7379                    //TODO: If versioning system tells us, that there is already a newer head entry, we ignore this and don't store ours
    7480                }
    75                 else                      //if there is nothing to store, we can load the yields up to "loadEnd"
     81                else                      //if there is nothing to store, we can load the yields up to "loadEnd".
    7682                {
    7783                    if (loadIndex < loadEnd)
     
    7985                        byte[] yield = ReadYield(loadIndex);
    8086                        loadqueue.Enqueue(yield);
     87                        SetProgressYield(loadIndex, YieldStatus.OthersLoaded);
    8188                        loadIndex++;
    8289                    }
     90                    else                //if there is nothing left to load, we can slow down.
     91                    {
     92                        Thread.Sleep(1000);
     93                    }
    8394                }
    8495            }
    8596        }
    8697
     98        private void SetProgressYield(int index, YieldStatus status)
     99        {
     100            quadraticSieveQuickWatchPresentation.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     101            {
     102                quadraticSieveQuickWatchPresentation.ProgressYields[index] = status;
     103            }, null);
     104        }
     105
     106        private void ClearProgressYields()
     107        {
     108            quadraticSieveQuickWatchPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     109            {
     110                quadraticSieveQuickWatchPresentation.ProgressYields.Clear();
     111            }, null);
     112        }
     113
    87114        private string HeadIdentifier()
    88115        {
    89116            return channel + "#" + factor + "HEAD";
     117        }
     118
     119        private string FactorListIdentifier()
     120        {
     121            return channel + "#" + number + "FACTORLIST";
    90122        }
    91123
     
    156188            Debug.Assert(this.number % this.factor == 0);
    157189
     190            ClearProgressYields();
    158191            byte[] h = P2PManager.Retrieve(HeadIdentifier());
    159192            if (h != null)
     193            {
    160194                head = int.Parse(h.ToString());
     195                SetProgressYield(head, YieldStatus.OthersNotLoaded);
     196            }
    161197            else
    162198                head = 0;
     
    173209        public bool SyncFactorManager(FactorManager factorManager)
    174210        {
    175             FactorManager dhtFactorManager = new FactorManager(null, null);
    176             //TODO: add factors from dht to dhtFactorManager here.
    177 
     211            FactorManager dhtFactorManager = null;
     212            //load DHT Factor Manager:
     213            byte[] dhtFactorManagerBytes = P2PManager.Retrieve(FactorListIdentifier());
     214            if (dhtFactorManagerBytes != null)
     215            {
     216                MemoryStream memstream = new MemoryStream();
     217                memstream.Write(dhtFactorManagerBytes, 0, dhtFactorManagerBytes.Length);
     218                BinaryFormatter bformatter = new BinaryFormatter();
     219                dhtFactorManager = (FactorManager)bformatter.Deserialize(memstream);
     220            }
     221
     222            //Synchronize DHT Factor Manager with our Factor List
    178223            if (dhtFactorManager == null || factorManager.Synchronize(dhtFactorManager))
    179224            {
    180                 //TODO: store factorManager to DHT
     225                //Our Factor Manager has more informations, so let's store it in the DHT:
     226                MemoryStream memstream = new MemoryStream();
     227                BinaryFormatter bformatter = new BinaryFormatter();
     228                bformatter.Serialize(memstream, factorManager);
     229                P2PManager.Store(FactorListIdentifier(), memstream.ToArray());
    181230            }
    182231
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSieve.cs

    r1522 r1525  
    6161        private bool userStopped = false;
    6262        private FactorManager factorManager;
    63         private PeerToPeer peerToPeer = new PeerToPeer();
     63        private PeerToPeer peerToPeer;
    6464        private uint sumSize = 0;
    6565        private bool usePeer2Peer;
     
    9595
    9696            QuickWatchPresentation = new QuadraticSievePresentation();
     97
     98            peerToPeer = new PeerToPeer(quadraticSieveQuickWatchPresentation);
    9799           
    98100            quadraticSieveQuickWatchPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
Note: See TracChangeset for help on using the changeset viewer.