Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
netindev committed Jan 14, 2019
1 parent 797a703 commit f1635be
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tk.netindev.drill</groupId>
<artifactId>drill</artifactId>
<version>0.0.3-SNAPSHOT</version>
<version>0.0.4-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/tk/netindev/drill/Drill.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ public class Drill {

private static final Logger logger = LoggerFactory
.getLogger(Drill.class.getName());
public static final double PACKAGE_VERSION = 0.03D;
public static final double PACKAGE_VERSION = 0.04D;

public static void main(String[] args) {

if (args.length == 0) {
logger.error(
"Invalid arguments, please add to the arguments \"-help\".");
Expand All @@ -33,7 +34,8 @@ public static void main(String[] args) {
+ PACKAGE_VERSION);
final String system = System.getProperty("os.name").toLowerCase();
if (!(system.indexOf("win") >= 0 || system.indexOf("nix") >= 0
|| system.indexOf("nux") >= 0 || system.indexOf("aix") >= 0)) {
|| system.indexOf("nux") >= 0 || system.indexOf("aix") >= 0)
|| !System.getProperty("sun.arch.data.model").equals("64")) {
logger.error("Unfortunately, " + system
+ " isn't supported at this time.");
return;
Expand All @@ -52,7 +54,7 @@ private static void parseArgs(String[] args) {

options.addOption(Option.builder("pass").hasArg().build());
options.addOption(Option.builder("thread").hasArg().build());

options.addOption(Option.builder("help").build());
try {
final CommandLine parse = new DefaultParser().parse(options, args);
Expand Down Expand Up @@ -84,7 +86,7 @@ private static void parseArgs(String[] args) {
} catch (final ParseException e) {
logger.error(e.getMessage());
logger.error("Correct use: java -jar scuti-lite.jar --help");
} catch (Exception e) {
} catch (final Exception e) {
logger.error(e.getMessage());
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/tk/netindev/drill/hasher/Hasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ public class Hasher {
public static native void slowHash(byte[] input, byte[] output, int variant);

static {
String string = null;
final String system = System.getProperty("os.name").toLowerCase(),
arch = System.getProperty("sun.arch.data.model");
String library = null;
final String system = System.getProperty("os.name").toLowerCase();
if (system.indexOf("win") >= 0) {
string = arch.equals("64") ? "/win/x64/cryptonight.dll"
: "/win/x86/cryptonight.dll";
library = "/win/x64/cryptonight.dll";
} else if (system.indexOf("nix") >= 0 || system.indexOf("nux") >= 0
|| system.indexOf("aix") >= 0) {
string = "/unix/x64/libcryptonight.so";
library = "/unix/x64/libcryptonight.so";
} else {
logger.error("Couldn't find a dynamic-link library for your system.");
}
try {
Misc.loadLibrary(string);
Misc.loadLibrary(library);
} catch (final IOException e) {
logger.error(e.getMessage());
}
Expand Down
41 changes: 21 additions & 20 deletions src/main/java/tk/netindev/drill/miner/Miner.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private boolean connect() {
this.socket = new Socket(this.host, this.port);
this.printWriter = new PrintWriter(this.socket.getOutputStream());
this.scanner = new Scanner(this.socket.getInputStream());
this.socket.setKeepAlive(true);
this.socket.setTcpNoDelay(true);
this.socket.setSoTimeout(1000 * 150 /* 2:30 mins */);
final JsonObject params = new JsonObject(), doc = new JsonObject();
params.add("login", this.user);
params.add("pass", this.pass);
Expand Down Expand Up @@ -94,9 +95,14 @@ public void start() throws Exception {
break;
}
}
for (final Thread thread : this.set) {
thread.interrupt();
}
this.set.clear();
logger.error("Disconnected from the pool");
this.reconnect();
} else {
logger.error("Couldn't connect to the pool");
this.reconnect();
}
}
Expand All @@ -105,16 +111,17 @@ private Job parseJob(String string) {
final Job job = new Job();
final AtomicBoolean status = new AtomicBoolean(false),
info = new AtomicBoolean(false);
for (Member member : JsonObject.readFrom(string)) {
for (final Member member : JsonObject.readFrom(string)) {
if (member.getName().equals("result")) {
for (Member resultTable : member.getValue().asObject()) {
for (final Member resultTable : member.getValue().asObject()) {
if (resultTable.getName().equals("id")) {
job.setId(resultTable.getValue().asString());
} else if (resultTable.getName().equals("job")) {
for (Member jobTable : resultTable.getValue().asObject()) {
for (final Member jobTable : resultTable.getValue()
.asObject()) {
if (jobTable.getName().equals("blob")) {
job.setBlob(Hex
.unhexlify(jobTable.getValue().asString()));
job.setBlob(
Hex.unhexlify(jobTable.getValue().asString()));
} else if (jobTable.getName().equals("job_id")) {
job.setJobId(jobTable.getValue().asString());
} else if (jobTable.getName().equals("target")) {
Expand All @@ -137,7 +144,7 @@ private Job parseJob(String string) {
}
} else if (member.getName().equals("error")) {
if (!member.getValue().isNull()) {
for (Member errorTable : member.getValue().asObject()) {
for (final Member errorTable : member.getValue().asObject()) {
if (errorTable.getName().equals("message")) {
if (errorTable.getValue().asString()
.equals("Unauthenticated")) {
Expand All @@ -149,12 +156,11 @@ private Job parseJob(String string) {
}
}
} else if (member.getName().equals("params")) {
for (Member paramTable : member.getValue().asObject()) {
for (final Member paramTable : member.getValue().asObject()) {
if (paramTable.getName().equals("id")) {
job.setId(paramTable.getValue().asString());
} else if (paramTable.getName().equals("blob")) {
job.setBlob(
Hex.unhexlify(paramTable.getValue().asString()));
job.setBlob(Hex.unhexlify(paramTable.getValue().asString()));
} else if (paramTable.getName().equals("job_id")) {
job.setJobId(paramTable.getValue().asString());
} else if (paramTable.getName().equals("target")) {
Expand Down Expand Up @@ -186,7 +192,7 @@ protected void send(Job job, byte[] nonce, byte[] result) {

private void work(Job job) {
// I didn't find a better way than this.
for (Thread thread : this.set) {
for (final Thread thread : this.set) {
thread.interrupt();
}
this.set.clear();
Expand All @@ -211,22 +217,17 @@ private float getHashrate() {
}
}
}

private void reconnect() {
try {
logger.info(
"Reconnecting in 30 seconds");
logger.info("Reconnecting in 30 seconds");
Thread.sleep(1000L * 30L);
while (!this.connect()) {
logger.error(
"Couldn't connect, trying to reconnect in 30 seconds");
for (Thread thread : this.set) {
thread.interrupt();
}
logger.error("Couldn't connect, trying to reconnect in 30 seconds");
Thread.sleep(1000L * 30L);
}
this.start();
} catch (Exception e) {
} catch (final Exception e) {
e.printStackTrace();
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/tk/netindev/drill/miner/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public void run() {
final byte[] array = new byte[4];
final byte[] blob = this.job.getBlob();
final int target = this.job.getTarget();
while (!Thread.interrupted()) {
while (!interrupted()) {
blob[39] = (byte) nonce;
blob[40] = (byte) (nonce >> 8);
blob[41] = (byte) (nonce >> 16);
blob[42] = (byte) (nonce >> 24);
Hasher.slowHash(blob, hash, 2 /* (blob[0] - 6 < 0 ? 0 : blob[0] - 6) */);
Hasher.slowHash(blob, hash,
2 /* (blob[0] - 6 < 0 ? 0 : blob[0] - 6) */);
final int difficulty = (((hash[31] << 24) | ((hash[30] & 255) << 16))
| ((hash[29] & 255) << 8)) | (hash[28] & 255);
if (difficulty >= 0 && difficulty <= target) {
Expand All @@ -42,7 +43,8 @@ public void run() {
this.miner.send(this.job, array, hash);
}
synchronized (this.miner.hashrate) {
while (this.miner.hashrate.size() > 99 && !this.miner.hashrate.isEmpty()) {
while (this.miner.hashrate.size() > 99
&& !this.miner.hashrate.isEmpty()) {
this.miner.hashrate.pop();
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/tk/netindev/drill/util/Hex.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tk.netindev.drill.util;

/**
*
*
* @author netindev
*
*/
Expand All @@ -22,25 +22,25 @@ public static int fromHexChar(char c) {
}

public static String hexlify(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
final char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
final int v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
String ret = new String(hexChars);
final String ret = new String(hexChars);
return ret;
}

public static byte[] unhexlify(String string) {
int length = string.length();
final int length = string.length();
if (length % 2 != 0) {
throw new RuntimeException("Odd-length string");
}
byte[] bytes = new byte[length / 2];
final byte[] bytes = new byte[length / 2];
for (int i = 0; i < length; i += 2) {
int top = Character.digit(string.charAt(i), 16);
int bot = Character.digit(string.charAt(i + 1), 16);
final int top = Character.digit(string.charAt(i), 16);
final int bot = Character.digit(string.charAt(i + 1), 16);
if (top == -1 || bot == -1) {
throw new RuntimeException("Non-hexadecimal digit found");
}
Expand Down
Binary file removed src/main/resources/win/x86/cryptonight.dll
Binary file not shown.

0 comments on commit f1635be

Please sign in to comment.