Author: batosai
Date: 2008-05-31 18:15:31 +0000 (Sat, 31 May 2008)
New Revision: 20169
Added:
trunk/apps/WoT/src/plugins/WoT/FCPHandler.java
trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
Modified:
trunk/apps/WoT/src/plugins/WoT/Identity.java
trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
New class (not finished) to handle identities fetching.
Added: trunk/apps/WoT/src/plugins/WoT/FCPHandler.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/FCPHandler.java
(rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/FCPHandler.java 2008-05-31 18:15:31 UTC
(rev 20169)
@@ -0,0 +1,101 @@
+package plugins.WoT;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+
+import net.pterodactylus.fcp.ClientGet;
+import net.pterodactylus.fcp.ClientHello;
+import net.pterodactylus.fcp.ClientPutDiskDir;
+import net.pterodactylus.fcp.FcpAdapter;
+import net.pterodactylus.fcp.FcpConnection;
+import net.pterodactylus.fcp.GenerateSSK;
+import net.pterodactylus.fcp.NodeHello;
+import net.pterodactylus.fcp.PutFailed;
+import net.pterodactylus.fcp.PutSuccessful;
+import net.pterodactylus.fcp.SSKKeypair;
+
+/**
+ * This class will only exist until Bombe finishes his high-level FCP API
+ *
+ * @author Julien Cornuwel (batosai at batosai.net) 0x61917D90
+ *
+ */
+public class FCPHandler extends FcpAdapter {
+
+ private FcpConnection fcp;
+ private SSKKeypair sskKeypair;
+ private boolean insertSuccessfull;
+ private IdentityFetcher fetcher;
+
+ public FCPHandler(String host, int port) throws UnknownHostException,
IOException, InterruptedException {
+
+ fcp = new FcpConnection(host,port);
+ fcp.connect();
+ fcp.addFcpListener(this);
+ synchronized (this) {
+ fcp.sendMessage(new ClientHello("WoT"));
+ this.wait();
+ }
+ }
+
+ public void close() {
+
+ fcp.disconnect();
+ }
+
+ public SSKKeypair getSSKKeypair() throws IOException,
InterruptedException {
+
+ synchronized (this) {
+ fcp.sendMessage(new GenerateSSK());
+ this.wait();
+ }
+ return sskKeypair;
+ }
+
+ public boolean insertDir (String dir, String uri) throws IOException,
InterruptedException {
+
+ synchronized (this) {
+ fcp.sendMessage(new ClientPutDiskDir(uri,
"WoTinserter", dir));
+ this.wait();
+ }
+
+ return insertSuccessfull;
+ }
+
+ public void getFile (String uri) throws IOException {
+ fcp.sendMessage(new ClientGet(uri, "WoTfetcher"));
+
+ }
+
+ // This is lame, I'll find a better way to notify it later
+ public void addIdentityFetcher(IdentityFetcher id) {
+ fetcher = id;
+ }
+
+ public void receivedNodeHello(FcpConnection fcpConnection, NodeHello
nodeHello) {
+ synchronized (this) {
+ notify();
+ }
+ }
+
+ public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair
sskKeypair) {
+ this.sskKeypair = sskKeypair;
+ synchronized (this) {
+ notify();
+ }
+ }
+
+ public void receivedPutSuccessful(FcpConnection fcpConnection,
PutSuccessful putSuccessful) {
+ insertSuccessfull = true;
+ synchronized (this) {
+ notify();
+ }
+ }
+
+ public void receivedPutFailed(FcpConnection fcpConnection, PutFailed
putFailed) {
+ insertSuccessfull = false;
+ synchronized (this) {
+ notify();
+ }
+ }
+}
Modified: trunk/apps/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-05-31 16:29:13 UTC
(rev 20168)
+++ trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-05-31 18:15:31 UTC
(rev 20169)
@@ -33,9 +33,10 @@
* @param lastChange Last time the Identity has been updated
* @param publishTrustList Whether the identity publishes its trustList
or not
*/
- public Identity (String requestURI, Date lastChange, boolean
publishTrustList) {
+ public Identity (String requestURI, Date lastChange, int edition,
boolean publishTrustList) {
this.requestURI = requestURI;
this.lastChange = lastChange;
+ this.edition = edition;
this.publishTrustList = publishTrustList;
}
@@ -57,6 +58,10 @@
public String getRequestURI() {
return requestURI;
}
+
+ public String getFullRequestURI() {
+ return requestURI + "wot/" + edition + "/identity.xml";
+ }
/**
* @param requestURI The RequestURI of the Identity
Added: trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
(rev 0)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-05-31 18:15:31 UTC
(rev 20169)
@@ -0,0 +1,48 @@
+package plugins.WoT;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import net.pterodactylus.fcp.ClientGet;
+
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import com.db4o.query.Predicate;
+
+public class IdentityFetcher {
+
+ private ObjectContainer db;
+ private FCPHandler fcp;
+
+ /**
+ * Creates the IdentityInserter
+ *
+ * @param db Connection to the database
+ */
+ public IdentityFetcher(ObjectContainer db, FCPHandler fcp) {
+ this.db = db;
+ this.fcp = fcp;
+
+ // TODO Find a better way to be notified of updates
+ fcp.addIdentityFetcher(this);
+
+ List<Identity> identitiesToInsert = db.query(new
Predicate<Identity> () {
+ public boolean match (Identity identity) {
+ // We only get identities we do not own
+ return !(identity instanceof OwnIdentity);
+ }
+ });
+
+ Iterator<Identity> it = identitiesToInsert.iterator();
+
+ while(it.hasNext()) {
+ System.out.println(it.next().getRequestURI());
+ }
+ }
+
+ public void fetch(Identity identity) throws IOException {
+ fcp.getFile(identity.getFullRequestURI());
+
+ }
+}
Modified: trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java 2008-05-31 16:29:13 UTC
(rev 20168)
+++ trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java 2008-05-31 18:15:31 UTC
(rev 20169)
@@ -52,9 +52,9 @@
* @param lastChange Last time the identity (or its trustList) has been
updated
* @param publishTrustList Whether the Identity publishes its trustList
or not
*/
- public OwnIdentity(String insertURI, String requestURI, Date
lastInsert, Date lastChange, boolean publishTrustList) {
+ public OwnIdentity(String insertURI, String requestURI, Date
lastInsert, Date lastChange, int edition, boolean publishTrustList) {
- super(requestURI, lastChange, publishTrustList);
+ super(requestURI, lastChange, edition, publishTrustList);
this.insertURI = insertURI;
this.lastInsert = lastInsert;
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-05-31 16:29:13 UTC (rev
20168)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-05-31 18:15:31 UTC (rev
20169)
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.net.UnknownHostException;
+import java.util.Date;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
@@ -52,8 +53,8 @@
db = Db4o.openFile("WoT.db4o");
fcp = new FCPHandler(host,port);
- identityInserter = new IdentityInserter(db, fcp);
- identityInserter.start();
+ //identityInserter = new IdentityInserter(db, fcp);
+ //identityInserter.start();
}
@@ -79,10 +80,10 @@
ObjectSet<Object> result = db.queryByExample(new Object());
while (result.hasNext()) { db.delete(result.next()); }
+ /*
OwnIdentity root = new OwnIdentity(fcp);
db.store(root);
- /*
Identity a = new Identity("a", new Date(), true);
Identity b = new Identity("b", new Date(), true);
@@ -92,9 +93,13 @@
root.addTrust(db, a, 80);
root.addTrust(db, b, 30);
a.addTrust(db, b, 100);
+ */
- root.exportToXML(db, new File("exportWOT"));
- */
+ Identity test = new Identity("USK at
DCOSLbqlCS-~Ly8ZBxvcI9MkrweRl0t7BLLKs2zGj38,J~GQAEk3m5eXI5KagpSXxHX2~3GPC61eJtQGIWn~5Ns,AQACAAE/",
new Date(), 0, true);
+
+ IdentityFetcher identityFetcher = new IdentityFetcher(db,fcp);
+ identityFetcher.fetch(test);
+
}
/**