Author: j16sdiz
Date: 2009-04-23 08:54:23 +0000 (Thu, 23 Apr 2009)
New Revision: 27237

Modified:
   trunk/freenet/src/freenet/io/AddressMatcher.java
   trunk/freenet/src/freenet/io/AllowedHosts.java
   trunk/freenet/src/freenet/io/EverythingMatcher.java
   trunk/freenet/src/freenet/io/Inet4AddressMatcher.java
   trunk/freenet/src/freenet/io/Inet6AddressMatcher.java
Log:
Less dependant on AddressType

Modified: trunk/freenet/src/freenet/io/AddressMatcher.java
===================================================================
--- trunk/freenet/src/freenet/io/AddressMatcher.java    2009-04-23 08:53:51 UTC 
(rev 27236)
+++ trunk/freenet/src/freenet/io/AddressMatcher.java    2009-04-23 08:54:23 UTC 
(rev 27237)
@@ -17,15 +17,12 @@
 package freenet.io;
 
 import java.net.InetAddress;
-import freenet.io.AddressIdentifier.AddressType;
 
 /**
  * @author David Roden <[email protected]>
  * @version $Id$
  */
 public interface AddressMatcher {
-       public AddressType getAddressType();
-
        public boolean matches(InetAddress address);
 
        /** Get the human-readable version of the Matcher */

Modified: trunk/freenet/src/freenet/io/AllowedHosts.java
===================================================================
--- trunk/freenet/src/freenet/io/AllowedHosts.java      2009-04-23 08:53:51 UTC 
(rev 27236)
+++ trunk/freenet/src/freenet/io/AllowedHosts.java      2009-04-23 08:54:23 UTC 
(rev 27237)
@@ -55,8 +55,7 @@
                        } else if (addressType == AddressType.IPv6) {
                                newAddressMatchers.add(new 
Inet6AddressMatcher(allowedHost));
                        } else if (allowedHost.equals("*")) {
-                               newAddressMatchers.add(new 
EverythingMatcher(AddressIdentifier.AddressType.IPv4));
-                               newAddressMatchers.add(new 
EverythingMatcher(AddressIdentifier.AddressType.IPv6));
+                               newAddressMatchers.add(new EverythingMatcher());
                        } else {
                                Logger.error(NetworkInterface.class, "Ignoring 
invalid allowedHost: " + allowedHost);
                        }
@@ -74,9 +73,7 @@
 
        public synchronized boolean allowed(AddressType clientAddressType, 
InetAddress clientAddress) {
                for(AddressMatcher matcher: addressMatchers) {
-                       if (clientAddressType == matcher.getAddressType()) {
-                               if(matcher.matches(clientAddress)) return true;
-                       }
+                       if(matcher.matches(clientAddress)) return true;
                }
                return false;
        }

Modified: trunk/freenet/src/freenet/io/EverythingMatcher.java
===================================================================
--- trunk/freenet/src/freenet/io/EverythingMatcher.java 2009-04-23 08:53:51 UTC 
(rev 27236)
+++ trunk/freenet/src/freenet/io/EverythingMatcher.java 2009-04-23 08:54:23 UTC 
(rev 27237)
@@ -2,20 +2,10 @@
 
 import java.net.InetAddress;
 
-import freenet.io.AddressIdentifier.AddressType;
-
 public class EverythingMatcher implements AddressMatcher {
-       
-       final AddressType type;
-
-       public EverythingMatcher(AddressType t) {
-               type = t;
+       public EverythingMatcher() {
        }
        
-       public AddressType getAddressType() {
-               return type;
-       }
-
        public boolean matches(InetAddress address) {
                return true;
        }

Modified: trunk/freenet/src/freenet/io/Inet4AddressMatcher.java
===================================================================
--- trunk/freenet/src/freenet/io/Inet4AddressMatcher.java       2009-04-23 
08:53:51 UTC (rev 27236)
+++ trunk/freenet/src/freenet/io/Inet4AddressMatcher.java       2009-04-23 
08:54:23 UTC (rev 27237)
@@ -20,8 +20,6 @@
 import java.net.InetAddress;
 import java.util.StringTokenizer;
 
-import freenet.io.AddressIdentifier.AddressType;
-
 /**
  * Matcher for IPv4 network addresses. It works like the regex matcher in
  * {...@link java.util.regex.Matcher}, i.e. you create a new 
Inet4AddressMatcher
@@ -38,10 +36,6 @@
  * @version $Id$
  */
 public class Inet4AddressMatcher implements AddressMatcher {
-       public AddressType getAddressType() {
-               return AddressType.IPv4;
-       }
-
        /** The address of this matcher */
        private int address;
 
@@ -103,6 +97,7 @@
         *         specification of this matcher, <code>false</code> otherwise
         */
        public boolean matches(InetAddress inetAddress) {
+               if (!(inetAddress instanceof Inet4Address)) return false;
                int matchAddress = convertToBytes(inetAddress.getHostAddress());
                return (matchAddress & networkMask) == (address & networkMask);
        }
@@ -119,9 +114,9 @@
         *         specification in <code>cidrHostname</code>, 
<code>false</code>
         *         otherwise
         * @see #Inet4AddressMatcher(String)
-        * @see #matches(Inet4Address)
+        * @see #matches(InetAddress)
         */
-       public static boolean matches(String cidrHostname, Inet4Address 
address) {
+       public static boolean matches(String cidrHostname, InetAddress address) 
{
                return new Inet4AddressMatcher(cidrHostname).matches(address);
        }
 

Modified: trunk/freenet/src/freenet/io/Inet6AddressMatcher.java
===================================================================
--- trunk/freenet/src/freenet/io/Inet6AddressMatcher.java       2009-04-23 
08:53:51 UTC (rev 27236)
+++ trunk/freenet/src/freenet/io/Inet6AddressMatcher.java       2009-04-23 
08:54:23 UTC (rev 27237)
@@ -81,6 +81,7 @@
        }
 
        public boolean matches(InetAddress address) {
+               if (!(address instanceof Inet6Address)) return false;
                byte[] addressBytes = address.getAddress();
                for (int index = 0; index < 16; index++) {
                        if ((addressBytes[index] & netmask[index]) != 
(this.address[index] & netmask[index])) {
@@ -90,7 +91,7 @@
                return true;
        }
 
-       public static boolean matches(String pattern, Inet6Address address) {
+       public static boolean matches(String pattern, InetAddress address) {
                return new Inet6AddressMatcher(pattern).matches(address);
        }
 

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to