send-list, with percentage, extra stats infos,...
This commit is contained in:
parent
37aa021674
commit
37992dd2d4
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/BesenBoincServer"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1 @@
|
||||||
|
/bin/
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>BBEncryptionCracker</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,27 @@
|
||||||
|
package de.mrbesen;
|
||||||
|
|
||||||
|
import Job.Jobsrc;
|
||||||
|
import Job.Result;
|
||||||
|
import Job.Result.ResultType;
|
||||||
|
|
||||||
|
public class Crack extends Jobsrc {
|
||||||
|
|
||||||
|
private final int start = 0;
|
||||||
|
private final int end = 0;
|
||||||
|
private int modul = 1;
|
||||||
|
private int publicKey = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result run() {
|
||||||
|
Result out = new Result(1);
|
||||||
|
for(int i = start; i < end; i++) {
|
||||||
|
out.add(out.new PartialResult(ResultType.Value, i + ":" + try_to_crack(i)));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean try_to_crack(int i) {
|
||||||
|
//encryption dependend. - for testing: modular multiplication
|
||||||
|
return (publicKey * i) % modul == 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package de.mrbesen;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
|
||||||
|
import Core.Program;
|
||||||
|
import Job.Job;
|
||||||
|
import Job.Result.PartialResult;
|
||||||
|
|
||||||
|
public class CryptCrack extends Program {
|
||||||
|
|
||||||
|
long testing = 1;
|
||||||
|
long public_key = 14012539;//valid private key: 2597832237
|
||||||
|
long mod = 4862802614L;
|
||||||
|
//long public_key = 12600;//valid private key = 5042
|
||||||
|
//long mod = 151621;
|
||||||
|
int testsperrun = 5000000;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
requestnewjobs(100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void HandlePartialResult(PartialResult pres) {
|
||||||
|
String in = (String) pres.obj;
|
||||||
|
System.out.println(in);
|
||||||
|
if(in.split(":",2)[1] == "true") {//match!
|
||||||
|
String key = in.split(":",2)[0];
|
||||||
|
//write to file
|
||||||
|
try {
|
||||||
|
FileWriter fw = new FileWriter("saved");
|
||||||
|
fw.write(key);
|
||||||
|
fw.close();
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("Error while saving progress");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("KEY FOUND!\nkey = " + key);
|
||||||
|
jobmanager.clear();//stop this job
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestnewjobs(int amount) {
|
||||||
|
for(long i = testing; i < testing+(amount*testsperrun); i+= testsperrun) {
|
||||||
|
String code = "import Job.Jobsrc;\nimport Job.Result;\nimport Job.Result.ResultType;\npublic class Crack" + i + " extends Jobsrc {\n private final long start = " + i + "L; private final long end = " + (i + testsperrun) + "L; private long modul = " + mod + "L; private long publicKey = " + public_key + "L; \n @Override\n public Result run() {\n Result out = new Result(" + (jobmanager.jobs_total() +1) + ");\n for(long i = start; i < end; i++) {\n if(try_to_crack(i))\n {out.add(out.new PartialResult(ResultType.Value, i + \":true\"));\n}\n }\n return out;\n }\n public boolean try_to_crack(long i) {\n /*System.out.println(\"Testing\"+i);*/ return (publicKey * i) % modul == 1;\n }\n}";
|
||||||
|
jobmanager.enque(new Job(code));
|
||||||
|
}
|
||||||
|
testing += (amount*testsperrun);
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,7 +60,6 @@ public class Server implements PacketHandler {
|
||||||
programthread = new Thread(prog, "Programm Thread");
|
programthread = new Thread(prog, "Programm Thread");
|
||||||
programthread.start();
|
programthread.start();
|
||||||
System.out.println("Programm execution started");
|
System.out.println("Programm execution started");
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -96,7 +95,6 @@ public class Server implements PacketHandler {
|
||||||
try {
|
try {
|
||||||
ssoc.close();//close server socket
|
ssoc.close();//close server socket
|
||||||
ssoc = null;
|
ssoc = null;
|
||||||
Runtime.getRuntime().gc();//delete ssoc
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,21 @@ import Job.Result.PartialResult;
|
||||||
|
|
||||||
public abstract class Program implements Runnable{
|
public abstract class Program implements Runnable{
|
||||||
|
|
||||||
public JobManager jobmanager = new JobManager();
|
public JobManager jobmanager = new JobManager(this);
|
||||||
|
|
||||||
public void HandleResult(Result r) {
|
public void HandleResult(Result r) {
|
||||||
|
jobmanager.setdone(r.getJobId());
|
||||||
|
|
||||||
while(r.hasnext()) {
|
while(r.hasnext()) {
|
||||||
PartialResult pres = r.next();
|
PartialResult pres = r.next();
|
||||||
switch(pres.type) {
|
switch(pres.type) {
|
||||||
case Console: System.out.println((String) pres.obj);
|
case Console: System.out.println((String) pres.obj); break;
|
||||||
case Value: HandlePartialResult(pres);
|
case Value: HandlePartialResult(pres);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void HandlePartialResult(PartialResult pres);
|
public abstract void HandlePartialResult(PartialResult pres);
|
||||||
|
|
||||||
|
public abstract void requestnewjobs(int amount);
|
||||||
}
|
}
|
|
@ -54,7 +54,7 @@ public class Starter {
|
||||||
run = false;
|
run = false;
|
||||||
} else if(in.equalsIgnoreCase("stats")) {
|
} else if(in.equalsIgnoreCase("stats")) {
|
||||||
JobManager jm = server.getProgram().jobmanager;
|
JobManager jm = server.getProgram().jobmanager;
|
||||||
System.out.println("\nStats:\nTasks done : " + jm.jobs_done() + "\nTasks compiled: " + jm.jobs_compiled() + "/" + jm.jobs_compiledtarget() + "\nCurrently Compiling: " + jm.isCompiling() + "\nTasks enqued : " + jm.jobs_enqued() + "\n--------------------\ntotal : " + jm.jobs_total()+ "\nConnections: " + server.getConnectionCount());
|
System.out.println("\nStats:\nTasks done : " + jm.jobs_done() + "\nTasks send : " + jm.jobs_send() + "\nTasks compiled: " + jm.jobs_compiled() + "/" + jm.jobs_compiledtarget() + "\nCurrently Compiling: " + jm.isCompiling() + "\nTasks enqued : " + jm.jobs_enqued() + "\n--------------------\ntotal : " + jm.jobs_total()+ "\nConnections: " + server.getConnectionCount());
|
||||||
} else {
|
} else {
|
||||||
System.out.println("unknown Command.");
|
System.out.println("unknown Command.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ public class Job implements Serializable{
|
||||||
|
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
// code.replace("[[Jobid]]",""+ id);
|
// code.replace(Pattern.quote("§JOBID§"),""+ id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
|
|
@ -10,15 +10,23 @@ import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import Comunication.Server;
|
import Comunication.Server;
|
||||||
|
import Core.Program;
|
||||||
import Utils.StringUtils;
|
import Utils.StringUtils;
|
||||||
|
|
||||||
public class JobManager implements Iterator<Job>{
|
public class JobManager implements Iterator<Job>{
|
||||||
|
|
||||||
private List<Job> enqued = new ArrayList<Job>();//enqued jobs
|
private List<Job> enqued = new ArrayList<Job>();//enqued jobs
|
||||||
private List<Job> todo = new ArrayList<Job>();//compiled jobs
|
private List<Job> todo = new ArrayList<Job>();//compiled jobs
|
||||||
|
private List<Job> send = new ArrayList<Job>();//assigned jobs
|
||||||
private List<Job> done = new ArrayList<Job>();//done jobs
|
private List<Job> done = new ArrayList<Job>();//done jobs
|
||||||
|
|
||||||
int jobcount = 0;
|
private int jobcount = 0;
|
||||||
|
|
||||||
|
private Program prog;
|
||||||
|
|
||||||
|
public JobManager(Program prog) {
|
||||||
|
this.prog = prog;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isCompiling = false;
|
private boolean isCompiling = false;
|
||||||
|
|
||||||
|
@ -35,7 +43,7 @@ public class JobManager implements Iterator<Job>{
|
||||||
public void run() {
|
public void run() {
|
||||||
isCompiling = true;//doppelt hält besser
|
isCompiling = true;//doppelt hält besser
|
||||||
// System.out.println("Compilingque started!");
|
// System.out.println("Compilingque started!");
|
||||||
while(enqued.size() > 0 & todo.size() < 15) {
|
while(enqued.size() > 0 & todo.size() < 15 & isCompiling) {
|
||||||
Job j = enqued.get(0);
|
Job j = enqued.get(0);
|
||||||
//compile script
|
//compile script
|
||||||
try {
|
try {
|
||||||
|
@ -63,28 +71,6 @@ public class JobManager implements Iterator<Job>{
|
||||||
scan.close();
|
scan.close();
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
|
|
||||||
/*BufferedReader br = new BufferedReader(new FileReader(classfile));//save the file to the String
|
|
||||||
String line = null;
|
|
||||||
StringBuilder strb = new StringBuilder();
|
|
||||||
String linesep = System.getProperty("line.seperator");
|
|
||||||
String out = "";
|
|
||||||
|
|
||||||
while((line= br.readLine()) != null) {
|
|
||||||
out += (line + linesep);
|
|
||||||
}
|
|
||||||
|
|
||||||
j.code = out;*/
|
|
||||||
/*
|
|
||||||
Scanner scanner = new Scanner(classfile);
|
|
||||||
j.code = "";
|
|
||||||
String out = "";
|
|
||||||
while(scanner.hasNext()) {
|
|
||||||
out = out + scanner.next();
|
|
||||||
}
|
|
||||||
scanner.close();
|
|
||||||
j.code = out;
|
|
||||||
System.out.println("File Readed size: " + j.code.length() + " " + out.length());
|
|
||||||
*/
|
|
||||||
|
|
||||||
RandomAccessFile f = new RandomAccessFile(classfile, "r");
|
RandomAccessFile f = new RandomAccessFile(classfile, "r");
|
||||||
j.classfile = new byte[(int)f.length()];
|
j.classfile = new byte[(int)f.length()];
|
||||||
|
@ -122,10 +108,11 @@ public class JobManager implements Iterator<Job>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Job next() {
|
public Job next() {
|
||||||
done.add(todo.get(0));
|
send.add(todo.get(0));
|
||||||
todo.remove(0);
|
todo.remove(0);
|
||||||
update();
|
update();
|
||||||
return done.get(done.size()-1);
|
System.out.println("" + ((int) (((float) done.size()) / ((float)jobs_total()))*100) + "% Done");
|
||||||
|
return send.get(send.size()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,6 +123,9 @@ public class JobManager implements Iterator<Job>{
|
||||||
public void update() {//called from Server on new Client Connection
|
public void update() {//called from Server on new Client Connection
|
||||||
if(enqued.size() > 0 & !isCompiling & todo.size() < jobs_compiledtarget()) {//7 für jede connection vorrätig
|
if(enqued.size() > 0 & !isCompiling & todo.size() < jobs_compiledtarget()) {//7 für jede connection vorrätig
|
||||||
startCompile();
|
startCompile();
|
||||||
|
} else if(enqued.size() < jobs_compiledtarget()) {
|
||||||
|
System.out.println("All jobs done.");
|
||||||
|
prog.requestnewjobs(jobs_compiledtarget() * 15);//mal nen par generieren
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +133,10 @@ public class JobManager implements Iterator<Job>{
|
||||||
return done.size();
|
return done.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int jobs_send() {
|
||||||
|
return send.size();
|
||||||
|
}
|
||||||
|
|
||||||
public int jobs_compiled() {
|
public int jobs_compiled() {
|
||||||
return todo.size();
|
return todo.size();
|
||||||
}
|
}
|
||||||
|
@ -165,8 +159,46 @@ public class JobManager implements Iterator<Job>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop all jobs
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
//posible bug: when the Compiler is running, an then the que is cleared, its posible that the compiler adds a job.
|
||||||
|
//work around: add a wait, or save the Thread object and wait for it
|
||||||
|
isCompiling = false;
|
||||||
|
enqued.clear();
|
||||||
|
done.clear();
|
||||||
|
send.clear();
|
||||||
|
todo.clear();
|
||||||
|
jobcount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isCompiling() {
|
public boolean isCompiling() {
|
||||||
return isCompiling;
|
return isCompiling;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a job as done
|
||||||
|
* @param jobId
|
||||||
|
*/
|
||||||
|
public void setdone(int jobId) {
|
||||||
|
//find yob
|
||||||
|
Job j = null;
|
||||||
|
int pos = -1;
|
||||||
|
for(int i = 0; i < send.size(); i++) {
|
||||||
|
if(send.get(i).getId() == jobId) {
|
||||||
|
j = send.get(i);
|
||||||
|
pos = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(j != null) {
|
||||||
|
send.remove(pos);
|
||||||
|
done.add(j);
|
||||||
|
} else {
|
||||||
|
System.out.println("Job id " + jobId + " not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,10 @@ public class Result implements Serializable{
|
||||||
private List<PartialResult> list = new ArrayList<PartialResult>();
|
private List<PartialResult> list = new ArrayList<PartialResult>();
|
||||||
private int jobid;
|
private int jobid;
|
||||||
|
|
||||||
|
public Result(int job) {
|
||||||
|
jobid = job;
|
||||||
|
}
|
||||||
|
|
||||||
public void OutputConsole(String out) {
|
public void OutputConsole(String out) {
|
||||||
list.add(new PartialResult(ResultType.Console, out));
|
list.add(new PartialResult(ResultType.Console, out));
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,9 @@ public class Worker implements PacketHandler, Runnable{
|
||||||
}
|
}
|
||||||
while (run) {
|
while (run) {
|
||||||
if(jobs.size()>0) {
|
if(jobs.size()>0) {
|
||||||
|
System.out.print("Executing Job: " + jobs.get(0).getId());
|
||||||
Result r = justrun(jobs.get(0));
|
Result r = justrun(jobs.get(0));
|
||||||
|
System.out.println("Done.");
|
||||||
if(r != null) {
|
if(r != null) {
|
||||||
client.send(new Data(r));
|
client.send(new Data(r));
|
||||||
jobs.remove(0);
|
jobs.remove(0);
|
||||||
|
@ -52,6 +54,7 @@ public class Worker implements PacketHandler, Runnable{
|
||||||
System.err.println("Result ist null!");
|
System.err.println("Result ist null!");
|
||||||
}
|
}
|
||||||
} else {//derzeit kein job in petto
|
} else {//derzeit kein job in petto
|
||||||
|
System.out.println("Idle");
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
requestnewjob();
|
requestnewjob();
|
||||||
|
@ -61,20 +64,12 @@ public class Worker implements PacketHandler, Runnable{
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result justrun(Job j) {
|
private Result justrun(Job j) {
|
||||||
// System.out.println("recived code:" + srccode);
|
|
||||||
Result r = null;
|
Result r = null;
|
||||||
try {
|
try {
|
||||||
File classfile = new File(j.classname+".class");//remove class file
|
File classfile = new File(j.classname+".class");//remove class file
|
||||||
if(classfile.exists())
|
if(classfile.exists())
|
||||||
classfile.delete();
|
classfile.delete();
|
||||||
|
|
||||||
System.out.println("File: " + classfile.getAbsolutePath());
|
|
||||||
|
|
||||||
/* System.out.println("Writing file size:" + j.code.length());
|
|
||||||
FileWriter fw = new FileWriter(classfile);//file writing
|
|
||||||
fw.write(j.code);
|
|
||||||
fw.close();
|
|
||||||
*/
|
|
||||||
FileOutputStream fos = new FileOutputStream(classfile);
|
FileOutputStream fos = new FileOutputStream(classfile);
|
||||||
fos.write(j.classfile);
|
fos.write(j.classfile);
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
|
@ -14,4 +14,7 @@ public class Test extends Program {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void HandlePartialResult(PartialResult pres) {}//unused
|
public void HandlePartialResult(PartialResult pres) {}//unused
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestnewjobs(int amount) {}
|
||||||
}
|
}
|
|
@ -97,4 +97,7 @@ public class PrimeFinder extends Program {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestnewjobs(int amount) {}
|
||||||
}
|
}
|
Loading…
Reference in New Issue