On Tuesday 11 November 2008 21:46, xor at freenetproject.org wrote:
> Author: xor
> Date: 2008-11-11 21:46:27 +0000 (Tue, 11 Nov 2008)
> New Revision: 23494
> 
> Modified:
>    trunk/plugins/WoT/introduction/IntroductionPuzzle.java
>    trunk/plugins/WoT/introduction/IntroductionServer.java
> Log:
> Finish implementation of the IntroductionServer. All we need is the client, 
a puzzle factory and UI.
> 
...
> Modified: trunk/plugins/WoT/introduction/IntroductionServer.java
> ===================================================================
> --- trunk/plugins/WoT/introduction/IntroductionServer.java    2008-11-11 
21:43:23 UTC (rev 23493)
> +++ trunk/plugins/WoT/introduction/IntroductionServer.java    2008-11-11 
21:46:27 UTC (rev 23494)
> @@ -38,6 +38,7 @@
>  import freenet.support.api.Bucket;
>  import freenet.support.io.TempBucketFactory;
>  import plugins.WoT.Identity;
> +import plugins.WoT.IdentityFetcher;
>  import plugins.WoT.IdentityParser;
>  import plugins.WoT.OwnIdentity;
>  import plugins.WoT.exceptions.InvalidParameterException;
> @@ -66,6 +67,8 @@
>       
>       /** The TempBucketFactory used to create buckets from puzzles before 
insert */
>       private final TempBucketFactory mTBF;
> +     
> +     private final IdentityFetcher mIdentityFetcher;
>  
>       private final IntroductionPuzzleFactory[] mPuzzleFactories = new 
IntroductionPuzzleFactory[] { new CaptchaFactory1() };
>       
> @@ -82,11 +85,12 @@
>        * @param tbf
>        *            Needed to create buckets from Identities before insert
>        */
> -     public IntroductionServer(ObjectContainer myDB, HighLevelSimpleClient 
myClient, TempBucketFactory myTBF) {
> +     public IntroductionServer(ObjectContainer myDB, HighLevelSimpleClient 
myClient, TempBucketFactory myTBF, IdentityFetcher myFetcher) {
>               isRunning = true;
>               db = myDB;
>               mClient = myClient;
>               mTBF = myTBF;
> +             mIdentityFetcher = myFetcher;
>       }
>  
>       public void run() {
> @@ -233,15 +237,18 @@
>               Logger.debug(this, "Fetched puzzle solution: " + 
> state.getURI());
>  
>               try {
> +                     db.commit();
> +                     Identity newIdentity = 
> Identity.importIntroductionFromXML(db, 
mIdentityFetcher, result.asBucket().getInputStream());
>                       IntroductionPuzzle p = 
> IntroductionPuzzle.getBySolutionURI(db, 
state.getURI());
> -                     Identity newIdentity = p.importSolutionFromXML(db, 
result.asBucket().getInputStream());
>                       OwnIdentity puzzleOwner = (OwnIdentity)p.getInserter();
> -                     
>                       puzzleOwner.setTrust(db, newIdentity, (byte)0, null); 
> /* FIXME: is 0 the 
proper trust for newly imported identities? */
> +                     db.delete(p);
> +                     db.commit();
>               
>                       state.cancel(); /* FIXME: is this necessary */ 
>                       mRequests.remove(state);
>               } catch (Exception e) {
> +                     db.rollback(); /* FIXME: toad: is this safe or might 
> some other thread 
get active and start a transaction which will be interrupted by this? */ 

Rollback in general isn't safe in that it can't automatically revert the 
structures you've stored to disk from their updated states in RAM - I only 
use it when exiting.

You need to ensure that transactions are serialized.

>                       Logger.error(this, "Parsing failed for "+ 
> state.getURI(), e);
>               }
>       }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: not available
URL: 
<https://emu.freenetproject.org/pipermail/devl/attachments/20081112/163c67f6/attachment.pgp>

Reply via email to