Re: [codepatch] Re: [discuss] block all hosts

Chuck McNulty <[email protected]> Thu, 07 Apr 2005 17:22:44 -0400
Newsgroups gmane.network.gnutella.limewire.general
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------040501000306090106040802
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Sweet!  That was all it took.  Here is the promised patch file with both 
"Block All Hosts" and "Block File" merged, however I must admit that I'm 
really disappointed with the results of my patch.  I've blocked many 
hundreds of hosts without seeing any drop-off in day to day spam 
results.  The results do seem to drop off for a few hours at least, or 
for a day at most, but within a few days, the spam results are back with 
a vengeance.  I can report however that I didn't notice any drop-off in 
non-spam results at least, so I don't think there are too many false 
positives. 

I must admit though, I was thinking about unintended consequences, and 
it occurs to me that one unintended consequence is that the host 
blocking essentially puts control of who you are blocking in the hands 
of whoever is spamming.  I am assuming for now that the objective of the 
spammers is to distribute their content (or viruses or whatever), and 
that therefore they would only distribute legitimate alternate hosts 
with their results.  With a block alternates functionality, they could 
easily trick users into blocking hundreds of legitimate hosts (for 
instance the www.magnetmix.com IPs) with a single click. Given that it 
doesn't really work anyway, I'd be tempted to eliminate the 
functionality altogether, both as it currently exists and as I've 
programmed it to work, and replace it with the block file 
functionality.  Am I being overly paranoid?  What do you guys (and gals) 
think of this scenario?

I can't believe I'm recommending non-acceptance of my patch :(

My next target is going to be increasing bitzi support using 
(http://bitzi.com/developer/xml)  It seems to me like this might be a 
better long-term solution (except of course that one can't make LimeWire 
depend to closely on an outside outfit.)  To anyone's knowledge is 
anyone working on integrating Bitzi's XML functionality?

-Chuck

Justin Schmidt wrote:

> Hi Chuck,
>
> I believe that the directory in which to apply the patch depends on 
> the directory in which the patch was created, unfortunately.
>
> However, the "Index:" part tells you the relative path of the file 
> it's looking for, or "ResultPanel.java" with no directory structure.  
> This means you need to apply the patch in the directory that contains 
> this file.  For you, I imagine it is:
>
>    C:\LimeWire\gui\com\limegroup\gnutella\gui\search\
>
> Try that, and see if that works?
>
> Justin
>
>
> Chuck McNulty wrote:
>
>> Okay, I tried all of these steps in as many ways as I could, and 
>> still no joy.  I got the diff files without a problem, but when I try 
>> to patch (after downloading patch for win32) it starts okay, but as 
>> soon as it starts to appy the patch it tells me that it can't find 
>> the file to be patched.  It looks to me like the problem is that the 
>> diff files refer to the files in the CVS structure.  Here is the output:
>>
>> C:\LimeWire>patch -p0 -i file-filter.txt
>> can't find file to patch at input line 10
>> Perhaps you used the wrong -p or --strip option?
>> The text leading up to this was:
>> --------------------------
>> |cvs server: Diffing .
>> |Index: ResultPanel.java
>> |===================================================================
>> |RCS file: /cvs/gui/com/limegroup/gnutella/gui/search/ResultPanel.java,v
>> |retrieving revision 1.140
>> |retrieving revision 1.140.26.2
>> |diff -u -w -r1.140 -r1.140.26.2
>> |--- ResultPanel.java   15 Nov 2004 04:48:24 -0000      1.140
>> |+++ ResultPanel.java   11 Jan 2005 18:13:28 -0000      1.140.26.2
>> --------------------------
>> File to patch: 
>> C:\LimeWire\gui\com\limegroup\gnutella\gui\search\ResultPanel.java
>> patching file 
>> C:\LimeWire\gui\com\limegroup\gnutella\gui\search\ResultPanel.java
>> Hunk #1 FAILED at 7.
>>
>>
>> -- 
>>
>> Any suggestions?
>> -Chuck
>>
>> Sam Berlin wrote:
>>
>>> You can get a diff of the changes on the file-filter branch by using 
>>> the cvs command:
>>>  cvs diff -uNw -r file-filter-branch-point -r file-filter-branch > 
>>> filter-changes.txt
>>>
>>> (It may also be -r file-filter-branch -r file-filter-branch-point -- 
>>> I can never remember the order.)
>>>
>>> Once you get those changes, you can incorporate them into your local 
>>> edits using:
>>>  patch -p0 -i filter-changes.txt
>>>
>>> Then, you can do a diff from your local copy to CVS head using
>>>   cvs diff -uNw > all-changes.txt
>>>
>>> The resulting all-changes.txt file should contain the diffs of both 
>>> your local edits & the file-filter branch.
>>>
>>> Hopefully that all made sense. :)
>>>
>>> Thanks,
>>>  Sam
>>>
>>> On Apr 4, 2005, at 4:47 PM, Chuck McNulty wrote:
>>>
>>>> Okay, nix the question on how to resolve merges, I've done that 
>>>> part.  At least I've resolved the conflicts between my versions and 
>>>> the file-filter-branch versions.  I'm just not sure what to do 
>>>> next.  When I did a diff it just did a diff between my changes to 
>>>> the file-filter-branch.  I need to figure out how to get the diffs 
>>>> from the file-filter-branch (including my changes) and the main 
>>>> trunk.  Any advise is welcome.
>>>>
>>>> Also, should I take this discussion off of discuss@lists?  Should 
>>>> it be on another list?  Should I just be sending these questions to 
>>>> you, Sam?
>>>>
>>>> -Chuck
>>>>
>>>> Chuck McNulty wrote:
>>>>
>>>>> Hi Sam and all,
>>>>>
>>>>> Okay, this is kinda fun learning so I'm going to go for it.  I 
>>>>> have a few questions and they're not really LimeWire specific I 
>>>>> think, but you've been so helpful and patient, what the heck...
>>>>>
>>>>> Like I mentioned earlier I'm still learning CVS, and I'm using 
>>>>> WinCVS, which is probably an unhelpful crutch in terms of learning 
>>>>> it, but whatever.  I think I've pretty much got checking out a 
>>>>> branch, and I see that when I did that, there were some conflicts 
>>>>> where I'd already made changes (to the block all hosts 
>>>>> functionality).  I assume that the next step after I resolve these 
>>>>> conflicts is to do a merge of the file-filter-branch with the main 
>>>>> trunk on my own local copies resolve those conflict, and then do a 
>>>>> diff to submit to you.  Does that make sense?
>>>>>
>>>>> If so, my question (and it's a total newbie question) is how I go 
>>>>> about "resolving the conflicts"  Here is the first conflict, for 
>>>>> instance, in ResultPanel.java:
>>>>>
>>>>> import java.awt.event.MouseListener;
>>>>> import java.io.IOException;
>>>>> import java.util.Date;
>>>>> <<<<<<< ResultPanel.java
>>>>> import java.util.Iterator;
>>>>> =======
>>>>> import java.util.ArrayList;
>>>>> import java.util.Arrays;
>>>>> >>>>>>> 1.140.26.2
>>>>> import java.util.LinkedList;
>>>>> import java.util.List;
>>>>> import java.util.Set;
>>>>>
>>>>> Is "resolving the conflicts" just taking out the <<<, ===, and 
>>>>> >>>> lines with a text editor and making sure it still works?  Or 
>>>>> is there some interactive CVS tool that I should be using to 
>>>>> resolve the conflicts?  I think that's it...
>>>>>
>>>>>
>>>>> After that, the next thing I'm really excited about adding to 
>>>>> LimeWire, if it would be accepted (and maybe into my own version 
>>>>> in either case) is a new window that displays the bitzi info 
>>>>> without having to open up a browser window (with all of it's 
>>>>> accompanying advertising).  I'd do it by using bitzi's XML 
>>>>> format:  http://bitzi.com/developer/xml  I'm assuming here that 
>>>>> LimeWire doesn't have a financial partnership or arrangement with 
>>>>> bitzi for a share of their ad dollars.  I can certainly understand 
>>>>> not wanting to add this functionality if that's the case, and I 
>>>>> certainly don't object to LimeWire trying to make a buck, but if 
>>>>> not it could really be a nice little feature.
>>>>>
>>>>> -Chuck
>>>>>
>>>>> Sam Berlin wrote:
>>>>>
>>>>>> Hi Charles,
>>>>>>
>>>>>>> Is there anything I could do to move along merging in the work 
>>>>>>> that has already been done to block files?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> If you'd like, you can incorporate the code that was on the 
>>>>>> branch for hashing files into your patch, and then we can merge 
>>>>>> the whole blocking shebang at once.
>>>>>>
>>>>>> > Here is the code... basically (current < total) never seems to 
>>>>>> evaluate to true.
>>>>>>
>>>>>> The 'filtered' display will only be shown if you use the 'filter 
>>>>>> results' tab on the left of the search results.  The GUI doesn't 
>>>>>> keep track of results that the core has thrown away (because they 
>>>>>> were blocked).
>>>>>>
>>>>>>> In a related issue, does LimeWire really want to report the 
>>>>>>> total number of all hosts (including alternates) in the tab 
>>>>>>> title?  It seems to me that it would make more sense to only 
>>>>>>> show the number of unique results, as that is a much more 
>>>>>>> meaningful number for the end user.  I could fix that pretty 
>>>>>>> easily I think.  Would a patch for that be accepted?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> We used to display the unique results, but after 'filter results' 
>>>>>> were added, we changed to the number of sources.  Users like 
>>>>>> seeing high numbers. :)
>>>>>>
>>>>>> Thanks,
>>>>>>  Sam
>>>>>>
>>>>>> _______________________________________________
>>>>>> discuss mailing list
>>>>>> [email protected]
>>>>>> http://www.limewire.org/mailman/listinfo/discuss
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> discuss mailing list
>>>>> [email protected]
>>>>> http://www.limewire.org/mailman/listinfo/discuss
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>> _______________________________________________
>>> discuss mailing list
>>> [email protected]
>>> http://www.limewire.org/mailman/listinfo/discuss
>>
>>
>>
>>
>> _______________________________________________
>> discuss mailing list
>> [email protected]
>> http://www.limewire.org/mailman/listinfo/discuss
>
>
> _______________________________________________
> discuss mailing list
> [email protected]
> http://www.limewire.org/mailman/listinfo/discuss



--------------040501000306090106040802
Content-Type: text/plain;
 name="all-changes.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="all-changes.txt"

? core/com/limegroup/gnutella/filters/ResponseFilter.java
? core/com/limegroup/gnutella/filters/URNResponseFilter.java
? gui/com/limegroup/gnutella/gui/options/panes/AllowFilesPaneItem.java
? lib/messagebundles/MessagesBundle.diff
? tests/com/limegroup/gnutella/filters/ResponseFilterTest.java
Index: core/com/limegroup/gnutella/RouterService.java
===================================================================
RCS file: /cvs/core/com/limegroup/gnutella/RouterService.java,v
retrieving revision 1.286
diff -u -w -r1.286 RouterService.java
--- core/com/limegroup/gnutella/RouterService.java	8 Mar 2005 17:53:56 -0000	1.286
+++ core/com/limegroup/gnutella/RouterService.java	7 Apr 2005 20:03:15 -0000
@@ -28,6 +28,7 @@
 import com.limegroup.gnutella.downloader.IncompleteFileManager;
 import com.limegroup.gnutella.filters.IPFilter;
 import com.limegroup.gnutella.filters.MutableGUIDFilter;
+import com.limegroup.gnutella.filters.ResponseFilter;
 import com.limegroup.gnutella.filters.SpamFilter;
 import com.limegroup.gnutella.handshaking.HeaderNames;
 import com.limegroup.gnutella.licenses.LicenseFactory;
@@ -918,6 +919,14 @@
         }
         
         UDPReplyHandler.setPersonalFilter(SpamFilter.newPersonalFilter());
+    }
+
+    /**
+     * Notifies the backend that response filter settings have changed, and that
+     * extra work must be done.
+     */
+    public static void adjustResponseFilters() {
+        ResponseFilter.instance().refresh();
     }
 
     /**
Index: core/com/limegroup/gnutella/messages/QueryReply.java
===================================================================
RCS file: /cvs/core/com/limegroup/gnutella/messages/QueryReply.java,v
retrieving revision 1.51
diff -u -w -r1.51 QueryReply.java
--- core/com/limegroup/gnutella/messages/QueryReply.java	6 Dec 2004 22:59:37 -0000	1.51
+++ core/com/limegroup/gnutella/messages/QueryReply.java	7 Apr 2005 20:03:16 -0000
@@ -13,6 +13,7 @@
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
@@ -25,6 +26,7 @@
 import com.limegroup.gnutella.Response;
 import com.limegroup.gnutella.RouterService;
 import com.limegroup.gnutella.UDPService;
+import com.limegroup.gnutella.filters.ResponseFilter;
 import com.limegroup.gnutella.search.HostData;
 import com.limegroup.gnutella.settings.SearchSettings;
 import com.limegroup.gnutella.statistics.DroppedSentMessageStatHandler;
@@ -552,6 +554,13 @@
         return (short)ByteOrder.ubyte2int(_payload[0]);
     }
 
+    /** Return the number of filtered results N in this query. */
+    public short getFilteredResultCount() {
+        if(_responses==null) 
+            return 0;
+        return (short)_responses.length;
+    }
+
     public int getPort() {
         return ByteOrder.ubytes2int(ByteOrder.leb2short(_payload,1));
     }
@@ -802,18 +811,22 @@
         //verified for these to be acceptable.  Also note that exceptions are
         //silently caught.
         int left=getResultCount();          //number of records left to get
-        Response[] responses=new Response[left];
+        Response[] responses;
         try {
             InputStream bais = 
                 new ByteArrayInputStream(_payload,i,_payload.length-i);
-            //For each record...
+            //For each record, parse and filter
+            List allowedResponses = new ArrayList(left);
+            ResponseFilter responseFilter = ResponseFilter.instance();
             for ( ; left > 0; left--) {
                 Response r = Response.createFromStream(bais);
-                responses[responses.length-left] = r;
                 i+=r.getLength();
+                if(responseFilter.allow(r)) 
+                    allowedResponses.add(r);
             }
             //All set.  Accept parsed results.
-            this._responses=responses;
+            this._responses= new Response[allowedResponses.size()];
+            allowedResponses.toArray(this._responses);
         } catch (ArrayIndexOutOfBoundsException e) {
             return;
         } catch (IOException e) {
Index: core/com/limegroup/gnutella/settings/FilterSettings.java
===================================================================
RCS file: /cvs/core/com/limegroup/gnutella/settings/FilterSettings.java,v
retrieving revision 1.4
diff -u -w -r1.4 FilterSettings.java
--- core/com/limegroup/gnutella/settings/FilterSettings.java	15 Oct 2004 23:19:03 -0000	1.4
+++ core/com/limegroup/gnutella/settings/FilterSettings.java	7 Apr 2005 20:03:16 -0000
@@ -54,6 +54,12 @@
 	 */    
     public static final BooleanSetting FILTER_HIGHBIT_QUERIES =
         FACTORY.createBooleanSetting("FILTER_HIGHBIT_QUERIES", true);
+
+    /**
+	 * An array of URNs the user has blocked.
+	 */    
+    public static final StringArraySetting BLOCKED_URNS =
+        FACTORY.createStringArraySetting("BLOCKED_URNS", new String[0]);
     
     /**
 	 * An array of ip addresses that the user has banned.
Index: gui/com/limegroup/gnutella/gui/library/LibraryTableMediator.java
===================================================================
RCS file: /cvs/gui/com/limegroup/gnutella/gui/library/LibraryTableMediator.java,v
retrieving revision 1.46
diff -u -w -r1.46 LibraryTableMediator.java
--- gui/com/limegroup/gnutella/gui/library/LibraryTableMediator.java	22 Feb 2005 18:58:27 -0000	1.46
+++ gui/com/limegroup/gnutella/gui/library/LibraryTableMediator.java	7 Apr 2005 20:11:19 -0000
@@ -34,6 +34,7 @@
 import com.limegroup.gnutella.gui.xml.MetaEditorFrame;
 import com.limegroup.gnutella.gui.xml.editor.MetaEditor;
 import com.limegroup.gnutella.settings.ConnectionSettings;
+import com.limegroup.gnutella.settings.FilterSettings;
 import com.limegroup.gnutella.settings.QuestionsHandler;
 import com.limegroup.gnutella.util.Launcher;
 import com.limegroup.gnutella.util.NetworkUtils;
@@ -68,6 +69,7 @@
     public static ActionListener MAGNET_LOOKUP_LISTENER;
     public static ActionListener HTTP_LOOKUP_LISTENER;
     public static ActionListener RESUME_LISTENER;
+    public static ActionListener BLOCK_FILE_LISTENER;
     public static ActionListener LICENSE_LISTENER;
     public static ActionListener RENAME_LISTENER;
 
@@ -99,6 +101,7 @@
         BITZI_LOOKUP_LISTENER = new BitziLookupListener();
         MAGNET_LOOKUP_LISTENER = new MagnetLookupListener();
         RESUME_LISTENER = new ResumeListener();
+        BLOCK_FILE_LISTENER = new BlockFileListener();
         LICENSE_LISTENER = new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                 showLicenseWindow();
@@ -614,6 +617,37 @@
     }
 
 	/**
+	 * Blocks the selected file from appearing in future results
+	 * 
+	 */
+    void blockFile() {
+        // get the selected file. If there are more than 1 we just use the
+        // last one.
+        int[] rows = TABLE.getSelectedRows();
+        int k = rows.length;
+        if(k == 0)
+            return;
+        int index = rows[k-1];//this is the index of the last row selected
+        FileDesc fd = ((LibraryTableModel)DATA_MODEL).getFileDesc(index);
+        if (fd==null) {
+            // noop
+            return;
+        }
+        URN urn = fd.getSHA1Urn();
+		if(urn==null)
+		    return;
+        int answer = GUIMediator.showYesNoMessage("SEARCH_BLOCK_FILE");
+        if (answer == GUIMediator.YES_OPTION) {
+            String[] oldBlockedUrns = FilterSettings.BLOCKED_URNS.getValue();
+            String[] newBlockedUrns = new String[oldBlockedUrns.length+1];
+            System.arraycopy(oldBlockedUrns,0,newBlockedUrns,0,oldBlockedUrns.length);
+            newBlockedUrns[newBlockedUrns.length-1] = urn.toString();
+            FilterSettings.BLOCKED_URNS.setValue(newBlockedUrns);
+            RouterService.adjustResponseFilters();
+        }
+    }
+
+	/**
 	 * Handles the selection of the specified row in the library window,
 	 * enabling or disabling buttons and chat menu items depending on
 	 * the values in the row.
@@ -682,13 +716,11 @@
     }
 
     private final class LaunchListener implements ActionListener {
-
     	public void actionPerformed(ActionEvent ae) {
     		launch();
     	}
     }
 
-
     private final class AddPLFileListener implements ActionListener{
         public void actionPerformed(ActionEvent ae){
 			//get the selected file. If there are more than 1 we add all
@@ -699,5 +731,11 @@
 				LIBRARY_MEDIATOR.addFileToPlayList(file);
 			}
         }
+    }
+
+    private final class BlockFileListener implements ActionListener {
+    	public void actionPerformed(ActionEvent ae) {
+    		blockFile();
+    	}
     }
 }
Index: gui/com/limegroup/gnutella/gui/library/LibraryTablePopupMenu.java
===================================================================
RCS file: /cvs/gui/com/limegroup/gnutella/gui/library/LibraryTablePopupMenu.java,v
retrieving revision 1.13
diff -u -w -r1.13 LibraryTablePopupMenu.java
--- gui/com/limegroup/gnutella/gui/library/LibraryTablePopupMenu.java	7 Mar 2005 18:42:06 -0000	1.13
+++ gui/com/limegroup/gnutella/gui/library/LibraryTablePopupMenu.java	7 Apr 2005 20:13:17 -0000
@@ -81,6 +81,13 @@
     	JMenuItem MAGNET_ITEM = new JMenuItem(
     	    GUIMediator.getStringResource("SEARCH_PUBLIC_MAGNET_LOOKUP_STRING"));
     
+    	/**
+    	 * Constant for the block file menu item.
+    	 */
+        final JMenuItem BLOCK_FILE_ITEM = new JMenuItem(
+            GUIMediator.getStringResource("SEARCH_PUBLIC_COMPLETE_BLOCK_FILE_STRING")
+        );
+
    		LAUNCH_ITEM.addActionListener( LibraryTableMediator.LAUNCH_LISTENER );
 		PLAYLIST_ITEM.addActionListener( LibraryTableMediator.ADD_PLAY_LIST_LISTENER );
 		DELETE_ITEM.addActionListener( ltm.REMOVE_LISTENER );
@@ -90,6 +97,7 @@
         LICENSE_ITEM.addActionListener( ltm.LICENSE_LISTENER );
         BITZI_ITEM.addActionListener( LibraryTableMediator.BITZI_LOOKUP_LISTENER );
         MAGNET_ITEM.addActionListener( LibraryTableMediator.MAGNET_LOOKUP_LISTENER );
+        BLOCK_FILE_ITEM.addActionListener( LibraryTableMediator.BLOCK_FILE_LISTENER );
 		MENU.add(LAUNCH_ITEM);
 		// if it's visible, add the playlist item.
         // otherwise, add a separator so that the indexes are still right. :)
@@ -104,6 +112,7 @@
 		MENU.add(LICENSE_ITEM);
         MENU.add(BITZI_ITEM);
         MENU.add(MAGNET_ITEM);
+        MENU.add(BLOCK_FILE_ITEM);
     }
     
     JPopupMenu getComponent() { return MENU; }
Index: gui/com/limegroup/gnutella/gui/options/OptionsConstructor.java
===================================================================
RCS file: /cvs/gui/com/limegroup/gnutella/gui/options/OptionsConstructor.java,v
retrieving revision 1.74
diff -u -w -r1.74 OptionsConstructor.java
--- gui/com/limegroup/gnutella/gui/options/OptionsConstructor.java	7 Apr 2005 15:47:24 -0000	1.74
+++ gui/com/limegroup/gnutella/gui/options/OptionsConstructor.java	7 Apr 2005 20:03:16 -0000
@@ -160,6 +160,7 @@
 		final String FILTERS_KEY        = "OPTIONS_FILTERS_MAIN_TITLE";
 		final String RESULTS_KEY        = "OPTIONS_RESULTS_MAIN_TITLE";
 		final String MESSAGES_KEY       = "OPTIONS_MESSAGES_MAIN_TITLE";
+		final String FILES_KEY          = "OPTIONS_FILES_MAIN_TITLE";
 		final String ADVANCED_KEY       = "OPTIONS_ADVANCED_MAIN_TITLE";
 		final String PREFERENCING_KEY   = "OPTIONS_PREFERENCING_MAIN_TITLE";
 		final String FIREWALL_KEY       = "OPTIONS_FIREWALL_MAIN_TITLE";
@@ -309,6 +310,11 @@
 		filtersMessagesPane.add(new IgnoreMessagesPaneItem("IGNORE_MESSAGES"));
 		filtersMessagesPane.add(new AllowMessagesPaneItem("ALLOW_MESSAGES"));
 		addOption(FILTERS_KEY, filtersMessagesPane);
+
+		final OptionsPane filtersFilesPane = 
+            new OptionsPaneImpl(FILES_KEY);
+		filtersFilesPane.add(new AllowFilesPaneItem("ALLOW_FILES"));
+		addOption(FILTERS_KEY, filtersFilesPane);
 
 
 		// add the advanced options group
Index: gui/com/limegroup/gnutella/gui/search/ResultPanel.java
===================================================================
RCS file: /cvs/gui/com/limegroup/gnutella/gui/search/ResultPanel.java,v
retrieving revision 1.141
diff -u -w -r1.141 ResultPanel.java
--- gui/com/limegroup/gnutella/gui/search/ResultPanel.java	10 Jan 2005 19:37:35 -0000	1.141
+++ gui/com/limegroup/gnutella/gui/search/ResultPanel.java	7 Apr 2005 20:07:09 -0000
@@ -7,8 +7,12 @@
 import java.awt.event.MouseListener;
 import java.io.IOException;
 import java.util.Date;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 
 import javax.swing.Box;
 import javax.swing.JComponent;
@@ -22,6 +26,7 @@
 import com.limegroup.gnutella.BrowseHostHandler;
 import com.limegroup.gnutella.GUID;
 import com.limegroup.gnutella.MediaType;
+import com.limegroup.gnutella.RemoteFileDesc;
 import com.limegroup.gnutella.RouterService;
 import com.limegroup.gnutella.URN;
 import com.limegroup.gnutella.gui.BoxPanel;
@@ -38,11 +43,13 @@
 import com.limegroup.gnutella.search.QueryHandler;
 import com.limegroup.gnutella.settings.FilterSettings;
 import com.limegroup.gnutella.util.Launcher;
+import com.limegroup.gnutella.util.IpPort;
 import com.limegroup.gnutella.licenses.License;
 import com.limegroup.gnutella.licenses.VerificationListener;
 import com.limegroup.gnutella.gui.LicenseWindow;
 
 
+
 public class ResultPanel extends AbstractTableMediator
                          implements VerificationListener {
     
@@ -348,8 +355,41 @@
         line.doChat();
 	}
 
+
+    /**
+     * Blocks all hosts and alternates that sent the selected result.
+     */
+    void blockAllHosts() {
+        TableLine line = getSelectedLine();
+        if(line == null)
+            return;
+        
+        Set alts = line.getAlts();
+
+        RemoteFileDesc[] rfds;
+        rfds = line.getAllRemoteFileDescs();
+        
+        int answer = GUIMediator.showYesNoMessage("SEARCH_BLOCK_ALL_HOSTS");
+        if (answer == GUIMediator.YES_OPTION) {
+
+            for(Iterator i = alts.iterator(); i.hasNext(); ) {
+                IpPort next = (IpPort)i.next();
+                String host = next.getAddress();
+                blockOneHost(host);
+            }
+
+            for(int i = 0; i < rfds.length; i++) {
+                RemoteFileDesc next = rfds[i];
+                String host = next.getHost();
+                blockOneHost(host);
+            }
+        }
+
+    }
+
+
     /**
-     * Blocks the host that sent the selected result.
+     * Blocks the first host (and no alternates) that sent the selected result.
      */
     void blockHost() {
         TableLine line = getSelectedLine();
@@ -359,6 +399,15 @@
         String host = line.getHostname();
         int answer = GUIMediator.showYesNoMessage("SEARCH_BLOCK_HOST", " " + host + "?");
         if (answer == GUIMediator.YES_OPTION && host != null) {
+            blockOneHost(host);
+        }
+    }
+
+
+    /**
+     * Blocks a given host.
+     */    
+    void blockOneHost(String host) {
             String[] bannedIps = FilterSettings.BLACK_LISTED_IP_ADDRESSES.getValue();
             // Ignore if this host is already banned.
             for (int i = 0; i < bannedIps.length; i++)
@@ -371,7 +420,7 @@
             FilterSettings.BLACK_LISTED_IP_ADDRESSES.setValue(newBannedIps);
             RouterService.adjustSpamFilters();
         }
-    }
+
     
     /**
      * Shows a LicenseWindow for the selected line.
@@ -392,6 +441,29 @@
             ((ResultPanelModel)DATA_MODEL).slowRefresh();
     }
     
+    /**
+     * Blocks the selected result based on URN
+     */    
+    void blockFile() {
+        TableLine line = getSelectedLine();
+        if(line == null)
+            return;
+            
+        URN urn = line.getSHA1Urn();
+		if(urn==null)
+		    return;
+
+        int answer = GUIMediator.showYesNoMessage("SEARCH_BLOCK_FILE");
+        if (answer == GUIMediator.YES_OPTION) {
+            String[] oldBlockedUrns = FilterSettings.BLOCKED_URNS.getValue();
+            String[] newBlockedUrns = new String[oldBlockedUrns.length+1];
+            System.arraycopy(oldBlockedUrns,0,newBlockedUrns,0,oldBlockedUrns.length);
+            newBlockedUrns[newBlockedUrns.length-1] = urn.toString();
+            FilterSettings.BLOCKED_URNS.setValue(newBlockedUrns);
+            RouterService.adjustResponseFilters();
+        }
+    }
+
     /**
      * Does a bitzi lookup on the selected line.
      */
Index: gui/com/limegroup/gnutella/gui/search/SearchMediator.java
===================================================================
RCS file: /cvs/gui/com/limegroup/gnutella/gui/search/SearchMediator.java,v
retrieving revision 1.90
diff -u -w -r1.90 SearchMediator.java
--- gui/com/limegroup/gnutella/gui/search/SearchMediator.java	19 Jan 2005 20:01:25 -0000	1.90
+++ gui/com/limegroup/gnutella/gui/search/SearchMediator.java	7 Apr 2005 20:03:17 -0000
@@ -59,6 +59,10 @@
         GUIMediator.getStringResource("SEARCH_PUBLIC_BITZI_LOOKUP_STRING");
     static final String BLOCK_STRING =
         GUIMediator.getStringResource("SEARCH_PUBLIC_BLOCK_STRING");
+    static final String BLOCK_HOST_STRING =
+        GUIMediator.getStringResource("SEARCH_PUBLIC_BLOCK_HOST_STRING");
+    static final String BLOCK_FILE_STRING = 
+        GUIMediator.getStringResource("SEARCH_PUBLIC_BLOCK_FILE_STRING");
 
     /**
      * Variable for the component that handles all search input from the user.
Index: gui/com/limegroup/gnutella/gui/search/SearchResultMenu.java
===================================================================
RCS file: /cvs/gui/com/limegroup/gnutella/gui/search/SearchResultMenu.java,v
retrieving revision 1.8
diff -u -w -r1.8 SearchResultMenu.java
--- gui/com/limegroup/gnutella/gui/search/SearchResultMenu.java	10 Jan 2005 19:37:35 -0000	1.8
+++ gui/com/limegroup/gnutella/gui/search/SearchResultMenu.java	7 Apr 2005 20:03:17 -0000
@@ -3,6 +3,7 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 
+import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 
@@ -31,6 +32,14 @@
         m.add(item);
     }
     
+    private static void add(String s, ActionListener l,
+                            JMenu m, boolean enable) {
+        JMenuItem item = new JMenuItem(s);
+        item.addActionListener(l);
+        item.setEnabled(enable);
+        m.add(item);
+    }
+
     /**
      * Creates the JPopupMenu.
      */
@@ -47,8 +56,12 @@
             menu, line != null);
         add(SearchMediator.BROWSE_HOST_STRING, PANEL.BROWSE_HOST_LISTENER,
             menu, line != null && line.isBrowseHostEnabled());
-        add(SearchMediator.BLOCK_STRING, new BlockListener(),
-            menu, line != null);
+        JMenu blockMenu = new JMenu(SearchMediator.BLOCK_STRING);
+        add(SearchMediator.BLOCK_HOST_STRING, new BlockListener(),
+            blockMenu, line != null);
+        add(SearchMediator.BLOCK_FILE_STRING, new BlockFileListener(),
+            blockMenu, line != null && line.getSHA1Urn() != null);
+        menu.add(blockMenu);
 
         /////////////////////////////
         menu.addSeparator();
@@ -85,7 +98,13 @@
     
     private class BlockListener implements ActionListener {
         public void actionPerformed(ActionEvent e) {
-            PANEL.blockHost();
+            PANEL.blockAllHosts();
+        }
+    }
+    
+    private class BlockFileListener implements ActionListener {
+        public void actionPerformed(ActionEvent e) {
+            PANEL.blockFile();
         }
     }
     
Index: lib/messagebundles/MessagesBundle.properties
===================================================================
RCS file: /cvs/lib/messagebundles/MessagesBundle.properties,v
retrieving revision 1.186
diff -u -w -r1.186 MessagesBundle.properties
--- lib/messagebundles/MessagesBundle.properties	7 Apr 2005 19:25:03 -0000	1.186
+++ lib/messagebundles/MessagesBundle.properties	7 Apr 2005 20:16:45 -0000
@@ -355,7 +355,10 @@
 SEARCH_PUBLIC_MAGNET_LOOKUP_STRING=Magnet details for file
 SEARCH_PUBLIC_HTTP_PAGE_STRING=Web page for file(s)
 SEARCH_PUBLIC_REPEAT_SEARCH_STRING=Repeat Search
-SEARCH_PUBLIC_BLOCK_STRING=Block Host
+SEARCH_PUBLIC_BLOCK_STRING=Block
+SEARCH_PUBLIC_BLOCK_HOST_STRING=Host
+SEARCH_PUBLIC_BLOCK_FILE_STRING=File
+SEARCH_PUBLIC_COMPLETE_BLOCK_FILE_STRING=Block File
 SEARCH_RESULT_TABLE_LABEL=Results
 SEARCH_SEARCHING_LABEL=Searching...
 SEARCH_VIRUS_MSG_ONE=One of the selected files is an executable
@@ -385,6 +388,9 @@
 SEARCH_FILTER_RESULTS=Filter Results:
 SEARCH_BACK_TO_SEARCH=Back To Search
 SEARCH_BLOCK_HOST=Do you want to block search results from the host at
+SEARCH_BLOCK_ALL_HOSTS=Do you want to block all hosts for this search result?
+SEARCH_BLOCK_FILE=Do you want to block this file from all future search results?
+SEARCH_UNBLOCK_ALL_FILES=Are you sure you want to clear all file blocks for future search results?
 
 #Media Types
 MEDIA_ANY_TYPE=Any Type
@@ -1133,6 +1139,7 @@
 OPTIONS_FILTERS_MAIN_TITLE=Filters
 OPTIONS_RESULTS_MAIN_TITLE=Keywords
 OPTIONS_MESSAGES_MAIN_TITLE=Hosts
+OPTIONS_FILES_MAIN_TITLE=Files
 OPTIONS_ADVANCED_MAIN_TITLE=Advanced
 OPTIONS_COMPRESSION_MAIN_TITLE=Compression
 OPTIONS_PREFERENCING_MAIN_TITLE=Preferencing
@@ -1478,6 +1485,13 @@
 OPTIONS_IGNORE_MESSAGES_LABEL=You can disallow messages from specific hosts by adding their IP addresses (e.g. "192.168.0.1", "192.*.*.*", "192.168.12.16/255.255.255.240" or "192.168.12.16/28") to the banned list.
 OPTIONS_ALLOW_MESSAGES_TITLE=Allow Hosts
 OPTIONS_ALLOW_MESSAGES_LABEL=You can allow messages from specific hosts by adding their IP addresses (e.g. "192.168.0.1", "192.*.*.*", "192.168.12.16/255.255.255.240" or "192.168.12.16/28") to the allow list. This list is only needed to override the banned list.
+
+################################################################################
+# Key/Value pairs for file filtering options in the options window
+################################################################################
+OPTIONS_ALLOW_FILES_TITLE=Filter Files
+OPTIONS_ALLOW_FILES_LABEL=Clearing all blocked files will allow them to appear in future search results.
+OPTIONS_ALLOW_FILES_CLEAR_ALL=Clear all
 
 ################################################################################
 # Key/Value pairs for disabling compression support

--------------040501000306090106040802
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
discuss mailing list
[email protected]
http://www.limewire.org/mailman/listinfo/discuss

--------------040501000306090106040802--