Here is a Diff to enable Freenet to only accept connections from the local
network. It adds the config option "localSubNet". This can be set to a,b or
c. These correspond to accepting connections for a class a b and c network
respectively. If it is set to anything else or blank it will assume that you
want to be part of the global network.
The code to check the IPs for the incoming connections is in and by my
preliminary tests is working. I still need to make "localSubNet" a proper
configuration option (It is just kind of hacked on now) and add a description
etc. (If someone beats me to it, that's cool...) So, if you get a chance,
test this code.
Drew Bradford, see if this works on your test network.
diff -ruBb freenet1/src/freenet/interfaces/PublicNIOInterface.java freenet2/src/freenet/interfaces/PublicNIOInterface.java
--- freenet1/src/freenet/interfaces/PublicNIOInterface.java 2003-08-14 21:27:03.000000000 -0500
+++ freenet2/src/freenet/interfaces/PublicNIOInterface.java 2003-08-14 20:48:42.000000000 -0500
@@ -94,6 +94,11 @@
throw new RejectedConnectionException("thread limit reached");
}
+ if (node.rejectThisConnection(conn.getPeerAddress().toString()))
+ {
+ throw new RejectedConnectionException("Non-local address.");
+ }
+
Core.diagnostics.occurrenceCounting("inboundConnectionsAccepted", 1);
long timeDoneDiagnostics = System.currentTimeMillis();
Only in freenet1/src/freenet/interfaces: PublicNIOInterface.java.new
diff -ruBb freenet1/src/freenet/node/Main.java freenet2/src/freenet/node/Main.java
--- freenet1/src/freenet/node/Main.java 2003-08-14 21:27:15.000000000 -0500
+++ freenet2/src/freenet/node/Main.java 2003-08-14 18:32:38.000000000 -0500
@@ -892,6 +893,18 @@
startNode(addr, params); // run Core
+ String localSubNet = params.getString("localSubNet");
+ if(localSubNet.equals("a") || localSubNet.equals("A"))
+ node.local=1;
+ else if (localSubNet.equals("b") || localSubNet.equals("B"))
+ node.local=2;
+ else if (localSubNet.equals("c") || localSubNet.equals("C"))
+ node.local=3;
+ else
+ node.local=0;
+
+
// Handle watchme
if (params.getBoolean("watchme")) {
new Checkpoint(watchme).schedule(node);
Only in freenet1/src/freenet/node: Main.java.new
diff -ruBb freenet1/src/freenet/node/Node.java freenet2/src/freenet/node/Node.java
--- freenet1/src/freenet/node/Node.java 2003-08-14 21:27:15.000000000 -0500
+++ freenet2/src/freenet/node/Node.java 2003-08-14 21:19:54.000000000 -0500
@@ -45,6 +45,8 @@
public static boolean isWin9X;
public static boolean isWinCE;
public static boolean isOSX;
+ public static int local = 0; //0 means part of global freenet network.
+
public static String sysName = System.getProperty("os.name");
@@ -2325,6 +2327,37 @@
return false;
}
+ public boolean rejectThisConnection(String IP)
+ {
+ if (local == 0) return false;
+ if (local > 3)
+ {
+ Core.logger.log(this, "Node.local set to nonsensical vlaue.", Logger.ERROR);
+ return false;
+ }
+ String MyIP = myRef.firstPhysicalIpToString();
+ if (MyIP == null || MyIP.equals("void"))
+ {
+ Core.logger.log(this, "Cannot get my IP", Logger.ERROR);
+ return false;
+ }
+ int loc=0;
+ for (int i=0;i<local;i++)
+ {
+ loc=MyIP.indexOf(".");
+ MyIP.indexOf(".",loc);
+ }
+ if (IP.startsWith(MyIP.substring(0, loc)))
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+
long lastLoggedRejectingConns = 0;
/**
Only in freenet1/src/freenet/node: Node.java.new
diff -ruBb freenet1/src/freenet/node/NodeReference.java freenet2/src/freenet/node/NodeReference.java
--- freenet1/src/freenet/node/NodeReference.java 2003-08-14 21:27:15.000000000 -0500
+++ freenet2/src/freenet/node/NodeReference.java 2003-08-14 21:01:23.000000000 -0500
@@ -696,6 +696,13 @@
return physical[0] + "/" + physical[1];
}
+ public String firstPhysicalIpToString() {
+ if (physical.length < 2)
+ return "void";
+ else
+ return physical[1];
+ }
+
public String toString() {
//return getFieldSet().toString();
StringBuffer sb = new StringBuffer(256);
Only in freenet1/src/freenet/node: NodeReference.java.new