Changeset 1653


Ignore:
Timestamp:
Jun 15, 2010, 11:55:06 PM (12 years ago)
Author:
Sven Rech
Message:

quadratic sieve fixes

Location:
trunk/CrypPlugins/QuadraticSieve
Files:
4 edited

Legend:

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

    r1648 r1653  
    6969        private int aliveCounter = 0;       //This is stored together with the performance in the DHT
    7070        private string ourName;
     71        private uint downloaded = 0;
     72        private uint uploaded = 0;
    7173
    7274        public delegate void P2PWarningHandler(String warning);
     
    106108            if (yield == null)
    107109                return null;
     110            downloaded += (uint)yield.Length;
    108111
    109112            byte[] decompressedYield = DecompressYield(yield);
     
    114117            byte[] y = new byte[decompressedYield.Length - 4];
    115118            Array.Copy(decompressedYield, 4, y, 0, y.Length);
    116 
    117             ownerID = -1;
    118 
     119           
    119120            return y;
    120121        }
     
    133134        }
    134135
    135         private uint ReadAndEnqueueYield(int loadIndex, uint downloaded, uint uploaded)
     136        private bool ReadAndEnqueueYield(int loadIndex)
    136137        {
    137138            int ownerID;
     
    139140            if (yield != null)
    140141            {
    141                 downloaded += (uint)yield.Length;
    142142                ShowTransfered(downloaded, uploaded);
    143143                loadqueue.Enqueue(yield);
    144144
    145                 //Progress Yield:
    146                 if (!nameCache.ContainsKey(ownerID))
    147                 {
    148                     byte[] n = P2PManager.Retrieve(NameIdentifier(ownerID));
    149                     if (n != null)
    150                         nameCache.Add(ownerID, System.Text.ASCIIEncoding.ASCII.GetString(n));
     145                string name = null;
     146
     147                if (ownerID != ourID)
     148                {
     149                    //Progress Yield:
     150                    if (!nameCache.ContainsKey(ownerID))
     151                    {
     152                        byte[] n = P2PManager.Retrieve(NameIdentifier(ownerID));
     153                        if (n != null)
     154                            nameCache.Add(ownerID, System.Text.ASCIIEncoding.ASCII.GetString(n));
     155                    }
     156                    if (nameCache.ContainsKey(ownerID))
     157                        name = nameCache[ownerID];
     158
     159                    //Performance and alive informations:
     160                    if (!activePeers.Contains(ownerID))
     161                    {
     162                        UpdatePeerPerformanceAndAliveInformation(ownerID);
     163                        activePeers.Add(ownerID);
     164                        UpdateActivePeerInformation();
     165                    }
    151166                }
    152                 string name = null;
    153                 if (nameCache.ContainsKey(ownerID))
    154                     name = nameCache[ownerID];
     167
     168                //Set progress info:
    155169                SetProgressYield(loadIndex, ownerID, name);
    156170
    157                 //Performance and alive informations:
    158                 if (!activePeers.Contains(ownerID))
    159                 {
    160                     UpdatePeerPerformanceAndAliveInformation(ownerID);
    161                     activePeers.Add(ownerID);
    162                     UpdateActivePeerInformation();
    163                 }
    164 
    165171                yieldEvent.Set();
    166                 return downloaded;
    167             }
    168             return 0;
     172                return true;
     173            }
     174            return false;
    169175        }
    170176
     
    173179        /// If it fails, it stores the index in lostIndices queue.
    174180        /// </summary>
    175         private uint TryReadAndEnqueueYield(int index, uint downloaded, uint uploaded, Queue<KeyValuePair<int, DateTime>> lostIndices)
    176         {
    177             uint res = ReadAndEnqueueYield(index, downloaded, uploaded);
    178             if (res != 0)
    179                 downloaded = res;
    180             else
     181        private void TryReadAndEnqueueYield(int index, Queue<KeyValuePair<int, DateTime>> lostIndices)
     182        {
     183            bool succ = ReadAndEnqueueYield(index);
     184            if (!succ)               
    181185            {
    182186                var e = new KeyValuePair<int, DateTime>(index, DateTime.Now);
     
    184188                SetProgressYield(index, -1, null);
    185189            }
    186 
    187             return downloaded;
    188190        }
    189191
     
    191193        {
    192194            int loadIndex = 0;
    193             uint downloaded = 0;
    194             uint uploaded = 0;
     195            downloaded = 0;
     196            uploaded = 0;
    195197            HashSet<int> ourIndices = new HashSet<int>();   //Stores all the indices which belong to our packets
    196198            //Stores all the indices (together with there check date) which belong to lost packets (i.e. packets that can't be load anymore):
     
    268270                    if (loadIndex < head)
    269271                    {
    270                         downloaded = TryReadAndEnqueueYield(loadIndex, downloaded, uploaded, lostIndices);
     272                        TryReadAndEnqueueYield(loadIndex, lostIndices);
    271273                        loadIndex++;
    272274                        busy = true;
     
    276278                    if (!busy)
    277279                    {
    278                         int count = 0;                       
     280                        int count = 0;
    279281                        //TODO: Maybe we should throw away those indices, which have been checked more than several times.
    280282                        while (lostIndices.Count != 0 && lostIndices.Peek().Value.CompareTo(DateTime.Now.Subtract(new TimeSpan(0, 2, 0))) < 0)
    281283                        {
    282284                            var e = lostIndices.Dequeue();
    283                             downloaded = TryReadAndEnqueueYield(loadIndex, downloaded, uploaded, lostIndices);
     285                            TryReadAndEnqueueYield(loadIndex, lostIndices);
    284286                            count++;
    285287                        }
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSieve.cs

    r1652 r1653  
    105105            quadraticSieveQuickWatchPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    106106            {
    107                 quadraticSieveQuickWatchPresentation.peer2peerExpander.Visibility = settings.UsePeer2Peer ? Visibility.Visible : Visibility.Collapsed;
     107                quadraticSieveQuickWatchPresentation.peer2peer.Visibility = settings.UsePeer2Peer ? Visibility.Visible : Visibility.Collapsed;
     108                quadraticSieveQuickWatchPresentation.Redraw();
    108109                quadraticSieveQuickWatchPresentation.timeLeft.Text = "?";
    109110                quadraticSieveQuickWatchPresentation.endTime.Text = "?";
     
    134135                    quadraticSieveQuickWatchPresentation.Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
    135136                    {
    136                         quadraticSieveQuickWatchPresentation.peer2peerExpander.Visibility = settings.UsePeer2Peer ? Visibility.Visible : Visibility.Collapsed;
     137                        quadraticSieveQuickWatchPresentation.peer2peer.Visibility = settings.UsePeer2Peer ? Visibility.Visible : Visibility.Collapsed;
     138                        quadraticSieveQuickWatchPresentation.Redraw();
    137139                    }, null);
    138140                }
     
    710712            }
    711713
    712             conf_list[threadNR] = null;
     714            if (conf_list != null)
     715                conf_list[threadNR] = null;
    713716            MethodInfo freeSieveConf = msieve.GetMethod("freeSieveConf");
    714717            freeSieveConf.Invoke(null, new object[] { clone });           
     
    723726            if (conf_list != null)
    724727            {
    725                 ArrayList cl = conf_list;
    726                 conf_list = null;
    727 
    728728                running = false;
    729729                if (usePeer2Peer)
     
    732732                MethodInfo stop = msieve.GetMethod("stop");
    733733                MethodInfo getObjFromConf = msieve.GetMethod("getObjFromConf");
    734                 foreach (IntPtr conf in cl)
     734                foreach (IntPtr conf in conf_list)
    735735                    if (conf != null)
    736736                        stop.Invoke(null, new object[] { getObjFromConf.Invoke(null, new object[] { conf }) });
     737
     738                conf_list = null;
    737739
    738740                GuiLogMessage("Waiting for threads to stop!", NotificationLevel.Debug);
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSievePresentation.xaml

    r1628 r1653  
    66    Background="White"
    77    Name="Presentation">
    8     <Canvas Name="Canvas">
    9     <Grid Name="Grid" ShowGridLines="False">
    10         <Grid.RowDefinitions>
    11             <RowDefinition Height="*"/>
    12             <RowDefinition Height="*"/>
    13             <RowDefinition Height="150"/>
    14             <RowDefinition Height="*"/>
    15             <RowDefinition Height="*"/>
    16             <RowDefinition Height="*"/>
    17         </Grid.RowDefinitions>
    18         <Grid.ColumnDefinitions>
    19             <ColumnDefinition Width="*" />
    20             <ColumnDefinition Width="*" />
    21         </Grid.ColumnDefinitions>
     8        <Canvas Name="Canvas">
     9            <Grid Name="Grid" ShowGridLines="False">
     10            <Grid.RowDefinitions>
     11                <RowDefinition Height="*"/>
     12                <RowDefinition Height="*"/>
     13                <RowDefinition Height="150"/>
     14                <RowDefinition Height="*"/>
     15                <RowDefinition Height="*"/>
     16                <RowDefinition Height="*"/>
     17            </Grid.RowDefinitions>
     18            <Grid.ColumnDefinitions>
     19                <ColumnDefinition Width="*" />
     20                <ColumnDefinition Width="*" />
     21            </Grid.ColumnDefinitions>
    2222       
    23         <Label FontSize="12" Name="Label1" Margin="1">Probable time left :</Label>
    24         <Label Grid.Column="1" FontSize="12" Name="Label2" Margin="1">Estimated end time :</Label>
     23            <Label FontSize="12" Name="Label1" Margin="1">Probable time left :</Label>
     24            <Label Grid.Column="1" FontSize="12" Name="Label2" Margin="1">Estimated end time :</Label>
    2525       
    26         <TextBox Name="timeLeft" Grid.Row="1" TextAlignment="Center" IsReadOnly="True" TextWrapping="WrapWithOverflow" Focusable="True" BorderThickness="1" Margin="1" BorderBrush="AliceBlue" />
    27         <TextBox Name="endTime" Grid.Row="1" Grid.Column="1" TextAlignment="Center" IsReadOnly="True" TextWrapping="WrapWithOverflow" BorderThickness="1" Margin="1" BorderBrush="AliceBlue" />
    28         <ListBox Grid.Row="2" Grid.ColumnSpan="2" Name="factorList" Canvas.Left="1" Canvas.Top="50" Height="150" Width="233" />
    29         <Label Grid.Row="3" Grid.ColumnSpan="2" Content="" HorizontalAlignment="Left" Name="factorInfo" VerticalAlignment="Top" /> 
    30        
    31         <Expander Grid.Row="4" Grid.ColumnSpan="2" Header="Peer2Peer informations" Name="peer2peerExpander" VerticalAlignment="Top" Expanded="peer2peerExpander_Expanded">
    32             <Grid>
     26            <TextBox Name="timeLeft" Grid.Row="1" TextAlignment="Center" IsReadOnly="True" TextWrapping="WrapWithOverflow" Focusable="True" BorderThickness="1" Margin="1" BorderBrush="AliceBlue" />
     27            <TextBox Name="endTime" Grid.Row="1" Grid.Column="1" TextAlignment="Center" IsReadOnly="True" TextWrapping="WrapWithOverflow" BorderThickness="1" Margin="1" BorderBrush="AliceBlue" />
     28            <ListBox Grid.Row="2" Grid.ColumnSpan="2" Name="factorList" Canvas.Left="1" Canvas.Top="50" Height="150" Width="233" />
     29            <Label Grid.Row="3" Grid.ColumnSpan="2" Content="" HorizontalAlignment="Left" Name="factorInfo" VerticalAlignment="Top" />
     30
     31            <UserControl Name="peer2peer" Grid.Row="4" Grid.ColumnSpan="2">
     32                <Grid>
    3333                <Grid.RowDefinitions>
    3434                    <RowDefinition />
     
    4242                <Label Grid.Row="1" Content="" HorizontalAlignment="Stretch" Name="relationsInfo" VerticalAlignment="Bottom" />
    4343                <Label Grid.Row="2" Content="" HorizontalAlignment="Stretch" Name="amountOfPeers" VerticalAlignment="Bottom" />
    44             </Grid>               
    45         </Expander>
    46        
    47         <TextBox Name="logging" Grid.Row="5" Grid.ColumnSpan="2" TextAlignment="Left" IsReadOnly="True" TextWrapping="WrapWithOverflow" BorderThickness="1" Margin="1" BorderBrush="AliceBlue" />       
    48         </Grid>       
    49     </Canvas>
     44                </Grid>
     45            </UserControl>
     46
     47            <TextBox Name="logging" Grid.Row="5" Grid.ColumnSpan="2" TextAlignment="Left" IsReadOnly="True" TextWrapping="WrapWithOverflow" BorderThickness="1" Margin="1" BorderBrush="AliceBlue" />       
     48           
     49            </Grid>       
     50        </Canvas>
    5051</UserControl>
  • trunk/CrypPlugins/QuadraticSieve/QuadraticSievePresentation.xaml.cs

    r1648 r1653  
    3131            SizeChanged += sizeChanged;
    3232
    33             Grid grid = ((Grid)peer2peerExpander.Content);
     33            Grid grid = ((Grid)peer2peer.Content);
    3434            Grid.SetRow(progressYields, 0);
    3535            grid.Children.Add(progressYields);
    36             progressYields.MaxWidth = 200;           
     36            //progressYields.MaxWidth = 200;           
    3737        }       
    3838
     
    4343        }
    4444
    45         private void peer2peerExpander_Expanded(object sender, RoutedEventArgs e)
     45        public void Redraw()
    4646        {
    47             //TODO: Refresh here
     47            //TODO: Redraw here
    4848        }
    4949    }
Note: See TracChangeset for help on using the changeset viewer.