On Friday 23 May 2008 15:24, batosai at freenetproject.org wrote: > Author: batosai > Date: 2008-05-23 14:24:43 +0000 (Fri, 23 May 2008) > New Revision: 20062 > > Added: > trunk/apps/WoT/README > trunk/apps/WoT/gpl.txt > trunk/apps/WoT/src/ > trunk/apps/WoT/src/plugins/ > trunk/apps/WoT/src/plugins/WoT/ > trunk/apps/WoT/src/plugins/WoT/Identity.java > trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java > trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java > trunk/apps/WoT/src/plugins/WoT/Trust.java > trunk/apps/WoT/src/plugins/WoT/Trustlist.java > trunk/apps/WoT/src/plugins/WoT/WoT.java > Log: > Initial import. > > Added: trunk/apps/WoT/README > =================================================================== > --- trunk/apps/WoT/README (rev 0) > +++ trunk/apps/WoT/README 2008-05-23 14:24:43 UTC (rev 20062) > @@ -0,0 +1,34 @@ > +COPYRIGHT > +========= > + > +WoT copyright is held by Freenet Project Incorporated.
It is? Generally this sort of statement requires a signed form to be filled in at some point. I suggest you retain copyright, and declare it as "GPL 2 or later", that should be sufficient flexibility for all plausible outcomes... > WoT is > +distributed under the GPL license. You can find it in the file called > +"gpl.txt". > +---------------- > + > +WoT > +Copyright (C) 2007 Freenet Project Incorporated > + > +This program is free software: you can redistribute it and/or modify > +it under the terms of the GNU General Public License as published by > +the Free Software Foundation, either version 3 of the License, or > +(at your option) any later version. It would be best for us if you made the plugin GPL 2 or later, rather than GPL 3 or later. You can of course license your own code under any license (e.g. WTFPL). Some parts of Freenet may not be GPL3 compatible at present, since I have been unable to contact their authors... :( ). Also, since you have full control at this stage, you can include a full copyright notice in the recommended form in each file (Copyright 2008 Julien Cornuwel, etc etc). This is better, we use the short form in Freenet because until relatively recently we didn't have any notices at all; for new code where the authors list should be kept up to date, a full notice is better. > + > +This program is distributed in the hope that it will be useful, > +but WITHOUT ANY WARRANTY; without even the implied warranty of > +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +GNU General Public License for more details. > + > +You should have received a copy of the GNU General Public License > +along with this program. If not, see <http://www.gnu.org/licenses/>. > + > +COMPILATION > +=========== > + > +You need to link to db4o.jar AND jFCPlib for this program to work. > + > + > +RUNNING > +======= > + > +For now, it only works inside of Eclipse. > \ No newline at end of file > > Added: trunk/apps/WoT/src/plugins/WoT/Identity.java > =================================================================== > --- trunk/apps/WoT/src/plugins/WoT/Identity.java (rev 0) > +++ trunk/apps/WoT/src/plugins/WoT/Identity.java 2008-05-23 14:24:43 UTC (rev 20062) > @@ -0,0 +1,95 @@ > +/** > + * This code is part of WoT, a plugin for Freenet. It is distributed > + * under the GNU General Public License, version 2 (or at your option > + * any later version). See http://www.gnu.org/ for details of the GPL. > + */ > +package plugins.WoT; > + > +import java.util.Date; > + > +import com.db4o.ObjectContainer; > + > +/** > + * An identity as handled by the WoT (a SSK) > + * > + * @author Julien Cornuwel (batosai at batosai.net) 0x61917D90 GPG keyID is a nice touch. > + * > + */ > +public class Identity { > + > + String requestURI; > + Date lastChange; > + boolean publishTrustList; > + > + public Identity() { > + > + } > + > + /** > + * Create an identity with the given parameters > + * > + * @param requestURI EequestURI where the identity can be fetched > + * @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) { > + this.requestURI = requestURI; > + this.lastChange = lastChange; > + this.publishTrustList = publishTrustList; > + } > + > + /** > + * Create a new trust relationship for this identity > + * > + * @param db Connection to the database > + * @param trustee Identity that receives the trust > + * @param value Numeric value of the trust granted [-100;+100] > + */ > + public void addTrust (ObjectContainer db, Identity trustee, int value) { > + Trust trust = new Trust(this,trustee,value); > + db.store(trust); > + } > + > + /** > + * @return requestURI > + */ > + public String getRequestURI() { > + return requestURI; > + } > + > + /** > + * @param requestURI The RequestURI of the Identity > + */ > + public void setRequestURI(String requestURI) { > + this.requestURI = requestURI; > + } > + > + /** > + * @return lastChange > + */ > + public Date getLastChange() { > + return lastChange; > + } > + > + /** > + * @param lastChange Date of the Identity's last update > + */ > + public void setLastChange(Date lastChange) { > + this.lastChange = lastChange; > + } > + > + /** > + * @return publishTrustList > + */ > + public boolean PublishesTrustList() { > + return publishTrustList; > + } > + > + /** > + * @param publishTrustList Whether the Identity publishes its trustList > or not > + */ > + public void setPublishTrustList(boolean publishTrustList) { > + this.publishTrustList = publishTrustList; > + } > + > +} > > Added: trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java > =================================================================== > --- trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java > (rev 0) > +++ trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java 2008-05-23 > 14:24:43 UTC (rev 20062) > @@ -0,0 +1,74 @@ > +/** > + * This code is part of WoT, a plugin for Freenet. It is distributed > + * under the GNU General Public License, version 2 (or at your option > + * any later version). See http://www.gnu.org/ for details of the GPL. > + */ > +package plugins.WoT; > + > +import java.util.Date; > + > +import com.db4o.ObjectContainer; > +import com.db4o.ObjectSet; > + > +/** > + * @author Julien Cornuwel (batosai at batosai.net) 0x61917D90 > + * > + * Inserts updated identities. > + */ > +public class IdentityInserter implements Runnable{ > + > + private ObjectContainer db; > + private ObjectSet<OwnIdentity> identities; > + private Thread inserter; > + > + /** > + * Creates the IdentityInserter > + * > + * @param db Connection to the database > + */ > + public IdentityInserter(ObjectContainer db) { > + this.db = db; > + } > + > + /** > + * Periodically checks what identities have been updated and inserts > them > + */ > + public void run() { > + > + while(Thread.currentThread() == inserter) { > + > + //TODO Rewrite this so we only get identities that need > to be inserted > + identities = db.query(OwnIdentity.class); > + while(identities.hasNext()) { > + OwnIdentity id = identities.next(); > + System.out.println(id.needsInsert()); > + id.setLastInsert(new Date()); > + } > + try { > + Thread.sleep(1000); > + } > + catch (InterruptedException e) { > + e.printStackTrace(); > + } > + > + } > + } > + > + /** > + * Creates a new Thread and launch the IdentityInserter > + */ > + public void start() { > + if (inserter == null) { > + inserter = new Thread(this); > + inserter.start(); > + } > + } > + > + /** > + * Cleanly stops the IdentityInserter thread > + */ > + public void stop() { > + inserter = null; > + } > + > +} > > Added: trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java > =================================================================== > --- trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java (rev 0) > +++ trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java 2008-05-23 14:24:43 UTC (rev 20062) > @@ -0,0 +1,179 @@ > +/** > + * This code is part of WoT, a plugin for Freenet. It is distributed > + * under the GNU General Public License, version 2 (or at your option > + * any later version). See http://www.gnu.org/ for details of the GPL. > + */ > +package plugins.WoT; > + > +import java.io.BufferedOutputStream; > +import java.io.File; > +import java.io.FileNotFoundException; > +import java.io.FileOutputStream; > +import java.io.IOException; > +import java.util.Date; > + > +import javax.xml.parsers.DocumentBuilder; > +import javax.xml.parsers.DocumentBuilderFactory; > +import javax.xml.parsers.ParserConfigurationException; > +import javax.xml.transform.OutputKeys; > +import javax.xml.transform.Transformer; > +import javax.xml.transform.TransformerConfigurationException; > +import javax.xml.transform.TransformerException; > +import javax.xml.transform.TransformerFactory; > +import javax.xml.transform.dom.DOMSource; > +import javax.xml.transform.stream.StreamResult; > + > +import net.pterodactylus.fcp.FcpAdapter; > +import net.pterodactylus.fcp.FcpConnection; > +import net.pterodactylus.fcp.GenerateSSK; > +import net.pterodactylus.fcp.SSKKeypair; > + > +import org.w3c.dom.DOMImplementation; > +import org.w3c.dom.Document; > +import org.w3c.dom.Element; > + > +import com.db4o.ObjectContainer; > + > +/** > + * A local Identity (it belongs to the user) > + * > + * @author Julien Cornuwel (batosai at batosai.net) 0x61917D90 > + * > + */ > +public class OwnIdentity extends Identity { > + > + private String insertURI; > + private Date lastInsert; > + > + > + /** > + * Creates a local identity with the given parameters > + * > + * @param insertURI Insert URI of the Identity > + * @param requestURI Request URI of the Identity > + * @param lastInsert Last time the Identity has been inserted in Freenet > + * @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) { > + > + super(requestURI, lastChange, publishTrustList); > + this.insertURI = insertURI; > + this.lastInsert = lastInsert; > + > + } > + > + /** > + * Creates a new local identity from scratch (generates a new SSK > Keypair) > + * > + * @param fcp Connection to the Freenet node > + * @throws IOException > + * @throws InterruptedException > + */ > + public OwnIdentity(FcpConnection fcp) throws IOException,InterruptedException { > + > + lastInsert = new Date(0); > + lastChange = new Date(); > + publishTrustList = true; > + > + FcpAdapter fcpAdapter = new FcpAdapter() { > + @Override > + public void receivedSSKKeypair(FcpConnection > fcpConnection, SSKKeypair sskKeypair) { > + requestURI = sskKeypair.getRequestURI(); > + insertURI = sskKeypair.getInsertURI(); > + synchronized (this) { > + notify(); > + } > + } > + }; > + > + fcp.addFcpListener(fcpAdapter); > + synchronized (fcpAdapter) { > + fcp.sendMessage(new GenerateSSK()); > + fcpAdapter.wait(); > + } > + } Nice library API. > + > + /** > + * Generates a XML file describing the identity > + * > + * @param db Connection to the database > + * @throws ParserConfigurationException > + * @throws TransformerConfigurationException > + * @throws TransformerException > + * @throws FileNotFoundException > + * @throws IOException > + */ > + public void exportToXML(ObjectContainer db, File dir ) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, FileNotFoundException, IOException { > + > + // Create the output file > + File outputFile = new File(dir, "identity.xml"); > + BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(outputFile)); > + StreamResult resultStream = new StreamResult(fos); > + > + // Create the XML document > + DocumentBuilderFactory xmlFactory = > DocumentBuilderFactory.newInstance(); > + DocumentBuilder xmlBuilder = xmlFactory.newDocumentBuilder(); > + DOMImplementation impl = xmlBuilder.getDOMImplementation(); > + Document xmlDoc = impl.createDocument(null, "WoT", null); > + Element rootElement = xmlDoc.getDocumentElement(); > + > + // Create the content > + Element identity = xmlDoc.createElement("identity"); > + Element publishTrustList = > xmlDoc.createElement("publishTrustList"); > + > publishTrustList.setTextContent(String.valueOf(this.publishTrustList)); > + identity.appendChild(publishTrustList); > + rootElement.appendChild(identity); > + > + if(this.publishTrustList) { > + Trustlist trustList = new Trustlist(db, this); > + rootElement.appendChild(trustList.toXML(xmlDoc)); > + } > + > + DOMSource domSource = new DOMSource(xmlDoc); > + TransformerFactory transformFactory = > TransformerFactory.newInstance(); > + Transformer serializer = transformFactory.newTransformer(); > + > + serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); > + serializer.setOutputProperty(OutputKeys.INDENT,"yes"); > + serializer.transform(domSource, resultStream); > + > + fos.close(); > + } > + > + /** > + * > + * @return Whether the identity has been updated since the last insert > + */ > + public boolean needsInsert() { > + return (lastChange.compareTo(lastInsert) > 0); > + } > + > + /** > + * @return insertURI > + */ > + public String getInsertURI() { > + return insertURI; > + } > + > + /** > + * @param insertURI InsertURI of the Identity > + */ > + public void setInsertURI(String insertURI) { > + this.insertURI = insertURI; > + } > + > + /** > + * @return lastInsert > + */ > + public Date getLastInsert() { > + return lastInsert; > + } > + > + /** > + * @param lastInsert Date of insertion in Freenet > + */ > + public void setLastInsert(Date lastInsert) { > + this.lastInsert = lastInsert; > + } > +} > > Added: trunk/apps/WoT/src/plugins/WoT/Trust.java > =================================================================== > --- trunk/apps/WoT/src/plugins/WoT/Trust.java (rev 0) > +++ trunk/apps/WoT/src/plugins/WoT/Trust.java 2008-05-23 14:24:43 UTC (rev 20062) > @@ -0,0 +1,97 @@ > +/** > + * This code is part of WoT, a plugin for Freenet. It is distributed > + * under the GNU General Public License, version 2 (or at your option > + * any later version). See http://www.gnu.org/ for details of the GPL. > + */ > +package plugins.WoT; > + > +import org.w3c.dom.Document; > +import org.w3c.dom.Element; > + > +/** > + * A trust relationship between two identities > + * > + * @author Julien Cornuwel (batosai at batosai.net) 0x61917D90 > + * > + */ > +public class Trust { > + > + /* We use a reference to the truster here rather that storing the trustList in the Identity. > + * This allows us to load only what's needed in memory instead of everything. > + * Maybe db4o can handle this, I don't know ATM. > + */ > + private Identity truster; > + private Identity trustee; > + private int value; > + > + > + /** > + * Creates a trust relationship between two identities > + * > + * @param truster Identity that gives the trust > + * @param trustee Identity that receives the trust > + * @param value Numeric value of the trust [-100;+100] > + */ > + public Trust(Identity truster, Identity trustee, int value) { > + this.truster = truster; > + this.trustee = trustee; > + setValue(value); > + } > + > + /** > + * > + * @param xmlDoc XML document > + * @return XML Element containing details of the trust relation > + */ > + public Element toXML(Document xmlDoc) { > + Element elem = xmlDoc.createElement("trust"); > + elem.setAttribute("value", String.valueOf(value)); > + elem.setTextContent(trustee.getRequestURI()); > + > + return elem; > + } Request URIs are used to identify those trusted. If you are using USKs, two URIs may refer to the same identity. (If you're not, what are you using for updating?). Is this a problem? > + > + /** > + * @return truster > + */ > + public Identity getTruster() { > + return truster; > + } > + > + /** > + * @param truster Identity that gives the trust > + */ > + public void setTruster(Identity truster) { > + this.truster = truster; > + } > + > + /** > + * @return trustee > + */ > + public Identity getTrustee() { > + return trustee; > + } > + > + /** > + * @param trustee Identity that receives the trust > + */ > + public void setTrustee(Identity trustee) { > + this.trustee = trustee; > + } > + > + /** > + * @return value > + */ > + public int getValue() { > + return value; > + } > + > + /** > + * @param value Numeric value of the trust [-100;+100] > + */ > + public void setValue(int value) { > + if(value >= -100 && value <= 100) { > + this.value = value; > + } > + } > +} > -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: <https://emu.freenetproject.org/pipermail/devl/attachments/20080802/5da1a95e/attachment.pgp>
