[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[freehaven-cvs] Optimizations, refactorings, sanity checks and gener...
Update of /home/freehaven/cvsroot/doc/e2e-traffic/src
In directory moria.mit.edu:/tmp/cvs-serv27320
Modified Files:
Makefile netparams.cpp rng.h sim.cpp sim.h simmain.cpp
trials.cpp trials.h vec.h
Log Message:
Optimizations, refactorings, sanity checks and general goodness for sim code
Index: Makefile
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Makefile 23 Aug 2003 19:04:29 -0000 1.3
+++ Makefile 22 Nov 2003 23:32:22 -0000 1.4
@@ -5,7 +5,7 @@
./test
CXX=g++
-CFLAGS=-Wall -g -O2 -DFAST_RANDOM
+CFLAGS += -Wall -DFAST_RANDOM
clean:
rm -f *.o *~ sim test
Index: netparams.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/netparams.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- netparams.cpp 23 Aug 2003 19:04:29 -0000 1.1
+++ netparams.cpp 22 Nov 2003 23:32:22 -0000 1.2
@@ -7,7 +7,7 @@
InvDist<int> *
getSingleMixDelays(double pDelay) {
assert(0.0 < pDelay && pDelay < 1.0);
- return new ExponentialDist(pDelay);
+ return new GeometricDist(pDelay);
}
InvDist<int> *
Index: rng.h
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/rng.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rng.h 23 Aug 2003 19:04:29 -0000 1.3
+++ rng.h 22 Nov 2003 23:32:22 -0000 1.4
@@ -40,28 +40,28 @@
~ConstDist() {}
};
-class ExponentialDist : public InvDist<int>
+class GeometricDist : public InvDist<int>
{
private:
double p;
public:
- ExponentialDist(double param) : p(param) {}
- Dist<int> *copy() const { return new ExponentialDist(p); }
+ GeometricDist(double param) : p(param) {}
+ Dist<int> *copy() const { return new GeometricDist(p); }
int get() const { int v = 0; while (rng() > p) ++v; return v; }
double getP(const int &val) const {
return p * std::pow(1-p, (int)val);
}
- ~ExponentialDist() {}
+ ~GeometricDist() {}
};
-class GeometricDist : public InvDist<int>
+class BinomialDist : public InvDist<int>
{
private:
double p;
int n;
public:
- GeometricDist(double prob, int maximum) : p(prob), n(maximum) {}
- Dist<int> *copy() const { return new GeometricDist(p, n); }
+ BinomialDist(double prob, int maximum) : p(prob), n(maximum) {}
+ Dist<int> *copy() const { return new BinomialDist(p, n); }
int get() const {
int v = 0;
for (int i = 0; i < n; ++i) {
@@ -72,7 +72,7 @@
double getP(const int &v) const {
return comb(n, v)*std::pow(p,v)*std::pow(1-p,n-v);
}
- ~GeometricDist() {}
+ ~BinomialDist() {}
};
class CumulativeDist : public InvDist<int>
Index: sim.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/sim.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sim.cpp 23 Aug 2003 21:30:38 -0000 1.4
+++ sim.cpp 22 Nov 2003 23:32:22 -0000 1.5
@@ -6,10 +6,11 @@
Alice::~Alice() {}
Background::~Background() {}
+
// ======================================================================
void
-DistAlice::getTraffic(vec<int> &v_out, int &n_out)
+DistAlice::addTraffic(vec<int> &v_out, int &n_out)
{
int nM;
n_out = nM = nMessageDist->get();
@@ -38,7 +39,7 @@
}
void
-UniformBackground::getNTraffic(vec<int> &v_out, int nMessages)
+UniformBackground::addNTraffic(vec<int> &v_out, int nMessages)
{
assert(nMessages >= 0);
while (nMessages--) {
@@ -47,10 +48,10 @@
}
void
-UniformBackground::getTraffic(vec<int> &v_out, int &nOut)
+UniformBackground::addTraffic(vec<int> &v_out, int &nOut)
{
assert(nPerRound >= 0);
- getNTraffic(v_out, nPerRound);
+ addNTraffic(v_out, nPerRound);
nOut = nPerRound;
}
@@ -65,13 +66,10 @@
}
void
-BatchMix::addRound(const vec<int> &alice,
- int nAlice, const vec<int> &background,
+BatchMix::addRound(const vec<int> &input, int nAlice, int nOther,
FwdAttacker *a)
{
- assert(alice.size() == background.size());
- int nOther = background.total(0);
- a->addRound(nAlice, nOther, alice+background);
+ a->addRound(nAlice, nOther, input);
}
SDAttacker::SDAttacker(vec<double> &bg)
@@ -119,18 +117,19 @@
// Unknown background
void
-DistBackground::getNTraffic(vec<int> &v_out, int nMessages)
+DistBackground::addNTraffic(vec<int> &v_out, int nMessages)
{
while (nMessages-- > 0) {
+ // XXX rng bottleneck
++ v_out[ recipientDist->get() ];
}
}
void
-DistBackground::getTraffic(vec<int> &v_out, int &nOut)
+DistBackground::addTraffic(vec<int> &v_out, int &nOut)
{
nOut = nMessages->get();
- getNTraffic(v_out, nOut);
+ addNTraffic(v_out, nOut);
}
UnkBGBatchAttacker::UnkBGBatchAttacker(int nR)
@@ -202,20 +201,18 @@
}
void
-DelayMix::addRound(const vec<int> &alice,
- int nAlice,
- const vec<int> &background,
+DelayMix::addRound(const vec<int> &inp, int nA, int nO,
FwdAttacker *a)
{
- int nOther = background.total(0);
- int sz = alice.size();
+ int sz = inp.size();
for (int i = 0; i < sz; ++i) {
- int totalForRecip = alice[i]+background[i];
+ int totalForRecip = inp[i];
for (int j = 0; j < totalForRecip; ++j) {
+ // XXX rng bottleneck
++( (*pools[(poolIdx+getDelay())%maxDelay]) [i]);
}
}
- a->addRound(nAlice, nOther, *pools[poolIdx]);
+ a->addRound(nA, nO, *pools[poolIdx]);
pools[poolIdx]->reset(0);
++poolIdx;
if (poolIdx >= maxDelay)
@@ -277,6 +274,7 @@
double exAlice = expectedAliceMsgs();
double exOther = expectedOtherMsgs();
++nRoundsObserved;
+ //std::cout << exAlice << std::endl;
if (exAlice < BG_THRESHOLD) {
for (int i = 0; i < nRecips; ++i)
background[i] += r[i]*exOther;
Index: sim.h
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/sim.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sim.h 23 Aug 2003 21:30:38 -0000 1.4
+++ sim.h 22 Nov 2003 23:32:22 -0000 1.5
@@ -8,15 +8,15 @@
class Alice {
public:
Alice() {}
- virtual void getTraffic(vec<int> &v_out, int &nOut) = 0;
+ virtual void addTraffic(vec<int> &v_add, int &nAdd) = 0;
virtual ~Alice();
};
class Background {
public:
Background() {}
- virtual void getNTraffic(vec<int> &v_out, int nMessages) = 0;
- virtual void getTraffic(vec<int> &v_out, int &nOut) = 0;
+ virtual void addNTraffic(vec<int> &v_out, int nMessages) = 0;
+ virtual void addTraffic(vec<int> &v_out, int &nOut) = 0;
virtual ~Background();
};
@@ -39,9 +39,8 @@
public:
Mixnet() {}
virtual void reset() = 0;
- virtual void addRound(const vec<int> &alice,
- int nAlice,
- const vec<int> &background,
+ virtual void addRound(const vec<int> &input,
+ int nAlice, int nBackground,
FwdAttacker *r) = 0;
virtual ~Mixnet() {}
};
@@ -64,7 +63,7 @@
int p=0)
: nMessageDist(msgs->copy()), nDummyDist(dummies->copy()),
recipientDist(recips->copy()), padding(p) {}
- void getTraffic(vec<int> &v_out, int &nOut);
+ void addTraffic(vec<int> &v_out, int &nOut);
~DistAlice() { delete nMessageDist; delete nDummyDist; delete recipientDist;}
};
@@ -82,9 +81,9 @@
int nPerRound;
public:
UniformBackground(int nR, int nPR=-1);
- void getNTraffic(vec<int> &v_out, int nMessages);
- void getTraffic(vec<int> &v_out, int &nOut);
~UniformBackground() {}
+ void addNTraffic(vec<int> &v_out, int nMessages);
+ void addTraffic(vec<int> &v_out, int &nOut);
};
class BatchMix : public Mixnet {
@@ -93,9 +92,8 @@
public:
BatchMix(int b);
void reset();
- void addRound(const vec<int> &alice,
- int nAlice,
- const vec<int> &background,
+ void addRound(const vec<int> &input,
+ int nAlice, int nBackground,
FwdAttacker *f);
~BatchMix() {}
};
@@ -126,9 +124,9 @@
public:
DistBackground(const Dist<int>&d, const Dist<int> &nMsgs)
: recipientDist(d.copy()), nMessages(nMsgs.copy()) {}
- void getNTraffic(vec<int> &v_out, int nMessages);
- void getTraffic(vec<int> &v_out, int &nOut);
~DistBackground() { delete recipientDist; delete nMessages; }
+ void addNTraffic(vec<int> &v_out, int nMessages);
+ void addTraffic(vec<int> &v_out, int &nOut);
};
class UnkBGBatchAttacker : public FwdAttacker {
@@ -144,6 +142,9 @@
void addRound(int nSentAlice, int nSentOther, const vec<int> &nReceived);
bool guessAlice(vec<double> &nRecipients);
~UnkBGBatchAttacker() {}
+ // protected:
+ void addNTraffic(vec<int> &v_out, int nMessages);
+ void addTraffic(vec<int> &v_out, int &nOut);
};
// ======================================================================
@@ -158,14 +159,13 @@
Dist<int> *delayDist;
protected:
- virtual int getDelay() { return delayDist->get(); }
+ int getDelay() { return delayDist->get(); }
public:
DelayMix(int nRecips, int maxDelay, Dist<int> *delayDist);
void reset();
- void addRound(const vec<int> &alice,
- int nAlice,
- const vec<int> &background,
+ void addRound(const vec<int> &input,
+ int nAlice, int background,
FwdAttacker *a);
~DelayMix();
};
Index: simmain.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/simmain.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- simmain.cpp 23 Aug 2003 21:30:38 -0000 1.3
+++ simmain.cpp 22 Nov 2003 23:32:22 -0000 1.4
@@ -15,7 +15,12 @@
public:
TrialResult attempt()
{
- UnkBGBatchTrial trial(100, 5, 30, true, true, 0.7, 0, 0, 10);
+ UnkBGBatchTrialSpec s;
+ s.setNRecipients(100).setNAliceRecipients(5).setBatchSize(30)
+ .setAliceIsSmallworld(true).setExpMsgDist(true).setPMsgAlice(0.7)
+ .setPDummyAlice(0).setPaddingLevel(0).setGranularity(10);
+
+ UnkBGBatchTrial trial(s);
return trial.attempt();
}
};
@@ -55,13 +60,18 @@
// XTrial trial;
// UnkBGBatchTrial trial(100, 5, 30, false, 0.5, 0.0, 10);
// MixTrial trial(100, 5, 3, 0.5, true, 0.6, 0.2, 30, 3, 0, 5);
- MixTrial trial(100, 5, 3, 0.5, true, 0.6, 0.2, 30, 3, 0, 20, true, 0.4);
+ MixTrialSpec s;
+ s.setNRecipients(100).setNAliceRecipients(5).setPathLen(3).setPDelay(0.5)
+ .setExpAlice(0.5).setPMessage(0.6).setPDummy(0.2).setBGVolMean(30)
+ .setBGVolDev(3).setPadding(0).setGranularity(20)
+ .setPartial(true).setPObserve(.6).setCutoff(1000000);
+ MixTrial trial(s);
+ //MixTrial trial(100, 5, 3, 0.5, true, 0.6, 0.2, 30, 3, 0, 20, true, 0.4);
percentiles p;
- getPercentile(trial, 5, p);
+ getPercentile(trial, 20, p);
cout << "======"
<< p.min << " " << p.p50 << " "
<< p.p90 << " " << p.max << "=====" << endl;
return 0;
}
-
Index: trials.cpp
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/trials.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- trials.cpp 23 Aug 2003 21:30:38 -0000 1.2
+++ trials.cpp 22 Nov 2003 23:32:22 -0000 1.3
@@ -19,8 +19,13 @@
void
TrialResult::write(std::ostream &out) const
{
- out << "[rounds: "<< nRounds<<" (alice in "<< nRoundsAlice
- << ") messages: "<< nMsgs << " (alice sent "<< nMsgsAlice
+ if (failed) {
+ out << "[-";
+ } else {
+ out << "[+";
+ }
+ out << "rounds: "<< nRounds<<" (alice in "<< nRoundsAlice
+ << ") msgs: "<< nMsgs << " (alice sent "<< nMsgsAlice
<< ", "<< nMsgsAliceReal << " real)";
if (nRoundsMaybeAlice) {
out << ". observed rounds: "<<nRoundsObserved<<" (alice maybe in "
@@ -43,33 +48,38 @@
mixnet->reset();
attacker->reset();
- vec<int> aTraffic(nRecips, 0);
- vec<int> bTraffic(nRecips, 0);
+ vec<int> trafficIn(nRecips, 0);
vec<double> recips(nRecips, 0.0);
int n = 0;
while (1) {
- aTraffic.reset(0);
- bTraffic.reset(0);
+ trafficIn.reset(0);
int nAlice;
- alice->getTraffic(aTraffic, nAlice);
+ alice->addTraffic(trafficIn, nAlice);
if (nAlice) {
res.nMsgsAlice += nAlice;
- res.nMsgsAliceReal += aTraffic.total(0);
+ res.nMsgsAliceReal += trafficIn.total(0);
res.nRoundsAlice += 1;
}
- background->getNTraffic(bTraffic, nBatch-nAlice);
+ background->addNTraffic(trafficIn, nBatch-nAlice);
res.nMsgs += nBatch;
//std::cout << n << " "<< aTraffic << std::endl;
- mixnet->addRound(aTraffic, nAlice, bTraffic, attacker);
+ mixnet->addRound(trafficIn, nAlice, nBatch-nAlice, attacker);
++n;
if (!(n % granularity)) {
+ if (n>cutoff) {
+ res.failed = true;
+ res.nRounds = n;
+ return res;
+ }
if (!attacker->guessAlice(recips)) continue;
- //std::cout << n << " " << recips << std::endl;
- //std::cout << n << " ------ " << std::endl;
- //pvec(std::cout, truth);
- //pvec(std::cout, recips.topN(truth.size()));
- //std::cout << n << " ------ " << std::endl;
+#ifndef QUIET
+ std::cout << n << " " << recips << std::endl;
+ std::cout << n << " ------ " << std::endl;
+ pvec(std::cout, truth);
+ pvec(std::cout, recips.topN(truth.size()));
+ std::cout << n << " ------ " << std::endl;
+#endif
if (truth == recips.topN(truth.size())) {
res.nRounds = n;
return res;
@@ -86,8 +96,8 @@
delete alice;
}
-
-SDTrial::SDTrial(int nR, int nAR, int b, int g)
+void
+SDTrial::init(int nR, int nAR, int b, int g, int c)
{
ConstDist<int> aMsgs(1);
ConstDist<int> aDummies(0);
@@ -101,22 +111,23 @@
mixnet = new BatchMix(b);
nRecips = nR;
nBatch = b; granularity = g;
+ cutoff = c;
}
SDTrial::~SDTrial()
{
}
-
-UnkBGBatchTrial::UnkBGBatchTrial(int nR, int nAR, int b,
- bool smallworldAlice,
- bool expMsgDist,
- double pMsgA, double pDA,
- int padding,
- int g)
+void
+UnkBGBatchTrial::init(int nR, int nAR, int b,
+ bool smallworldAlice,
+ bool expMsgDist,
+ double pMsgA, double pDA,
+ int padding,
+ int g, int c)
{
- ExponentialDist aMsgsE(1.0-pMsgA);
- ExponentialDist aDummiesE(1.0-pDA);
+ GeometricDist aMsgsE(1.0-pMsgA);
+ GeometricDist aDummiesE(1.0-pDA);
BinaryDist<int> aMsgsB(pMsgA, 1, 0);
BinaryDist<int> aDummiesB(pDA, 1, 0);
@@ -153,6 +164,7 @@
nRecips = nR;
nBatch = b; granularity = g;
+ cutoff = c;
}
UnkBGBatchTrial::~UnkBGBatchTrial()
@@ -169,32 +181,41 @@
attacker->reset();
mixnet->reset();
- vec<int> aTraffic(nRecips, 0);
+ vec<int> trafficIn(nRecips, 0);
vec<int> bTraffic(nRecips, 0);
vec<double> recips(nRecips, 0.0);
int n = 0;
while (1) {
- aTraffic.reset(0);
- bTraffic.reset(0);
+ trafficIn.reset(0);
int nAlice;
- alice->getTraffic(aTraffic, nAlice);
+ alice->addTraffic(trafficIn, nAlice);
if (nAlice) {
res.nMsgsAlice += nAlice;
- res.nMsgsAliceReal += aTraffic.total(0);
+ res.nMsgsAliceReal += trafficIn.total(0);
res.nRoundsAlice += 1;
}
int nBackground;
- background->getTraffic(bTraffic, nBackground);
+ background->addTraffic(trafficIn, nBackground);
res.nMsgs += nAlice + nBackground;
- mixnet->addRound(aTraffic, nAlice, bTraffic, attacker);
+ mixnet->addRound(trafficIn, nAlice, nBackground, attacker);
++n;
if (!(n % granularity)) {
+ if (n > cutoff) {
+ attacker->guessAlice(recips);
+ res.nRounds = n;
+ res.failed = true;
+ std::cout << "Got only "<<nVecMatch(recips.topN(truth.size()),truth)
+ << " / " << truth.size() << std::endl;
+ return res;
+ }
if (!attacker->guessAlice(recips)) continue;
+#ifndef QUIET
std::cout << n << " ------ " << std::endl;
pvec(std::cout, truth);
pvec(std::cout, recips.topN(truth.size()));
std::cout << n << " ------ " << std::endl;
+#endif
if (truth == recips.topN(truth.size())) {
res.nRounds = n;
return res;
@@ -211,11 +232,11 @@
delete attacker;
}
-MixTrial::MixTrial(int nR, int nAR, int pathLen, double pDelay,
+void
+MixTrial::init(int nR, int nAR, int pathLen, double pDelay,
bool expAlice, double pMessage, double pDummy,
double bgVolMean, double bgVolDev, int padding,
- int g, bool partial, double pObserve)
- : NonbatchTrial(nR, g)
+ int g, bool partial, double pObserve, int c)
{
assert(pathLen > 0);
@@ -246,8 +267,8 @@
nAR, nR);
//// set up alice.
- ExponentialDist aMsgsE(1.0-pMessage);
- ExponentialDist aDummiesE(1.0-pDummy);
+ GeometricDist aMsgsE(1.0-pMessage);
+ GeometricDist aDummiesE(1.0-pDummy);
BinaryDist<int> aMsgsB(pMessage, 1, 0);
BinaryDist<int> aDummiesB(pDummy, 1, 0);
@@ -260,6 +281,8 @@
//// set up background.
background = new DistBackground(*backgroundTrafficDist,
IntNormalDist(bgVolMean, bgVolDev, true));
+
+ cutoff = c;
delete aliceRecipDist;
delete backgroundTrafficDist;
Index: trials.h
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/trials.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- trials.h 23 Aug 2003 21:30:38 -0000 1.2
+++ trials.h 22 Nov 2003 23:32:22 -0000 1.3
@@ -3,6 +3,7 @@
#define _TRIALS_H
#include <iostream>
+#include <assert.h>
#include "sim.h"
#include "rng.h"
@@ -12,6 +13,7 @@
TrialResult() {
nRounds = nRoundsAlice = nRoundsObserved = nRoundsMaybeAlice = 0;
nMsgs = nMsgsAlice = nMsgsAliceReal = 0L;
+ failed = false;
}
int nRounds;
int nRoundsAlice;
@@ -19,6 +21,8 @@
long nMsgsAlice;
long nMsgsAliceReal;
+ bool failed;
+
// only interesting for DelayMix attacks
int nRoundsObserved;
int nRoundsMaybeAlice;
@@ -49,22 +53,55 @@
int nRecips; // How many recipients are there in total?
int nBatch; // How large is the batch?
int granularity; // How often to we check whether the attacker has won?
-
+ int cutoff;
+
BatchTrial() : alice(0), background(0), mixnet(0), attacker(0) {}
public:
TrialResult attempt();
virtual ~BatchTrial();
};
+class SDTrialSpec
+{
+ friend class SDTrial;
+ protected:
+ int nRecipients;
+ int nAliceRecipients;
+ int batchSize;
+ int granularity;
+ int cutoff;
+ public:
+ SDTrialSpec() {
+ granularity = 5; nRecipients = nAliceRecipients = batchSize = 0;
+ cutoff = 1000000000;
+ }
+ SDTrialSpec &setNRecipients(int n) { nRecipients = n; return *this; }
+ SDTrialSpec &setAliceRecipients(int n) { nAliceRecipients = n;return *this; }
+ SDTrialSpec &setBatchSize(int n) { batchSize = n; return *this; }
+ SDTrialSpec &setGranularity(int n) { granularity = n; return *this; }
+ SDTrialSpec &setCutoff(int n) { cutoff = n; return *this; }
+ void assertFilled() const {
+ assert(nRecipients > 0);
+ assert(nAliceRecipients > 0);
+ assert(batchSize > 0);
+ }
+};
+
// ========================================
// Simple statistical disclosure attack
// Batch mix, alice sends 1 message per batch
// Background distribution is known
// Alice has fixed list of recipients, chooses with equal probability.
class SDTrial : public BatchTrial {
-public:
- SDTrial(int nRecipients, int nAliceRecipients, int batchSize,
- int granularity=5);
+ protected:
+ void init(int nRecipients, int nAliceRecipients, int batchSize,
+ int granularity, int cutoff);
+ public:
+ SDTrial(const SDTrialSpec &s) {
+ s.assertFilled();
+ init(s.nRecipients, s.nAliceRecipients, s.batchSize, s.granularity,
+ s.cutoff);
+ }
~SDTrial();
};
@@ -75,14 +112,59 @@
// - follows smallworld distribution.
// Background distribution is unknown smallworld instance.
+class UnkBGBatchTrialSpec
+{
+ friend class UnkBGBatchTrial;
+ protected:
+ int nRecipients, nAliceRecipients, batchSize;
+ bool aliceIsSmallworld, expMsgDist, ais_set, emd_set;
+ double pMsgAlice, pDummyAlice;
+ int paddingLevel, granularity;
+ int cutoff;
+ public:
+ UnkBGBatchTrialSpec() {
+ paddingLevel = 0; granularity = 5; cutoff = 1000000000;
+ nRecipients = nAliceRecipients = batchSize = 0;
+ pMsgAlice = pDummyAlice = -1;
+ ais_set = emd_set = false;
+ }
+ UnkBGBatchTrialSpec &setNRecipients(int n) { nRecipients = n; return *this; }
+ UnkBGBatchTrialSpec &setNAliceRecipients(int n) { nAliceRecipients = n; return *this; }
+ UnkBGBatchTrialSpec &setBatchSize(int n) { batchSize = n; return *this; }
+ UnkBGBatchTrialSpec &setPaddingLevel(int n) { paddingLevel = n; return *this; }
+ UnkBGBatchTrialSpec &setGranularity(int n) { granularity = n; return *this; }
+ UnkBGBatchTrialSpec &setCutoff(int n) { cutoff = n; return *this; }
+
+ UnkBGBatchTrialSpec &setAliceIsSmallworld(bool b) {
+ aliceIsSmallworld = b; ais_set = true; return *this; }
+ UnkBGBatchTrialSpec &setExpMsgDist(bool b) {
+ expMsgDist = b; emd_set = true; return *this; }
+
+ UnkBGBatchTrialSpec &setPMsgAlice(double p) { pMsgAlice = p; return *this; }
+ UnkBGBatchTrialSpec &setPDummyAlice(double p) { pDummyAlice = p; return *this; }
+
+ void assertFilled() const {
+ assert(nRecipients && nAliceRecipients && batchSize);
+ assert(pMsgAlice >= 0.0 && pDummyAlice >= 0.0);
+ assert(ais_set && emd_set);
+ }
+};
+
class UnkBGBatchTrial : public BatchTrial {
-public:
- UnkBGBatchTrial(int nRecipients, int nAliceRecipients,
- int batchSize, bool aliceIsSmallworld,
- bool expMsgDist, // if true, alice sends N msgs on exp. dist
- double pMsgAlice, double pDummyAlice,
- int paddingLevel=0, // if true, and if alice sends dummies in a round, she sends fillDummies messages total.
- int granularity=5);
+ protected:
+ void init(int nRecipients, int nAliceRecipients,
+ int batchSize, bool aliceIsSmallworld,
+ bool expMsgDist, // if true, alice sends N msgs on exp. dist
+ double pMsgAlice, double pDummyAlice,
+ int paddingLevel=0, // if true, and if alice sends dummies in a round, she sends fillDummies messages total.
+ int granularity=5, int cutoff=1000000000);
+ public:
+ UnkBGBatchTrial(const UnkBGBatchTrialSpec &s) {
+ s.assertFilled();
+ init(s.nRecipients, s.nAliceRecipients, s.batchSize,
+ s.aliceIsSmallworld, s.expMsgDist, s.pMsgAlice, s.pDummyAlice,
+ s.paddingLevel, s.granularity, s.cutoff);
+ }
~UnkBGBatchTrial();
};
@@ -100,6 +182,7 @@
std::vector<int> truth;
int nRecips;
int granularity;
+ int cutoff;
NonbatchTrial(int nR, int g) : alice(0), background(0), mixnet(0),
attacker(0), truth(nR), nRecips(nR), granularity(g) {}
@@ -108,22 +191,70 @@
~NonbatchTrial();
};
+class MixTrialSpec {
+ friend class MixTrial;
+ protected:
+ int nRecipients, nAliceRecipients, pathLen, padding, granularity, cutoff;
+ bool expAlice, partial, ea_set, p_set;
+ double pDelay, pMessage, pDummy, bgVolMean, bgVolDev, pObserve;
+ public:
+ MixTrialSpec() {
+ padding = 0; granularity = 5; partial=false; pObserve=1.0;
+ cutoff = 1000000000;
+
+ nRecipients = nAliceRecipients = pathLen = 0;
+ ea_set = p_set = false;
+ pDelay = pMessage = pDummy = bgVolMean = bgVolDev = -1;
+ }
+ MixTrialSpec &setNRecipients(int n) { nRecipients = n; return *this; }
+ MixTrialSpec &setNAliceRecipients(int n) { nAliceRecipients = n; return *this; }
+ MixTrialSpec &setPathLen(int n) { pathLen = n; return *this; }
+ MixTrialSpec &setPadding(int n) { padding = n; return *this; }
+ MixTrialSpec &setGranularity(int n) { granularity = n; return *this; }
+ MixTrialSpec &setCutoff(int n) { cutoff = n; return *this; }
+
+ MixTrialSpec &setExpAlice(bool b) { expAlice = b; ea_set = true; return *this; }
+ MixTrialSpec &setPartial(bool b) { partial = b; p_set = true; return *this; }
+
+ MixTrialSpec &setPDelay(double d) { pDelay = d; return *this; }
+ MixTrialSpec &setPMessage(double d) { pMessage = d; return *this; }
+ MixTrialSpec &setPDummy(double d) { pDummy = d; return *this; }
+ MixTrialSpec &setBGVolMean(double d) { bgVolMean = d; return *this; }
+ MixTrialSpec &setBGVolDev(double d) { bgVolDev = d; return *this; }
+ MixTrialSpec &setPObserve(double d) { pObserve = d; return *this; }
+
+ void assertFilled() const {
+ assert(nRecipients && nAliceRecipients && pathLen);
+ assert(ea_set && p_set);
+ assert(pDelay >= 0.0 && pMessage >= 0.0 && pDummy >= 0.0 &&
+ bgVolMean >= 0.0 && bgVolDev >= 0.0);
+ }
+
+};
+
// Trial with a single mix or a whole mixnet.
class MixTrial : public NonbatchTrial {
+ private:
+ void init(int nRecipients, int nAliceRecipients,
+ int pathLen, // 1 if using a single mix.
+ double pDelay, // probability of being delayed in a randomly chosen round.
+ bool expAlice, // alice uses exponential distribution.
+ double pMessage, // probability of Alice sending a single message.
+ double pDummy, // probability of Alice sending a dummy message
+ double bgVolMean, // \ Taken together, these two decide how many
+ double bgVolDev, // / messages the background sends in a round.
+ int padding=0,
+ int granularity=5,
+ bool partial=false,
+ double pObserve=1.0,
+ int cutoff=1000000000
+ );
public:
- MixTrial(int nRecipients, int nAliceRecipients,
- int pathLen, // 1 if using a single mix.
- double pDelay, // probability of being delayed in a randomly chosen round.
- bool expAlice, // alice uses exponential distribution.
- double pMessage, // probability of Alice sending a single message.
- double pDummy, // probability of Alice sending a dummy message
- double bgVolMean, // \ Taken together, these two decide how many
- double bgVolDev, // / messages the background sends in a round.
- int padding=0,
- int granularity=5,
- bool partial=false,
- double pObserve=1.0
- );
+ MixTrial(const MixTrialSpec &s) : NonbatchTrial(s.nRecipients, s.granularity)
+ { s.assertFilled();
+ init(s.nRecipients, s.nAliceRecipients, s.pathLen, s.pDelay,
+ s.expAlice, s.pMessage, s.pDummy, s.bgVolMean, s.bgVolDev,
+ s.padding, s.granularity, s.partial, s.pObserve, s.cutoff); }
TrialResult attempt();
~MixTrial() {}
};
Index: vec.h
===================================================================
RCS file: /home/freehaven/cvsroot/doc/e2e-traffic/src/vec.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- vec.h 9 Aug 2003 02:35:13 -0000 1.1
+++ vec.h 22 Nov 2003 23:32:22 -0000 1.2
@@ -218,4 +218,21 @@
return o;
}
+inline int
+nVecMatch(const std::vector<int> &a, const std::vector<int> &b)
+{
+ int n = 0;
+
+ for (std::vector<int>::const_iterator it = a.begin(); it != a.end(); ++it) {
+ for (std::vector<int>::const_iterator it2 = b.begin(); it2 != b.end(); ++it2) {
+
+ if (*it2 == *it) {
+ ++n;
+ break;
+ }
+ }
+ }
+ return n;
+}
+
#endif /* _VEC_H */
***********************************************************************
To unsubscribe, send an e-mail to majordomo@seul.org with
unsubscribe freehaven-cvs in the body. http://freehaven.net/