Author: toad
Date: 2006-11-30 02:20:06 +0000 (Thu, 30 Nov 2006)
New Revision: 11131
Modified:
trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
trunk/freenet/src/freenet/node/FNPPacketMangler.java
trunk/freenet/src/freenet/node/PeerNode.java
trunk/freenet/src/freenet/node/fcp/ModifyPeer.java
Log:
Add new peer option ignoreSourcePort. If this is enabled, we will search for
another address with the same address as the detected peer but a different
port, and use that if we find one. This enables us to connect through corporate
NATs. Not currently auto-detected; must be set manually.
Document the "On selected peers" options in the dropdown a bit.
Delete superfluous PeerNode.getDetectedPeer() in favour of getPeer()
Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
2006-11-30 02:17:12 UTC (rev 11130)
+++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java
2006-11-30 02:20:06 UTC (rev 11131)
@@ -495,12 +495,14 @@
if(advancedEnabled) {
actionSelect.addChild("option",
"value", "enable", "Enable selected peers");
actionSelect.addChild("option",
"value", "disable", "Disable selected peers");
- actionSelect.addChild("option",
"value", "set_burst_only", "On selected peers, set BurstOnly");
+ actionSelect.addChild("option",
"value", "set_burst_only", "On selected peers, set BurstOnly (only set this if
you have a static IP and are not NATed and neither is the peer)");
actionSelect.addChild("option",
"value", "clear_burst_only", "On selected peers, clear BurstOnly");
- actionSelect.addChild("option",
"value", "set_listen_only", "On selected peers, set ListenOnly");
+ actionSelect.addChild("option",
"value", "set_listen_only", "On selected peers, set ListenOnly (not
recommended)");
actionSelect.addChild("option",
"value", "clear_listen_only", "On selected peers, clear ListenOnly");
- actionSelect.addChild("option",
"value", "set_allow_local", "On selected peers, set allowLocalAddresses");
+ actionSelect.addChild("option",
"value", "set_allow_local", "On selected peers, set allowLocalAddresses (useful
if you are connecting to another node on the same LAN)");
actionSelect.addChild("option",
"value", "clear_allow_local", "On selected peers, clear allowLocalAddresses");
+ actionSelect.addChild("option",
"value", "set_ignore_source_port", "On selected peers, set ignoreSourcePort
(try this if behind an evil corporate firewall; otherwise not recommended)");
+ actionSelect.addChild("option",
"value", "clear_ignore_source_port", "On selected peers, clear
ignoreSourcePort");
}
actionSelect.addChild("option", "value", "",
"-- -- --");
actionSelect.addChild("option", "value",
"remove", "Remove selected peers");
@@ -764,6 +766,32 @@
headers.put("Location", "/darknet/");
ctx.sendReplyHeaders(302, "Found", headers, null, 0);
return;
+ } else if (request.isPartSet("doAction") &&
request.getPartAsString("action",25).equals("set_ignore_source_port")) {
+ //int hashcode =
Integer.decode(request.getParam("node")).intValue();
+
+ PeerNode[] peerNodes = node.getDarknetConnections();
+ for(int i = 0; i < peerNodes.length; i++) {
+ if
(request.isPartSet("node_"+peerNodes[i].hashCode())) {
+ peerNodes[i].setIgnoreSourcePort(true);
+ }
+ }
+ MultiValueTable headers = new MultiValueTable();
+ headers.put("Location", "/darknet/");
+ ctx.sendReplyHeaders(302, "Found", headers, null, 0);
+ return;
+ } else if (request.isPartSet("doAction") &&
request.getPartAsString("action",25).equals("clear_ignore_source_port")) {
+ //int hashcode =
Integer.decode(request.getParam("node")).intValue();
+
+ PeerNode[] peerNodes = node.getDarknetConnections();
+ for(int i = 0; i < peerNodes.length; i++) {
+ if
(request.isPartSet("node_"+peerNodes[i].hashCode())) {
+ peerNodes[i].setIgnoreSourcePort(false);
+ }
+ }
+ MultiValueTable headers = new MultiValueTable();
+ headers.put("Location", "/darknet/");
+ ctx.sendReplyHeaders(302, "Found", headers, null, 0);
+ return;
} else if (request.isPartSet("doAction") &&
request.getPartAsString("action",25).equals("set_listen_only")) {
//int hashcode =
Integer.decode(request.getParam("node")).intValue();
Modified: trunk/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- trunk/freenet/src/freenet/node/FNPPacketMangler.java 2006-11-30
02:17:12 UTC (rev 11130)
+++ trunk/freenet/src/freenet/node/FNPPacketMangler.java 2006-11-30
02:20:06 UTC (rev 11131)
@@ -494,6 +494,10 @@
}
private void sendPacket(byte[] data, Peer replyTo, PeerNode pn, int
alreadyReportedBytes) throws LocalAddressException {
+ if(pn.isIgnoreSourcePort()) {
+ Peer p = pn.getPeer();
+ if(p != null) replyTo = p;
+ }
usm.sendPacket(data, replyTo, pn.allowLocalAddresses());
pn.reportOutgoingBytes(data.length);
node.outputThrottle.forceGrab(data.length - alreadyReportedBytes);
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2006-11-30 02:17:12 UTC
(rev 11130)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2006-11-30 02:20:06 UTC
(rev 11131)
@@ -283,6 +283,13 @@
/** True if we are currently sending this peer a burst of handshake
requests */
private boolean isBursting;
+
+ /** True if we want to ignore the source port of the node's sent packets.
+ * This is normally set when dealing with an Evil Corporate Firewall which
rewrites the port on outgoing
+ * packets but does not redirect incoming packets destined to the
rewritten port.
+ * What it does is this: If we have an address with the same IP but a
different port, to the detectedPeer,
+ * we use that instead. */
+ private boolean ignoreSourcePort;
/** True if we want to allow LAN/localhost addresses. */
private boolean allowLocalAddresses;
@@ -461,7 +468,7 @@
"\nNode hash: "+HexUtil.bytesToHex(nodeKeyHash)+
"\nThis:
"+HexUtil.bytesToHex(identityHash)+
"\nThis hash:
"+HexUtil.bytesToHex(setupKeyHash)+
- "\nFor: "+getDetectedPeer());
+ "\nFor: "+getPeer());
try {
incomingSetupCipher = new Rijndael(256,256);
@@ -576,6 +583,7 @@
isDisabled = Fields.stringToBool(metadata.get("isDisabled"),
false);
isListenOnly =
Fields.stringToBool(metadata.get("isListenOnly"), false);
isBurstOnly = Fields.stringToBool(metadata.get("isBurstOnly"),
false);
+ ignoreSourcePort =
Fields.stringToBool(metadata.get("ignoreSourcePort"), false);
allowLocalAddresses =
Fields.stringToBool(metadata.get("allowLocalAddresses"), false);
String tempHadRoutableConnectionCountString =
metadata.get("hadRoutableConnectionCount");
if(tempHadRoutableConnectionCountString != null) {
@@ -664,13 +672,24 @@
}
/**
- * Get my low-level address
+ * Get my low-level address.
+ *
+ * Normally this is the address that packets have been received from from
this node.
+ * However, if ignoreSourcePort is set, we will search for a similar
address with a different port
+ * number in the node reference.
*/
- public synchronized Peer getDetectedPeer() {
- return detectedPeer;
- }
-
public synchronized Peer getPeer(){
+ if(ignoreSourcePort) {
+ FreenetInetAddress addr = detectedPeer == null ? null :
detectedPeer.getFreenetAddress();
+ int port = detectedPeer == null ? -1 : detectedPeer.getPort();
+ if(nominalPeer == null) return detectedPeer;
+ for(int i=0;i<nominalPeer.size();i++) {
+ Peer p = (Peer) nominalPeer.get(i);
+ if(p.getPort() != port &&
p.getFreenetAddress().equals(addr)) {
+ return p;
+ }
+ }
+ }
return detectedPeer;
}
@@ -1527,7 +1546,7 @@
*/
private void sendInitialMessages() {
Message locMsg =
DMT.createFNPLocChangeNotification(node.lm.loc.getValue());
- Message ipMsg = DMT.createFNPDetectedIPAddress(getDetectedPeer());
+ Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer);
try {
if(isRoutable())
@@ -1539,7 +1558,7 @@
}
private void sendIPAddressMessage() {
- Message ipMsg = DMT.createFNPDetectedIPAddress(getDetectedPeer());
+ Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer);
try {
sendAsync(ipMsg, null, 0, null);
} catch (NotConnectedException e) {
@@ -1845,7 +1864,7 @@
*/
public synchronized SimpleFieldSet exportMetadataFieldSet() {
SimpleFieldSet fs = new SimpleFieldSet();
- if(getDetectedPeer() != null)
+ if(detectedPeer != null)
fs.put("detected.udp", detectedPeer.toString());
if(lastReceivedPacketTime() > 0)
fs.put("timeLastReceivedPacket",
Long.toString(timeLastReceivedPacket));
@@ -1863,6 +1882,8 @@
fs.put("isListenOnly", "true");
if(isBurstOnly)
fs.put("isBurstOnly", "true");
+ if(ignoreSourcePort)
+ fs.put("ignoreSourcePort", "true");
if(allowLocalAddresses)
fs.put("allowLocalAddresses", "true");
if(hadRoutableConnectionCount > 0)
@@ -2494,6 +2515,17 @@
node.peers.writePeers();
}
+ public void setIgnoreSourcePort(boolean setting) {
+ synchronized(this) {
+ ignoreSourcePort = setting;
+ }
+ }
+
+
+ public boolean isIgnoreSourcePort() {
+ return ignoreSourcePort;
+ }
+
public synchronized boolean isBurstOnly() {
return isBurstOnly;
}
Modified: trunk/freenet/src/freenet/node/fcp/ModifyPeer.java
===================================================================
--- trunk/freenet/src/freenet/node/fcp/ModifyPeer.java 2006-11-30 02:17:12 UTC
(rev 11130)
+++ trunk/freenet/src/freenet/node/fcp/ModifyPeer.java 2006-11-30 02:20:06 UTC
(rev 11131)
@@ -56,6 +56,12 @@
pn.setBurstOnly(Fields.stringToBool(isBurstOnlyString, false));
}
}
+ String ignoreSourcePortString = fs.get("IsBurstOnly");
+ if(ignoreSourcePortString != null) {
+ if(!ignoreSourcePortString.equals("")) {
+
pn.setIgnoreSourcePort(Fields.stringToBool(ignoreSourcePortString, false));
+ }
+ }
String allowLocalAddressesString =
fs.get("AllowLocalAddresses");
if(allowLocalAddressesString != null) {
if(!allowLocalAddressesString.equals("")) {