This commit is contained in:
Doug Hoyte
2023-03-05 16:35:43 -05:00
parent 0be5f1b5de
commit 2f59f8ffa3
3 changed files with 39 additions and 72 deletions

View File

@ -57,15 +57,8 @@ int main() {
} else {
throw herr("unexpected mode");
}
if (mode == 1) std::cerr << "CLIENT-ONLY: " << to_hex(id) << std::endl;
if (mode == 2) std::cerr << "RELAY-ONLY : " << to_hex(id) << std::endl;
if (mode == 3) std::cerr << "BOTH : " << to_hex(id) << std::endl;
}
std::cerr << "BEGIN RECONCILATION" << std::endl;
x1.finalise();
x2.finalise();
@ -76,35 +69,36 @@ int main() {
while (q.size()) {
round++;
std::cerr << "ROUND A " << round << std::endl;
std::cerr << "CLIENT -> RELAY" << std::endl;
std::cerr << "CLIENT -> RELAY: " << q.size() << " bytes" << std::endl;
{
std::vector<std::string> have, need;
q = x2.handleQuery(q, have, need);
// q and have are returned to client
for (auto &id : have) {
if (ids1.contains(id)) throw herr("redundant set");
ids1.insert(id);
std::cerr << "ADD CLIENT: " << to_hex(id) << std::endl;
}
for (auto &id : need) {
if (ids2.contains(id)) throw herr("redundant set");
ids2.insert(id);
std::cerr << "ADD RELAY: " << to_hex(id) << std::endl;
}
}
if (q.size()) {
std::cerr << "ROUND B " << round << std::endl;
std::cerr << "RELAY -> CLIENT" << std::endl;
std::cerr << "ROUND B " << round << std::endl;
std::cerr << "RELAY -> CLIENT: " << q.size() << " bytes" << std::endl;
std::vector<std::string> have, need;
q = x1.handleQuery(q, have, need);
for (auto &id : need) {
if (ids1.contains(id)) throw herr("redundant set");
ids1.insert(id);
std::cerr << "ADD CLIENT: " << to_hex(id) << std::endl;
}
for (auto &id : have) {
if (ids2.contains(id)) throw herr("redundant set");
ids2.insert(id);
std::cerr << "ADD RELAY: " << to_hex(id) << std::endl;
}
}
}
@ -115,14 +109,5 @@ int main() {
throw herr("mismatch");
}
/*
std::vector<std::string> have, need;
auto q2 = x2.handleQuery(q, have, need);
for (auto &s : have) std::cout << "HAVE: " << to_hex(s) << std::endl;
for (auto &s : need) std::cout << "NEED: " << to_hex(s) << std::endl;
std::cout << to_hex(q2) << std::endl;
*/
return 0;
}

View File

@ -8,24 +8,37 @@ my $idSize = 16;
srand($ENV{SEED} || 0);
my $stgen = Session::Token->new(seed => "\x00" x 1024, alphabet => '0123456789abcdef', length => $idSize * 2);
my $pid = open2(my $outfile, my $infile, './test/xor');
my $num = rnd(10000) + 1;
while(1) {
my $pid = open2(my $outfile, my $infile, './test/xor');
for (1..$num) {
my $mode = rnd(3) + 1;
my $created = 1677970534 + rnd($num);
my $id = $stgen->get;
print $infile "$mode,$created,$id\n";
my $num = rnd(10000) + 1;
for (1..$num) {
my $mode;
if (rand() < 0.001) {
$mode = rnd(2) + 1;
} else {
$mode = 3;
}
my $created = 1677970534 + rnd($num);
my $id = $stgen->get;
print $infile "$mode,$created,$id\n";
}
close($infile);
while (<$outfile>) {
print $_;
}
waitpid($pid, 0);
my $child_exit_status = $?;
die "failure" if $child_exit_status;
print "\n-----------OK-----------\n";
}
close($infile);
while (<$outfile>) {
print $_;
}
sub rnd {
my $n = shift;