Skip to content

Commit

Permalink
Version 1.0.8
Browse files Browse the repository at this point in the history
Updated Extasys library
  • Loading branch information
nsiatras committed Mar 11, 2024
1 parent 9b23283 commit 77af0e5
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 47 deletions.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions RabbitMiner/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/RabbitMiner
endorsed.classpath=
excludes=
file.reference.Extasys_NT_1.0.3.jar=ExternalLibraries/Extasys/Extasys_NT_1.0.3.jar
file.reference.Extasys_NT_1.0.4.jar=ExternalLibraries/Extasys_NT_1.0.4.jar
file.reference.jna-5.8.0.jar=ExternalLibraries/jna-5.8.0.jar
file.reference.sojo-1.0.0.jar=ExternalLibraries/sojo-1.0.0.jar
includes=**
jar.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${file.reference.Extasys_NT_1.0.3.jar}:\
${file.reference.jna-5.8.0.jar}:\
${file.reference.sojo-1.0.0.jar}:\
${file.reference.Extasys_NT_1.0.4.jar}:\
${libs.absolutelayout.classpath}
# Space-separated list of extra javac options
javac.compilerargs=
Expand Down
78 changes: 41 additions & 37 deletions RabbitMiner/src/rabbitminer/Cluster/Server/ClusterServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
package rabbitminer.Cluster.Server;

import Extasys.DataFrame;
import Extasys.Encryption.Base64Encryptor;
import Extasys.ManualResetEvent;
import Extasys.Network.TCP.Server.Listener.Exceptions.ClientIsDisconnectedException;
import Extasys.Network.TCP.Server.Listener.Exceptions.OutgoingPacketFailedException;
import Extasys.Network.TCP.Server.Listener.TCPClientConnection;
import Extasys.Network.TCP.Server.Listener.TCPListener;
import java.util.HashMap;
import java.util.LinkedHashMap;
import rabbitminer.Cluster.ClusterCommunicationCommons;
Expand All @@ -45,17 +47,19 @@
*/
public class ClusterServer extends Extasys.Network.TCP.Server.ExtasysTCPServer
{

private final RabbitCluster fMyCluster;
private final Object fClientsConnectOrDisconnectLock = new Object();
private final HashMap<String, TCPClientConnection> fConnectedClients;
private final Thread fPingConnectedClientsThread;

public ClusterServer(RabbitCluster myCluster, ClusterServerSettings clusterServerSettings)
{
super("", "", Computer.getComputerCPUCoresCount(), Computer.getComputerCPUCoresCount() * 2);
super.AddListener("", clusterServerSettings.getIPAddress(), clusterServerSettings.getPort(), 60000, 10240, 30000, 150, ClusterCommunicationCommons.fETX);

TCPListener listener = super.AddListener("", clusterServerSettings.getIPAddress(), clusterServerSettings.getPort(), 60000, 10240, 30000, 150, ClusterCommunicationCommons.fETX);
listener.setAutoApplyMessageSplitterState(true);
listener.setConnectionEncryptor(new Base64Encryptor());

fMyCluster = myCluster;
fConnectedClients = new HashMap<>();

Expand All @@ -73,22 +77,22 @@ public ClusterServer(RabbitCluster myCluster, ClusterServerSettings clusterServe
}
catch (Exception ex)
{

}
evt.Reset();
}
});
fPingConnectedClientsThread.start();
}

@Override
public void OnDataReceive(TCPClientConnection sender, DataFrame data)
{
try
{
String incomingStr = new String(data.getBytes(), "UTF-8");
String[] parts = incomingStr.split(ClusterCommunicationCommons.fMessageSplitter);

switch (parts[0])
{
case "LOGIN":
Expand All @@ -106,41 +110,41 @@ public void OnDataReceive(TCPClientConnection sender, DataFrame data)
sender.setTag(var);

// Ειδοποιούμε το Node οτι συνδέθηκε
sender.SendData("AUTHORIZED" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
sender.SendData("AUTHORIZED" + ClusterCommunicationCommons.fMessageSplitter);
}
else
{
sender.SendData("WRONG_PASSWORD" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
sender.SendData("WRONG_PASSWORD" + ClusterCommunicationCommons.fMessageSplitter);
}
break;

case "GET_JOB":
if (CheckIfClientIsAuthorized(sender))
{
// Ζήτα απο το Cluster να φτιάξει ένα
// job για να το δώσουμε στο Node
StratumJob job = fMyCluster.GiveNodeAJobToDo(sender);

if (job != null)
{
sender.SendData("JOB" + ClusterCommunicationCommons.fMessageSplitter + job.toJSON() + ClusterCommunicationCommons.fETX);
sender.SendData("JOB" + ClusterCommunicationCommons.fMessageSplitter + job.toJSON());
}
else
{
// Δεν υπάρχει Job....
sender.SendData("NO_JOB" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
sender.SendData("NO_JOB" + ClusterCommunicationCommons.fMessageSplitter);
}
}
break;

case "JOB_SOLVED":
if (CheckIfClientIsAuthorized(sender))
{
final String jobID = parts[1];
final String extranonce2 = parts[2];
final String nTime = parts[3];
final String nonce = parts[4];

String submitJobStr = "{\"params\": [\"#WORKER_NAME#\", \"#JOB_ID#\", \"#EXTRANONCE_2#\", \"#NTIME#\", \"#NONCE#\"], \"id\": #STRATUM_MESSAGE_ID#, \"method\": \"mining.submit\"}";
submitJobStr = submitJobStr.replace("#WORKER_NAME#", fMyCluster.getStratumPoolSettings().getUsername());
submitJobStr = submitJobStr.replace("#JOB_ID#", jobID);
Expand All @@ -158,49 +162,49 @@ public void OnDataReceive(TCPClientConnection sender, DataFrame data)
fMyCluster.fJobsSubmitted += 1;
}
break;

case "JOB_SOLVED_RANDOMX":
if (CheckIfClientIsAuthorized(sender))
{
StratumJob_RandomX randomXJobSolved = new StratumJob_RandomX(parts[1]);

LinkedHashMap solvedJobParams = new LinkedHashMap();
solvedJobParams.put("id", Parser_RandomX.fPoolLoginID);
solvedJobParams.put("job_id", randomXJobSolved.getJobID());
solvedJobParams.put("nonce", randomXJobSolved.getSolution_NonceHexlifyByteArray());
solvedJobParams.put("result", randomXJobSolved.getSolution_HashHexlifyByteArray());

LinkedHashMap messageToPool = new LinkedHashMap();
messageToPool.put("id", 1);
messageToPool.put("jsonrpc", "2.0");
messageToPool.put("method", "submit");
messageToPool.put("params", solvedJobParams);

String dataToSend = JSONSerializer.SerializeObject(messageToPool);

System.err.println(dataToSend);

fMyCluster.getStratumClient().SendData(dataToSend + "\n");
System.out.println("SOLVED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

// Καποιο Node ολοκλήρωσε ενα job με επιτυχία!
// Στειλε το αποτέλεσμα στον Stratum Server
fMyCluster.setCurrentStratumJob(null, false);
}

break;

case "PONG":
if (CheckIfClientIsAuthorized(sender))
{

}
break;
}
}
catch (Exception ex)
{

}
}

Expand All @@ -217,10 +221,10 @@ private boolean CheckIfClientIsAuthorized(TCPClientConnection client)
NodeTCPConnectionVariables var = (NodeTCPConnectionVariables) client.getTag();
return var.isClientAuthorized();
}

return false;
}

@Override
public void OnClientConnect(TCPClientConnection client)
{
Expand All @@ -232,7 +236,7 @@ public void OnClientConnect(TCPClientConnection client)
frmClusterControl.ACTIVE_INSTANCE.NodeConnected(client);
}
}

@Override
public void OnClientDisconnect(TCPClientConnection client)
{
Expand All @@ -247,7 +251,7 @@ public void OnClientDisconnect(TCPClientConnection client)
}
}
}

public void InformClientsToCleanJobs()
{
synchronized (fClientsConnectOrDisconnectLock)
Expand All @@ -256,14 +260,14 @@ public void InformClientsToCleanJobs()
{
try
{
client.SendData("CLEAN_JOBS" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
client.SendData("CLEAN_JOBS" + ClusterCommunicationCommons.fMessageSplitter);
}
catch (ClientIsDisconnectedException | OutgoingPacketFailedException ex)
{
}
});
}

}

/**
Expand All @@ -277,21 +281,21 @@ private void PingClients()
{
try
{
con.SendData("PING" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
con.SendData("PING" + ClusterCommunicationCommons.fMessageSplitter);
}
catch (ClientIsDisconnectedException | OutgoingPacketFailedException ex)
{

}
});
}
}

public HashMap<String, TCPClientConnection> getConnectedClients()
{
return fConnectedClients;
}

public void ClearRangesFromClients()
{
synchronized (fClientsConnectOrDisconnectLock)
Expand All @@ -304,10 +308,10 @@ public void ClearRangesFromClients()
}
catch (Exception ex)
{

}
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package rabbitminer.ClusterNode.Client;

import Extasys.DataFrame;
import Extasys.Encryption.Base64Encryptor;
import Extasys.ManualResetEvent;
import Extasys.Network.TCP.Client.Connectors.TCPConnector;
import java.net.InetAddress;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void OnDataReceive(TCPConnector connector, DataFrame data)
case "PING":
// Server sents PING.
// Answer with PONG.
connector.SendData("PONG" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
connector.SendData("PONG" + ClusterCommunicationCommons.fMessageSplitter);
break;

}
Expand All @@ -151,7 +152,7 @@ public void OnConnect(TCPConnector connector)
fMyClusterNode.setStatus("Requesting access to Cluster...");
String loginStr = "LOGIN" + ClusterCommunicationCommons.fMessageSplitter;
loginStr += fMyClusterNode.getClusterPassword() + ClusterCommunicationCommons.fMessageSplitter;
loginStr += String.valueOf(Computer.getComputerCPUCoresCount()) + ClusterCommunicationCommons.fETX;
loginStr += String.valueOf(Computer.getComputerCPUCoresCount());
try
{
SendData(loginStr);
Expand Down Expand Up @@ -191,13 +192,14 @@ private void StartAutoReconnect()
InetAddress serverIP = ACTIVE_INSTANCE.fMyClusterNode.getClusterIP();
int serverPort = ACTIVE_INSTANCE.fMyClusterNode.getClusterPort();
int readBufferSize = 10240;
String messageSplitter = ClusterCommunicationCommons.fETX;

// Remove the old TCPConnector
ClusterClient.ACTIVE_INSTANCE.RemoveConnector("");

// Add new connector
ClusterClient.ACTIVE_INSTANCE.AddConnector("", serverIP, serverPort, readBufferSize, messageSplitter);
TCPConnector conn = ClusterClient.ACTIVE_INSTANCE.AddConnector("", serverIP, serverPort, readBufferSize, ClusterCommunicationCommons.fETX);
conn.setAutoApplyMessageSplitterState(true);
conn.setConnectionEncryptor(new Base64Encryptor());

fMyClusterNode.setStatus("Trying to connect to server...");
try
Expand Down
2 changes: 1 addition & 1 deletion RabbitMiner/src/rabbitminer/ClusterNode/ClusterNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void AskServerForJobAndWaitForReply()
{
fAskServerForJobAndWaitForReplyEvent.Reset();

fClusterClient.SendData("GET_JOB" + ClusterCommunicationCommons.fMessageSplitter + ClusterCommunicationCommons.fETX);
fClusterClient.SendData("GET_JOB" + ClusterCommunicationCommons.fMessageSplitter);
try
{
fAskServerForJobAndWaitForReplyEvent.WaitOne(5000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public boolean MeetsTarget(final int nonce, final int threadNo)

String reply = "JOB_SOLVED_RANDOMX" + ClusterCommunicationCommons.fMessageSplitter;
reply += randomXJob.toJSON() + ClusterCommunicationCommons.fMessageSplitter;
reply += ClusterCommunicationCommons.fETX;


try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void JobSolved(final int nonce, final String extranonce2)
reply += extranonce2 + ClusterCommunicationCommons.fMessageSplitter;
reply += nTime + ClusterCommunicationCommons.fMessageSplitter;
reply += DecToHex.decToHex(nonce);
reply += ClusterCommunicationCommons.fETX;


try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class SettingsManager
{

private static final String fAppVersion = "1.0.7";
private static final String fAppVersion = "1.0.8";
public static final String fClusterSettingsFileExtension = "rbmcs";
private static final String fSettingsFileName = "RabbitMiner.conf";

Expand Down

0 comments on commit 77af0e5

Please sign in to comment.