On Friday 14 November 2008 00:35, xor at freenetproject.org wrote:
> Author: xor
> Date: 2008-11-14 00:35:15 +0000 (Fri, 14 Nov 2008)
> New Revision: 23548
>
> Modified:
> trunk/plugins/WoT/introduction/IntroductionPuzzle.java
> Log:
> - Provide boolean to store whether a puzzle was solved, keep solved puzzles
in pool until they expire: We need to store them at least for 1 day for being
able to check which index value is free.
> - Add function for getting a free index value
> - Change constructor to take the mDateOfInsertion as parameter instead of
setting it to current time: this prevents the rare problem that
getFreeIndex() is called before midnight and the puzzle is contructed after
midgnight.
This is to avoid solving the same puzzle twice?
>
> Modified: trunk/plugins/WoT/introduction/IntroductionPuzzle.java
> ===================================================================
> --- trunk/plugins/WoT/introduction/IntroductionPuzzle.java 2008-11-13
23:53:26 UTC (rev 23547)
> +++ trunk/plugins/WoT/introduction/IntroductionPuzzle.java 2008-11-14
00:35:15 UTC (rev 23548)
> @@ -80,6 +80,12 @@
> /* Supplied at creation time or by user: */
>
> private final String mSolution;
> +
> + /**
> + * Set to true after it was used for introducing a new identity. We
> keep
used puzzles in the database until they expire for the purpose of
> + * being able to figure out free index values of new puzzles. Storing a
few KiB for some days will not hurt.
> + */
> + private boolean iWasSolved = false;
>
>
> /* FIXME: wire this in */
> @@ -103,7 +109,7 @@
> mMimeType = newMimeType;
> mData = newData;
> mSolution = null;
> - mDateOfInsertion = myDateOfInsertion;
> + mDateOfInsertion = new Date(myDateOfInsertion.getYear(),
myDateOfInsertion.getMonth(), myDateOfInsertion.getDay());
> mValidUntilTime = myValidUntilTime;
> mIndex = myIndex;
> }
> @@ -113,15 +119,15 @@
> * @param newType
> * @param newData
> */
> - public IntroductionPuzzle(Identity newInserter, String newMimeType,
> byte[]
newData, String newSolution, int myIndex) {
> + public IntroductionPuzzle(Identity newInserter, String newMimeType,
> byte[]
newData, String newSolution, Date newDateOfInsertion, int myIndex) {
> assert( newInserter != null && newMimeType != null
&& !newMimeType.equals("") && newData!=null && newData.length!=0 &&
> newSolution!=null &&
> newSolution.length()>=MINIMAL_SOLUTION_LENGTH &&
myIndex >= 0);
> mInserter = newInserter;
> mMimeType = newMimeType;
> mData = newData;
> mSolution = newSolution;
> - mDateOfInsertion = new Date(); /* FIXME: get it in UTC */
> - mValidUntilTime = System.currentTimeMillis() +
IntroductionServer.PUZZLE_INVALID_AFTER_DAYS * 24 * 60 * 60 * 1000; /* FIXME:
get it in UTC */
> + mDateOfInsertion = new Date(newDateOfInsertion.getYear(),
newDateOfInsertion.getMonth(), newDateOfInsertion.getDay());
> + mValidUntilTime = mDateOfInsertion.getTime() +
IntroductionServer.PUZZLE_INVALID_AFTER_DAYS * 24 * 60 * 60 * 1000; /* FIXME:
get it in UTC */
> mIndex = myIndex;
> }
>
> @@ -129,6 +135,7 @@
> Query q = db.query();
> q.constrain(IntroductionPuzzle.class);
> q.descend("mInserter").constrain(i);
> + q.descend("iWasSolved").constrain(new Boolean(false));
> return q.execute();
> }
>
> @@ -150,6 +157,17 @@
> return (result.hasNext() ? result.next() : null);
> }
>
> + public static int getFreeIndex(ObjectContainer db, OwnIdentity id, Date
date) {
> + Query q = db.query();
> + q.constrain(IntroductionPuzzle.class);
> + q.descend("mInserter").descend("id").constrain(id.getId());
> + q.descend("mDateOfInsertion").constrain(new
> Date(date.getYear(),
date.getMonth(), date.getDay()));
> + q.descend("mIndex").orderDescending();
> + ObjectSet<IntroductionPuzzle> result = q.execute();
> +
> + return result.size() > 0 ? result.next().getIndex()+1 : 0;
> + }
> +
> public String getMimeType() {
> return mMimeType;
> }
> @@ -213,6 +231,10 @@
> return mSolution;
> }
>
> + public void setSolved() {
> + iWasSolved = true;
> + }
> +
> public Identity getInserter() {
> return mInserter;
> }
>
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
>
-------------- 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/20081115/2e31dd11/attachment.pgp>