Author: xor
Date: 2008-11-16 20:22:29 +0000 (Sun, 16 Nov 2008)
New Revision: 23664
Modified:
trunk/plugins/WoT/WoT.java
trunk/plugins/WoT/introduction/IntroductionClient.java
trunk/plugins/WoT/introduction/IntroductionServer.java
Log:
Wire-in the nodes PRNG and use it to download random puzzle indexes.
Modified: trunk/plugins/WoT/WoT.java
===================================================================
--- trunk/plugins/WoT/WoT.java 2008-11-16 20:04:50 UTC (rev 23663)
+++ trunk/plugins/WoT/WoT.java 2008-11-16 20:22:29 UTC (rev 23664)
@@ -13,6 +13,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Random;
import java.util.UUID;
import java.util.Map.Entry;
@@ -96,6 +97,8 @@
public static final String SELF_URI = "/plugins/plugins.WoT.WoT";
public static final String WOT_CONTEXT = "WoT";
+
+ public Random random;
public void runPlugin(PluginRespirator pr) {
@@ -111,6 +114,7 @@
seed = getSeedIdentity();
pm = pr.getPageMaker();
+ random = pr.getNode().fastWeakRandom;
/* FIXME: i cannot get this to work, it does not print any
objects although there are definitely IntroductionPuzzle objects in my db.
@@ -153,10 +157,10 @@
}
catch(InvalidParameterException e) {}
- introductionServer = new IntroductionServer(db, client,
pr.getNode().clientCore.tempBucketFactory, fetcher);
+ introductionServer = new IntroductionServer(this,
pr.getNode().clientCore.tempBucketFactory, fetcher);
pr.getNode().executor.execute(introductionServer, "WoT
introduction server");
- introductionClient = new IntroductionClient(db, client,
pr.getNode().clientCore.tempBucketFactory);
+ introductionClient = new IntroductionClient(this,
pr.getNode().clientCore.tempBucketFactory);
pr.getNode().executor.execute(introductionClient, "WoT
introduction client");
// Try to fetch all known identities
Modified: trunk/plugins/WoT/introduction/IntroductionClient.java
===================================================================
--- trunk/plugins/WoT/introduction/IntroductionClient.java 2008-11-16
20:04:50 UTC (rev 23663)
+++ trunk/plugins/WoT/introduction/IntroductionClient.java 2008-11-16
20:22:29 UTC (rev 23664)
@@ -19,6 +19,7 @@
import plugins.WoT.Identity;
import plugins.WoT.OwnIdentity;
+import plugins.WoT.WoT;
import plugins.WoT.exceptions.NotInTrustTreeException;
import plugins.WoT.introduction.IntroductionPuzzle.PuzzleType;
@@ -53,8 +54,8 @@
*/
public final class IntroductionClient implements Runnable, ClientCallback {
- private static final long STARTUP_DELAY = 1 * 60 * 1000;
- private static final long THREAD_PERIOD = 10 * 60 * 1000; /* FIXME:
tweak before release: */
+ private static final int STARTUP_DELAY = 1 * 60 * 1000;
+ private static final int THREAD_PERIOD = 10 * 60 * 1000; /* FIXME:
tweak before release: */
public static final byte PUZZLE_DOWNLOAD_BACKWARDS_DAYS =
IntroductionServer.PUZZLE_INVALID_AFTER_DAYS - 1;
public static final int PUZZLE_REQUEST_COUNT = 16;
@@ -74,6 +75,8 @@
/** Used to tell the introduction server thread if it should stop */
private volatile boolean isRunning;
+ private WoT mWoT;
+
/** A reference to the database */
private ObjectContainer db;
@@ -101,10 +104,11 @@
* @param tbf
* Needed to create buckets from Identities before insert
*/
- public IntroductionClient(ObjectContainer myDB, HighLevelSimpleClient
myClient, TempBucketFactory myTBF) {
+ public IntroductionClient(WoT myWoT, TempBucketFactory myTBF) {
isRunning = true;
- db = myDB;
- mClient = myClient;
+ mWoT = myWoT;
+ db = mWoT.getDB();
+ mClient = mWoT.getClient();
mTBF = myTBF;
}
@@ -113,7 +117,7 @@
mThread = Thread.currentThread();
try {
- Thread.sleep((long) (STARTUP_DELAY * (0.5f +
Math.random()))); // Let the node start up
+ Thread.sleep(STARTUP_DELAY/2 +
mWoT.random.nextInt(STARTUP_DELAY)); // Let the node start up
}
catch (InterruptedException e)
{
@@ -130,7 +134,7 @@
Logger.debug(this, "Introduction client loop
finished.");
try {
- Thread.sleep((long) (THREAD_PERIOD * (0.5f +
Math.random())));
+ Thread.sleep(THREAD_PERIOD/2 +
mWoT.random.nextInt(THREAD_PERIOD));
}
catch (InterruptedException e)
{
@@ -284,7 +288,7 @@
for(Identity i : ids) {
try {
- downloadPuzzle(i, 0);
+ downloadPuzzle(i,
mWoT.random.nextInt(IntroductionServer.PUZZLE_COUNT)); /* FIXME: store the
puzzle count as an identity property (i.e. identities will publish in
identity.xml how many puzzles they upload */
} catch (Exception e) {
Logger.error(this, "Starting puzzle download
failed.", e);
}
Modified: trunk/plugins/WoT/introduction/IntroductionServer.java
===================================================================
--- trunk/plugins/WoT/introduction/IntroductionServer.java 2008-11-16
20:04:50 UTC (rev 23663)
+++ trunk/plugins/WoT/introduction/IntroductionServer.java 2008-11-16
20:22:29 UTC (rev 23664)
@@ -17,6 +17,7 @@
import plugins.WoT.Identity;
import plugins.WoT.IdentityFetcher;
import plugins.WoT.OwnIdentity;
+import plugins.WoT.WoT;
import plugins.WoT.introduction.captcha.CaptchaFactory1;
import com.db4o.ObjectContainer;
@@ -48,8 +49,8 @@
*/
public final class IntroductionServer implements Runnable, ClientCallback {
- private static final long STARTUP_DELAY = 1 * 60 * 1000;
- private static final long THREAD_PERIOD = 10 * 60 * 1000; /* FIXME:
tweak before release */
+ private static final int STARTUP_DELAY = 1 * 60 * 1000;
+ private static final int THREAD_PERIOD = 10 * 60 * 1000; /* FIXME:
tweak before release */
public static final byte PUZZLE_COUNT = 10;
public static final byte PUZZLE_INVALID_AFTER_DAYS = 3;
@@ -59,6 +60,8 @@
/** Used to tell the introduction server thread if it should stop */
private volatile boolean isRunning;
+ private WoT mWoT;
+
/** A reference to the database */
private ObjectContainer db;
@@ -88,10 +91,11 @@
* @param tbf
* Needed to create buckets from Identities before insert
*/
- public IntroductionServer(ObjectContainer myDB, HighLevelSimpleClient
myClient, TempBucketFactory myTBF, IdentityFetcher myFetcher) {
+ public IntroductionServer(WoT myWoT, TempBucketFactory myTBF,
IdentityFetcher myFetcher) {
isRunning = true;
- db = myDB;
- mClient = myClient;
+ mWoT = myWoT;
+ db = mWoT.getDB();
+ mClient = mWoT.getClient();
mTBF = myTBF;
mIdentityFetcher = myFetcher;
}
@@ -101,7 +105,7 @@
mThread = Thread.currentThread();
try {
- Thread.sleep((long) (STARTUP_DELAY * (0.5f +
Math.random()))); // Let the node start up
+ Thread.sleep(STARTUP_DELAY/2 +
mWoT.random.nextInt(STARTUP_DELAY)); // Let the node start up
}
catch (InterruptedException e)
{
@@ -132,7 +136,7 @@
Logger.debug(this, "Introduction server loop
finished.");
try {
- Thread.sleep((long) (THREAD_PERIOD * (0.5f +
Math.random())));
+ Thread.sleep(THREAD_PERIOD/2 +
mWoT.random.nextInt(THREAD_PERIOD));
}
catch (InterruptedException e)
{
@@ -233,7 +237,7 @@
IntroductionPuzzle p = null;
do {
try {
- p =
mPuzzleFactories[(int)(Math.random() * 100) %
mPuzzleFactories.length].generatePuzzle(db, identity);
+ p =
mPuzzleFactories[mWoT.random.nextInt(mPuzzleFactories.length)].generatePuzzle(db,
identity);
p.exportToXML(os);
os.close(); os = null;
tempB.setReadOnly();
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs