Author: toad
Date: 2008-02-29 18:18:57 +0000 (Fri, 29 Feb 2008)
New Revision: 18256
Modified:
trunk/freenet/src/freenet/node/PeerNode.java
Log:
Support lookup table for groups.
This will reduce the size of anon-initiator JFK(3)'s by 500 bytes, to under
1kB, and therefore make it possible to connect to nodes with much lower MTUs.
Whether the connection will work once established is another question, but
being able to connect via darknet but not via announcement due to connectivity
problems is pretty common.
This is only the "read" support. The "write" support will be implemented once
this is mandatory.
And yes I know there's a feature freeze - IMHO this is important, and doesn't
impact much code.
Modified: trunk/freenet/src/freenet/node/PeerNode.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerNode.java 2008-02-29 17:59:15 UTC
(rev 18255)
+++ trunk/freenet/src/freenet/node/PeerNode.java 2008-02-29 18:18:57 UTC
(rev 18256)
@@ -30,6 +30,7 @@
import freenet.crypt.DSAGroup;
import freenet.crypt.DSAPublicKey;
import freenet.crypt.DSASignature;
+import freenet.crypt.Global;
import freenet.crypt.HMAC;
import freenet.crypt.KeyAgreementSchemeContext;
import freenet.crypt.SHA256;
@@ -2049,10 +2050,20 @@
}
static SimpleFieldSet compressedNoderefToFieldSet(byte[] data, int
offset, int length) throws FSParseException {
- if(length == 0)
+ if(length <= 4)
throw new FSParseException("Too short");
- // Firstly, is it compressed?
- if(data[offset] == 1) {
+ // Lookup table for groups.
+ DSAGroup group = null;
+ int firstByte = data[offset];
+ if((firstByte & 2) == 2) {
+ int groupIndex = Fields.bytesToInt(data, offset);
+ offset += 4;
+ length -= 4;
+ group = Global.getGroup(groupIndex);
+ if(group == null) throw new FSParseException("Unknown
group number "+groupIndex);
+ }
+ // Is it compressed?
+ if((firstByte & 1) == 1) {
// Gzipped
Inflater i = new Inflater();
i.setInput(data, offset + 1, length - 1);
@@ -2090,7 +2101,10 @@
}
BufferedReader br = new BufferedReader(isr);
try {
- return new SimpleFieldSet(br, false, true);
+ SimpleFieldSet fs = new SimpleFieldSet(br, false, true);
+ if(group != null)
+ fs.putAllOverwrite(group.asFieldSet());
+ return fs;
} catch(IOException e) {
FSParseException ex = new FSParseException("Impossible:
" + e);
ex.initCause(e);