Author: toad
Date: 2006-01-23 23:39:11 +0000 (Mon, 23 Jan 2006)
New Revision: 7906
Modified:
branches/async-client/build.xml
branches/async-client/src/freenet/crypt/DSAPublicKey.java
branches/async-client/src/freenet/io/comm/DMT.java
branches/async-client/src/freenet/keys/ClientSSK.java
branches/async-client/src/freenet/keys/NodeSSK.java
branches/async-client/src/freenet/node/RequestSender.java
branches/async-client/src/freenet/node/SSKInsertHandler.java
branches/async-client/src/freenet/node/SSKInsertSender.java
branches/async-client/src/freenet/node/TextModeClientInterface.java
branches/async-client/src/freenet/node/Version.java
branches/async-client/src/freenet/node/fcp/AllDataMessage.java
branches/async-client/src/freenet/node/fcp/ClientGetMessage.java
branches/async-client/src/freenet/node/fcp/ClientPut.java
branches/async-client/src/freenet/node/fcp/ClientPutMessage.java
branches/async-client/src/freenet/node/fcp/DataFoundMessage.java
branches/async-client/src/freenet/node/fcp/FCPConnectionHandler.java
branches/async-client/src/freenet/node/fcp/FCPConnectionInputHandler.java
branches/async-client/src/freenet/node/fcp/GetFailedMessage.java
branches/async-client/src/freenet/node/fcp/ProtocolErrorMessage.java
branches/async-client/src/freenet/node/fcp/PutFailedMessage.java
branches/async-client/src/freenet/store/BerkeleyDBFreenetStore.java
Log:
Merge recent trunk changes into branch.
Modified: branches/async-client/build.xml
===================================================================
--- branches/async-client/build.xml 2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/build.xml 2006-01-23 23:39:11 UTC (rev 7906)
@@ -7,7 +7,7 @@
Possible targets: compile, dist (default), clean
</description>
- <!-- set global properties for this build -->
+<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="lib" location="lib"/>
Modified: branches/async-client/src/freenet/crypt/DSAPublicKey.java
===================================================================
--- branches/async-client/src/freenet/crypt/DSAPublicKey.java 2006-01-23
23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/crypt/DSAPublicKey.java 2006-01-23
23:39:11 UTC (rev 7906)
@@ -2,6 +2,8 @@
package freenet.crypt;
import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.io.*;
import freenet.support.HexUtil;
@@ -133,6 +135,15 @@
return bytes;
}
+ public byte[] asBytesHash() {
+ try {
+ MessageDigest md256 =
MessageDigest.getInstance("SHA-256");
+ return md256.digest(asBytes());
+ } catch (NoSuchAlgorithmException e) {
+ throw new Error(e);
+ }
+ }
+
public byte[] asPaddedBytes() {
byte[] asBytes = asBytes();
if(asBytes.length == PADDED_SIZE)
Modified: branches/async-client/src/freenet/io/comm/DMT.java
===================================================================
--- branches/async-client/src/freenet/io/comm/DMT.java 2006-01-23 23:28:05 UTC
(rev 7905)
+++ branches/async-client/src/freenet/io/comm/DMT.java 2006-01-23 23:39:11 UTC
(rev 7906)
@@ -688,6 +688,8 @@
return "Verify failed";
else if(reason == DATA_INSERT_REJECTED_RECEIVE_FAILED)
return "Receive failed";
+ else if(reason == DATA_INSERT_REJECTED_SSK_ERROR)
+ return "SSK error";
return "Unknown reason code: "+reason;
}
Modified: branches/async-client/src/freenet/keys/ClientSSK.java
===================================================================
--- branches/async-client/src/freenet/keys/ClientSSK.java 2006-01-23
23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/keys/ClientSSK.java 2006-01-23
23:39:11 UTC (rev 7906)
@@ -9,6 +9,7 @@
import freenet.crypt.DSAPublicKey;
import freenet.crypt.UnsupportedCipherException;
import freenet.crypt.ciphers.Rijndael;
+import freenet.support.Logger;
public class ClientSSK extends ClientKey {
@@ -100,6 +101,7 @@
return new NodeSSK(pubKeyHash, ehDocname, pubKey);
} catch (SSKVerifyException e) {
IllegalStateException x = new
IllegalStateException("Have already verified and yet it fails!: "+e);
+ Logger.error(this, "Have already verified and yet it
fails!: "+e);
x.initCause(e);
throw x;
}
Modified: branches/async-client/src/freenet/keys/NodeSSK.java
===================================================================
--- branches/async-client/src/freenet/keys/NodeSSK.java 2006-01-23 23:28:05 UTC
(rev 7905)
+++ branches/async-client/src/freenet/keys/NodeSSK.java 2006-01-23 23:39:11 UTC
(rev 7906)
@@ -131,7 +131,7 @@
if(pubKey == pubKey2) return;
if(pubKey2 == null) return;
if(pubKey == null || !pubKey2.equals(pubKey)) {
- if(pubKey != null) {
+ if(pubKey2 != null) {
MessageDigest md256;
try {
md256 =
MessageDigest.getInstance("SHA-256");
@@ -140,11 +140,16 @@
}
byte[] newPubKeyHash =
md256.digest(pubKey2.asBytes());
if(Arrays.equals(pubKeyHash, newPubKeyHash)) {
- Logger.error(this, "Found SHA-256
collision or something... WTF?");
+ if(pubKey != null) {
+ // same hash, yet different
keys!
+ Logger.error(this, "Found
SHA-256 collision or something... WTF?");
+ throw new
SSKVerifyException("Invalid new pubkey: "+pubKey2+" old pubkey: "+pubKey);
+ } else {
+ // Valid key, assign.
+ }
} else {
throw new SSKVerifyException("New
pubkey has invalid hash");
}
- throw new SSKVerifyException("Invalid new
pubkey: "+pubKey2+" old pubkey: "+pubKey);
}
pubKey = pubKey2;
}
Modified: branches/async-client/src/freenet/node/RequestSender.java
===================================================================
--- branches/async-client/src/freenet/node/RequestSender.java 2006-01-23
23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/RequestSender.java 2006-01-23
23:39:11 UTC (rev 7906)
@@ -342,10 +342,10 @@
((NodeSSK)key).setPubKey(pubKey);
} catch (SSKVerifyException e) {
pubKey = null;
- Logger.error(this, "Invalid pubkey from
"+source+" on "+uid+" (wrong hash)");
+ Logger.error(this, "Invalid pubkey from
"+source+" on "+uid+" ("+e.getMessage()+")", e);
break; // try next node
} catch (IOException e) {
- Logger.error(this, "Invalid pubkey from
"+source+" on "+uid);
+ Logger.error(this, "Invalid pubkey from
"+source+" on "+uid+" ("+e+")");
break; // try next node
}
if(sskData != null) {
Modified: branches/async-client/src/freenet/node/SSKInsertHandler.java
===================================================================
--- branches/async-client/src/freenet/node/SSKInsertHandler.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/SSKInsertHandler.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -105,7 +105,7 @@
byte[] pubkeyAsBytes =
((ShortBuffer)pk.getObject(DMT.PUBKEY_AS_BYTES)).getData();
try {
pubKey = new
DSAPublicKey(pubkeyAsBytes);
- Logger.minor(this, "Got pubkey on
"+uid);
+ Logger.minor(this, "Got pubkey on
"+uid+" : "+pubKey);
Message confirm =
DMT.createFNPSSKPubKeyAccepted(uid);
try {
source.sendAsync(confirm, null);
Modified: branches/async-client/src/freenet/node/SSKInsertSender.java
===================================================================
--- branches/async-client/src/freenet/node/SSKInsertSender.java 2006-01-23
23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/SSKInsertSender.java 2006-01-23
23:39:11 UTC (rev 7906)
@@ -11,7 +11,6 @@
import freenet.io.comm.Message;
import freenet.io.comm.MessageFilter;
import freenet.io.comm.NotConnectedException;
-import freenet.keys.CHKBlock;
import freenet.keys.NodeSSK;
import freenet.keys.SSKBlock;
import freenet.keys.SSKVerifyException;
Modified: branches/async-client/src/freenet/node/TextModeClientInterface.java
===================================================================
--- branches/async-client/src/freenet/node/TextModeClientInterface.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/TextModeClientInterface.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -7,9 +7,12 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -104,7 +107,7 @@
// System.out.println("PUBLISH:<name> - create a publish/subscribe
stream called <name>");
// System.out.println("PUSH:<name>:<text> - publish a single line of
text to the stream named");
// System.out.println("SUBSCRIBE:<key> - subscribe to a
publish/subscribe stream by key");
- System.out.println("CONNECT:<filename> - connect to a node from its
ref in a file.");
+ System.out.println("CONNECT:<filename|URL> - connect to a node from
its ref in a file/url.");
System.out.println("CONNECT:\n<noderef including an End on a line by
itself> - enter a noderef directly.");
System.out.println("DISCONNECT:<ip:port> - disconnect from a node by
providing it's ip+port");
System.out.println("NAME:<new node name> - change the node's name.");
@@ -443,29 +446,32 @@
key = key.substring(1);
while(key.length() > 0 && key.charAt(key.length()-1) == ' ')
key = key.substring(0, key.length()-2);
+
+ String content = null;
if(key.length() > 0) {
// Filename
+ BufferedReader in;
System.out.println("Trying to connect to noderef in "+key);
File f = new File(key);
- System.out.println("Attempting to read file "+key);
- try {
- FileInputStream fis = new FileInputStream(key);
- DataInputStream dis = new DataInputStream(fis);
- int length = (int)f.length();
- byte[] data = new byte[length];
- dis.readFully(data);
- dis.close();
- connect(new String(data));
- } catch (IOException e) {
- System.err.println("Could not read file: "+e);
- e.printStackTrace(System.err);
+ if (f.isFile()) {
+ System.out.println("Given string seems to be a file,
loading...");
+ in = new BufferedReader(new FileReader(f));
+ } else {
+ System.out.println("Given string seems to be an URL,
loading...");
+ URL url = new URL(key);
+ URLConnection uc = url.openConnection();
+ in = new BufferedReader(
+ new
InputStreamReader(uc.getInputStream()));
}
+ content = readLines(in, true);
+ in.close();
} else {
- String content = readLines(reader, true);
- if(content == null) return;
- if(content.equals("")) return;
- connect(content);
+ content = readLines(reader, true);
}
+ if(content == null) return;
+ if(content.equals("")) return;
+ connect(content);
+
} else if(uline.startsWith("NAME:")) {
System.out.println("Node name currently: "+n.myName);
String key = line.substring("NAME:".length());
Modified: branches/async-client/src/freenet/node/Version.java
===================================================================
--- branches/async-client/src/freenet/node/Version.java 2006-01-23 23:28:05 UTC
(rev 7905)
+++ branches/async-client/src/freenet/node/Version.java 2006-01-23 23:39:11 UTC
(rev 7906)
@@ -20,10 +20,10 @@
public static final String protocolVersion = "1.0";
/** The build number of the current revision */
- public static final int buildNumber = 363;
+ public static final int buildNumber = 374;
/** Oldest build of Fred we will talk to */
- public static final int lastGoodBuild = 359;
+ public static final int lastGoodBuild = 374;
/** The highest reported build of fred */
public static int highestSeenBuild = buildNumber;
Modified: branches/async-client/src/freenet/node/fcp/AllDataMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/AllDataMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/AllDataMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -26,7 +26,7 @@
public SimpleFieldSet getFieldSet() {
SimpleFieldSet fs = new SimpleFieldSet();
- fs.put("DataLength", Long.toHexString(dataLength));
+ fs.put("DataLength", Long.toString(dataLength));
fs.put("Identifier", identifier);
return fs;
}
Modified: branches/async-client/src/freenet/node/fcp/ClientGetMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/ClientGetMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/ClientGetMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -105,11 +105,11 @@
fs.put("IgnoreDS", Boolean.toString(ignoreDS));
fs.put("URI", uri.toString(false));
fs.put("Identifier", identifier);
- fs.put("Verbosity", Integer.toHexString(verbosity));
+ fs.put("Verbosity", Integer.toString(verbosity));
fs.put("ReturnType", getReturnTypeString());
- fs.put("MaxSize", Long.toHexString(maxSize));
- fs.put("MaxTempSize", Long.toHexString(maxTempSize));
- fs.put("MaxRetries", Integer.toHexString(maxRetries));
+ fs.put("MaxSize", Long.toString(maxSize));
+ fs.put("MaxTempSize", Long.toString(maxTempSize));
+ fs.put("MaxRetries", Integer.toString(maxRetries));
return fs;
}
Modified: branches/async-client/src/freenet/node/fcp/ClientPut.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/ClientPut.java 2006-01-23
23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/ClientPut.java 2006-01-23
23:39:11 UTC (rev 7906)
@@ -15,10 +15,12 @@
final InsertBlock block;
final FCPConnectionHandler handler;
final String identifier;
+ final boolean getCHKOnly;
public ClientPut(FCPConnectionHandler handler, ClientPutMessage
message) {
this.handler = handler;
this.identifier = message.identifier;
+ this.getCHKOnly = message.getCHKOnly;
ctx = new InserterContext(handler.defaultInsertContext);
// Now go through the fields one at a time
uri = message.uri;
@@ -37,7 +39,7 @@
public void run() {
try {
- FreenetURI uri = inserter.run(block, false, false,
false, null);
+ FreenetURI uri = inserter.run(block, false, getCHKOnly,
false, null);
FCPMessage msg = new PutSuccessfulMessage(identifier,
uri);
handler.outputHandler.queue(msg);
} catch (InserterException e) {
Modified: branches/async-client/src/freenet/node/fcp/ClientPutMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/ClientPutMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/ClientPutMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -29,6 +29,7 @@
final String identifier;
final int verbosity;
final int maxRetries;
+ final boolean getCHKOnly;
public ClientPutMessage(SimpleFieldSet fs) throws
MessageInvalidException {
try {
@@ -69,15 +70,16 @@
throw new
MessageInvalidException(ProtocolErrorMessage.ERROR_PARSING_NUMBER, "Error
parsing MaxSize field: "+e.getMessage());
}
}
+ getCHKOnly = Boolean.getBoolean(fs.get("GetCHKOnly"));
}
public SimpleFieldSet getFieldSet() {
SimpleFieldSet sfs = new SimpleFieldSet();
sfs.put("URI", uri.toString());
sfs.put("Identifier", identifier);
- sfs.put("DataLength", Long.toHexString(dataLength));
- sfs.put("Verbosity", Integer.toHexString(verbosity));
- sfs.put("MaxRetries", Integer.toHexString(maxRetries));
+ sfs.put("DataLength", Long.toString(dataLength));
+ sfs.put("Verbosity", Integer.toString(verbosity));
+ sfs.put("MaxRetries", Integer.toString(maxRetries));
sfs.put("Metadata.ContentType", contentType);
return sfs;
}
Modified: branches/async-client/src/freenet/node/fcp/DataFoundMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/DataFoundMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/DataFoundMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -20,7 +20,7 @@
SimpleFieldSet fs = new SimpleFieldSet();
fs.put("Identifier", identifier);
fs.put("Metadata.ContentType", mimeType);
- fs.put("DataLength", Long.toHexString(dataLength));
+ fs.put("DataLength", Long.toString(dataLength));
return fs;
}
Modified: branches/async-client/src/freenet/node/fcp/FCPConnectionHandler.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/FCPConnectionHandler.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/FCPConnectionHandler.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -37,6 +37,7 @@
HighLevelSimpleClient client =
node.makeClient((short)0,(short)0);
defaultFetchContext = client.getFetcherContext();
defaultInsertContext = client.getInserterContext();
+ inputHandler.start();
}
public void close() {
Modified:
branches/async-client/src/freenet/node/fcp/FCPConnectionInputHandler.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/FCPConnectionInputHandler.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/FCPConnectionInputHandler.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -11,13 +11,16 @@
final FCPConnectionHandler handler;
- public FCPConnectionInputHandler(FCPConnectionHandler handler) {
+ FCPConnectionInputHandler(FCPConnectionHandler handler) {
this.handler = handler;
+ }
+
+ void start() {
Thread t = new Thread(this, "FCP input handler for
"+handler.sock.getRemoteSocketAddress()+":"+handler.sock.getPort());
t.setDaemon(true);
t.start();
}
-
+
public void run() {
try {
realRun();
Modified: branches/async-client/src/freenet/node/fcp/GetFailedMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/GetFailedMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/GetFailedMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -25,7 +25,7 @@
public SimpleFieldSet getFieldSet() {
SimpleFieldSet sfs = new SimpleFieldSet();
- sfs.put("Code", Integer.toHexString(code));
+ sfs.put("Code", Integer.toString(code));
sfs.put("CodeDescription", codeDescription);
if(extraDescription != null)
sfs.put("ExtraDescription", extraDescription);
Modified: branches/async-client/src/freenet/node/fcp/ProtocolErrorMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/ProtocolErrorMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -58,7 +58,7 @@
public SimpleFieldSet getFieldSet() {
SimpleFieldSet sfs = new SimpleFieldSet();
- sfs.put("Code", Integer.toHexString(code));
+ sfs.put("Code", Integer.toString(code));
sfs.put("CodeDescription", codeDescription());
if(extra != null)
sfs.put("ExtraDescription", extra);
Modified: branches/async-client/src/freenet/node/fcp/PutFailedMessage.java
===================================================================
--- branches/async-client/src/freenet/node/fcp/PutFailedMessage.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/node/fcp/PutFailedMessage.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -29,7 +29,7 @@
public SimpleFieldSet getFieldSet() {
SimpleFieldSet fs = new SimpleFieldSet();
fs.put("Identifier", identifier);
- fs.put("Code", Integer.toHexString(code));
+ fs.put("Code", Integer.toString(code));
fs.put("CodeDescription", codeDescription);
if(extraDescription != null)
fs.put("ExtraDescription", extraDescription);
Modified: branches/async-client/src/freenet/store/BerkeleyDBFreenetStore.java
===================================================================
--- branches/async-client/src/freenet/store/BerkeleyDBFreenetStore.java
2006-01-23 23:28:05 UTC (rev 7905)
+++ branches/async-client/src/freenet/store/BerkeleyDBFreenetStore.java
2006-01-23 23:39:11 UTC (rev 7906)
@@ -4,6 +4,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.util.Arrays;
import com.sleepycat.bind.tuple.TupleBinding;
import com.sleepycat.bind.tuple.TupleInput;
@@ -331,6 +332,17 @@
return null;
}
+ if(!Arrays.equals(block.asBytesHash(), hash)) {
+ Logger.normal(this, "Does not verify, setting
accessTime to 0 for : "+HexUtil.bytesToHex(hash));
+ storeBlock.setRecentlyUsedToZero();
+ DatabaseEntry updateDBE = new DatabaseEntry();
+
storeBlockTupleBinding.objectToEntry(storeBlock, updateDBE);
+ c.putCurrent(updateDBE);
+ c.close();
+ t.commit();
+ return null;
+ }
+
if(!dontPromote)
{
storeBlock.updateRecentlyUsed();