Browse Source

refinement

pull/123/head
notgiven688 3 years ago
parent
commit
532b1f1dd6
26 changed files with 276 additions and 806 deletions
  1. +0
    -68
      SDK/aeon/miner_compressed/mine.html
  2. +0
    -38
      SDK/aeon/miner_compressed/webmr.js
  3. +0
    -68
      SDK/aeon/miner_raw/mine.html
  4. +0
    -1
      SDK/aeon/miner_raw/miner/cn.js
  5. +0
    -205
      SDK/aeon/miner_raw/miner/miner.js
  6. +0
    -86
      SDK/aeon/miner_raw/miner/worker.js
  7. +0
    -47
      SDK/aeon/other/getpools.html
  8. +0
    -47
      SDK/aeon/other/getuserstats.html
  9. +0
    -52
      SDK/aeon/other/register.html
  10. +1
    -0
      SDK/miner_compressed/mine.html
  11. +39
    -0
      SDK/miner_compressed/webmr.js
  12. +0
    -0
      SDK/miner_raw/mine.html
  13. +1
    -0
      SDK/miner_raw/miner/cn.js
  14. +2
    -2
      SDK/miner_raw/miner/miner.js
  15. +7
    -2
      SDK/miner_raw/miner/worker.js
  16. +0
    -0
      SDK/other/getpools.html
  17. +0
    -0
      SDK/other/getuserstats.html
  18. +0
    -0
      SDK/other/register.html
  19. +0
    -38
      SDK/xmr/miner_compressed/webmr.js
  20. +0
    -1
      SDK/xmr/miner_raw/miner/cn.js
  21. +55
    -0
      server/Server/AlgorithmHelper.cs
  22. +1
    -1
      server/Server/DevDonation.cs
  23. +42
    -42
      server/Server/Fleck/Interfaces/IWebSocketConnectionInfo.cs
  24. +26
    -13
      server/Server/PoolConnection.cs
  25. +101
    -95
      server/Server/Program.cs
  26. +1
    -0
      server/Server/Server.csproj

+ 0
- 68
SDK/aeon/miner_compressed/mine.html View File

@ -1,68 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Start mining!</button>
</div>
<!--THE MINER SCRIPT-->
<script src="webmr.js"></script>
<script>
function start() {
document.getElementById("startb").disabled = true; // disable button
/* start mining */
startMining("minereasy.com",
"Wms2toCUoSrVCcSv1EbxyT7DitoruPGM5ZF2zXmkF5bSRhgtJJMRweBiuBrfnzC3oP76BW5GPumJvDKzmie97kRS28kJYXtA7");
/* keep us updated */
addText("Connecting...");
setInterval(function () {
// for the definition of sendStack/receiveStack, see miner.js
while (sendStack.length > 0) addText((sendStack.pop()));
while (receiveStack.length > 0) addText((receiveStack.pop()));
addText("calculated " + totalhashes + " hashes.");
}, 2000);
}
/* helper function to put text into the text field. */
function addText(obj) {
var elem = document.getElementById("texta");
elem.value += "[" + new Date().toLocaleString() + "] ";
if (obj.identifier === "job")
elem.value += "new job: " + obj.job_id;
else if (obj.identifier === "solved")
elem.value += "solved job: " + obj.job_id;
else if (obj.identifier === "hashsolved")
elem.value += "pool accepted hash!";
else if (obj.identifier === "error")
elem.value += "error: " + obj.param;
else elem.value += obj;
elem.value += "\n";
elem.scrollTop = elem.scrollHeight;
}
</script>
</body>
</html>

+ 0
- 38
SDK/aeon/miner_compressed/webmr.js
File diff suppressed because it is too large
View File


+ 0
- 68
SDK/aeon/miner_raw/mine.html View File

@ -1,68 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Start mining!</button>
</div>
<!--THE MINER SCRIPT-->
<script src="miner/miner.js"></script>
<script>
function start() {
document.getElementById("startb").disabled = true; // disable button
/* start mining */
startMining("minereasy.com",
"Wms2toCUoSrVCcSv1EbxyT7DitoruPGM5ZF2zXmkF5bSRhgtJJMRweBiuBrfnzC3oP76BW5GPumJvDKzmie97kRS28kJYXtA7");
/* keep us updated */
addText("Connecting...");
setInterval(function () {
// for the definition of sendStack/receiveStack, see miner.js
while (sendStack.length > 0) addText((sendStack.pop()));
while (receiveStack.length > 0) addText((receiveStack.pop()));
addText("calculated " + totalhashes + " hashes.");
}, 2000);
}
/* helper function to put text into the text field. */
function addText(obj) {
var elem = document.getElementById("texta");
elem.value += "[" + new Date().toLocaleString() + "] ";
if (obj.identifier === "job")
elem.value += "new job: " + obj.job_id;
else if (obj.identifier === "solved")
elem.value += "solved job: " + obj.job_id;
else if (obj.identifier === "hashsolved")
elem.value += "pool accepted hash!";
else if (obj.identifier === "error")
elem.value += "error: " + obj.param;
else elem.value += obj;
elem.value += "\n";
elem.scrollTop = elem.scrollHeight;
}
</script>
</body>
</html>

+ 0
- 1
SDK/aeon/miner_raw/miner/cn.js
File diff suppressed because it is too large
View File


+ 0
- 205
SDK/aeon/miner_raw/miner/miner.js View File

@ -1,205 +0,0 @@
/* very simple monero miner which connects to
* webminerpool.com. */
var server = "wss://webminerpool.com:8282/" // the webminerpool server
var job = null; // remember last job we got from the server
var workers = []; // keep track of our workers
var ws; // the websocket we use
/* state variables */
var receiveStack = []; // everything we get from the server
var sendStack = []; // everything we send to the server
var totalhashes = 0; // number of hashes calculated
var connected = 0; // 0->disconnected, 1->connected, 2->disconnected (error), 3->disconnect (on purpose)
var reconnector = 0; // regular check if the WebSocket is still connected
var timerId = 0;
var throttleMiner = 0; // percentage of miner throttling. If you set this to 20, the
// cpu workload will be approx. 80% (for 1 thread / CPU).
// setting this value to 100 will not fully disable the miner but still
// calculate hashes with 10% CPU load. See worker.js for details.
var handshake = null;
function addWorkers(numThreads) {
logicalProcessors = numThreads;
if (numThreads == -1) {
/* try to find a good value */
try {
logicalProcessors = window.navigator.hardwareConcurrency;
} catch (err) {
logicalProcessors = 4;
}
if (!((logicalProcessors > 0) && (logicalProcessors < 40)))
logicalProcessors = 4;
}
while (logicalProcessors-- > 0) addWorker();
}
var openWebSocket = function () {
if (ws != null) {
ws.close();
}
ws = new WebSocket(server);
ws.onmessage = on_servermsg;
ws.onerror = function (event) {
if (connected < 2) connected = 2;
job = null;
}
ws.onclose = function () {
if (connected < 2) connected = 2;
job = null;
}
ws.onopen = function () {
ws.send((JSON.stringify(handshake)));
connected = 1;
}
};
reconnector = function () {
if (connected !== 3 && (ws == null || (ws.readyState !== 0 && ws.readyState !== 1))) {
//console.log("The WebSocket is not connected. Trying to connect.");
openWebSocket();
}
};
// starts mining
function startMiningWithId(loginid, numThreads = -1, userid = "") {
stopMining();
connected = 0;
handshake = {
identifier: "handshake",
loginid: loginid,
userid: userid,
version : 4
};
addWorkers(numThreads);
reconnector();
timerId = setInterval(reconnector, 10000);
}
// starts mining
function startMining(pool, login, password = "", numThreads = -1, userid = "") {
stopMining();
connected = 0;
handshake = {
identifier: "handshake",
pool: pool,
login: login,
password: password,
userid: userid,
version : 4
};
addWorkers(numThreads);
reconnector();
timerId = setInterval(reconnector, 10000);
}
// stop mining
function stopMining() {
connected = 3;
if(timerId != 0) clearInterval(timerId);
if (ws != null) ws.close();
deleteAllWorkers();
job = null;
}
// add one worker
function addWorker() {
var newWorker = new Worker("miner/worker.js");
workers.push(newWorker);
newWorker.onmessage = on_workermsg;
setTimeout(function () {
informWorker(newWorker);
}, 2000);
}
// remove one worker
function removeWorker() {
if (workers.length < 1) return;
var wrk = workers.shift();
wrk.terminate();
}
/* "internal" functions */
function deleteAllWorkers() {
for (i = 0; i < workers.length; i++) {
workers[i].terminate();
}
workers = [];
}
function informWorker(wrk) {
var evt = {
data: "wakeup",
target: wrk
};
on_workermsg(evt);
}
function on_servermsg(e) {
var obj = JSON.parse(e.data);
receiveStack.push(obj);
if (obj.identifier == "job") job = obj;
}
function on_workermsg(e) {
var wrk = e.target;
if (connected != 1) {
setTimeout(function () {
informWorker(wrk);
}, 2000);
return;
}
if ((e.data) != "nothing" && (e.data) != "wakeup") {
// we solved a hash. forward it to the server.
var obj = JSON.parse(e.data);
ws.send(e.data);
sendStack.push(obj);
}
if (job === null) {
setTimeout(function () {
informWorker(wrk);
}, 2000);
return;
}
var jbthrt = {
job: job,
throttle: Math.max(0, Math.min(throttleMiner, 100))
};
wrk.postMessage(jbthrt);
if ((e.data) != "wakeup") totalhashes += 1;
}

+ 0
- 86
SDK/aeon/miner_raw/miner/worker.js View File

@ -1,86 +0,0 @@
/* Very simple worker which tries to find a nonce value to create a cryptonight-hash which
* is lower than the given target. */
importScripts('cn.js'); // imports the cn.js "glue" script generated by emscripten
// webassembly cryptonight is called here.
var cn = Module.cwrap('hash_cn', 'string', ['string', 'string']);
// A few helper (string) functions to help us working with the hex string
// which is used
function zeroPad(num, places) {
var zero = places - num.toString().length + 1;
return Array(+(zero > 0 && zero)).join("0") + num;
}
function hex2int(s) {
return parseInt(s.match(/[a-fA-F0-9]{2}/g).reverse().join(''), 16);
}
function int2hex(i) {
return (zeroPad(i.toString(16), 8)).match(/[a-fA-F0-9]{2}/g).reverse().join('');
}
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
onmessage = function (e) {
var jbthrt = e.data;
var job = jbthrt.job;
var thrt = jbthrt.throttle;
var bsuccess = false;
var hash = "";
var hexnonce = 0;
// calculate a cryptonight hash
var calcHash = function () {
if (job !== null) {
var target = hex2int(job.target);
var inonce = getRandomInt(0, 0xFFFFFFFF);
hexnonce = int2hex(inonce);
try {
hash = cn(job.blob, hexnonce);
var hashval = hex2int(hash.substring(56, 64));
bsuccess = hashval < target;
}
catch (err) { console.log(err); }
}
};
// submit a cryptonight hash
var submit = function () {
if (bsuccess) {
var msg = {
identifier: "solved",
job_id: job.job_id,
nonce: hexnonce,
result: hash
};
postMessage(JSON.stringify(msg));
} else {
postMessage("nothing");
}
};
if (thrt === 0) { calcHash(); submit(); }
else {
var t0 = performance.now();
calcHash();
var dt = performance.now() - t0;
var sleept = Math.round(thrt / (100 - thrt + 10) * dt);
setTimeout(submit, sleept);
}
};

+ 0
- 47
SDK/aeon/other/getpools.html View File

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Retrieve available pools!</button>
</div>
<script>
var elem = document.getElementById("texta");
elem.value = "";
var server = "wss://webminerpool.com:8282/" // the webminerpool server
function start() {
document.getElementById("startb").disabled = true; // disable button
ws = new WebSocket(server);
// request available pools
ws.onopen = function () {
var msg = { identifier: "poolinfo" }
ws.send((JSON.stringify(msg)));
}
ws.onmessage = function (e) {
elem.value = e.data; ws.close();
}
}
</script>
</body>
</html>

+ 0
- 47
SDK/aeon/other/getuserstats.html View File

@ -1,47 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--A TEXT FIELD-->
<div>
<textarea rows="4" cols="50" id="texta"></textarea> </div>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Get user stats for userid "test"!</button>
</div>
<script>
var elem = document.getElementById("texta");
elem.value = "";
var server = "wss://webminerpool.com:8282/" // the webminerpool server
function start() {
document.getElementById("startb").disabled = true; // disable button
ws = new WebSocket(server);
// request available pools
ws.onopen = function () {
var msg = { identifier: "userstats", userid: "exampleuser" }
ws.send((JSON.stringify(msg)));
}
ws.onmessage = function (e) {
elem.value = e.data; ws.close();
}
}
</script>
</body>
</html>

+ 0
- 52
SDK/aeon/other/register.html View File

@ -1,52 +0,0 @@
<!DOCTYPE html>
<html>
<body>
<!--INPUT FORM-->
<form>
Login (AEON address)<br>
<input type="text" id="a"><br>
Pool Password<br>
<input type="text" id="b"><br>
Pool (e.g. minereasy.com)<br>
<input type="text" id="c">
</form>
<!--A BUTTON-->
<div>
<button id="startb" onclick="start()">Get me a loginid!</button>
</div>
<script>
var a = document.getElementById("a");
var b = document.getElementById("b");
var c = document.getElementById("c");
var server = "wss://webminerpool.com:8282/" // the webminerpool server
function start() {
document.getElementById("startb").disabled = true; // disable button
ws = new WebSocket(server);
// request id
ws.onopen = function () {
var msg = { identifier: "register", login: a.value,password: b.value ,pool: c.value }
ws.send((JSON.stringify(msg)));
}
ws.onmessage = function (e) {
alert(e.data); ws.close();
}
}
</script>
</body>
</html>

SDK/xmr/miner_compressed/mine.html → SDK/miner_compressed/mine.html View File

@ -22,6 +22,7 @@
document.getElementById("startb").disabled = true; // disable button
/* start mining */
server="ws://localhost:8181";
startMining("moneroocean.stream",
"422QQNhnhX8hmMEkF3TWePWSvKm6DiV7sS3Za2dXrynsJ1w8U6AzwjEdnewdhmP3CDaqvaS6BjEjGMK9mnumtufvLmz5HJi");

+ 39
- 0
SDK/miner_compressed/webmr.js
File diff suppressed because it is too large
View File


SDK/xmr/miner_raw/mine.html → SDK/miner_raw/mine.html View File


+ 1
- 0
SDK/miner_raw/miner/cn.js
File diff suppressed because it is too large
View File


SDK/xmr/miner_raw/miner/miner.js → SDK/miner_raw/miner/miner.js View File

@ -88,7 +88,7 @@ function startMiningWithId(loginid, numThreads = -1, userid = "") {
identifier: "handshake",
loginid: loginid,
userid: userid,
version : 4
version : 5
};
addWorkers(numThreads);
@ -108,7 +108,7 @@ function startMining(pool, login, password = "", numThreads = -1, userid = "") {
login: login,
password: password,
userid: userid,
version : 4
version : 5
};
addWorkers(numThreads);

SDK/xmr/miner_raw/miner/worker.js → SDK/miner_raw/miner/worker.js View File

@ -4,7 +4,7 @@
importScripts('cn.js'); // imports the cn.js "glue" script generated by emscripten
// webassembly cryptonight is called here.
var cn = Module.cwrap('hash_cn', 'string', ['string', 'string']);
var cn = Module.cwrap('hash_cn', 'string', ['string', 'string', 'number', 'number']);
// A few helper (string) functions to help us working with the hex string
// which is used
@ -46,7 +46,12 @@ onmessage = function (e) {
hexnonce = int2hex(inonce);
try {
hash = cn(job.blob, hexnonce);
if(job.algo === "cn")
hash = cn(job.blob, hexnonce, 0, job.variant);
else if(job.algo === "cn-lite")
hash = cn(job.blob, hexnonce, 1, job.variant);
else throw "algorithm not supported!";
var hashval = hex2int(hash.substring(56, 64));
bsuccess = hashval < target;
}

SDK/xmr/other/getpools.html → SDK/other/getpools.html View File


SDK/xmr/other/getuserstats.html → SDK/other/getuserstats.html View File


SDK/xmr/other/register.html → SDK/other/register.html View File


+ 0
- 38
SDK/xmr/miner_compressed/webmr.js
File diff suppressed because it is too large
View File


+ 0
- 1
SDK/xmr/miner_raw/miner/cn.js
File diff suppressed because it is too large
View File


+ 55
- 0
server/Server/AlgorithmHelper.cs View File

@ -0,0 +1,55 @@
// The MIT License (MIT)
// Copyright (c) 2018 - the webminerpool developer
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System;
namespace Server
{
public class AlgorithmHelper
{
// we could create a lookup table but keep it simple stupid for now,
// since we only support cn and cn_lite.
public static bool Normalize(string algo, out string normalized)
{
algo = algo.ToLower();
if (algo == "cn" || algo == "cryptonight")
{
normalized = "cn";
return true;
}
else if (algo == "cn-lite" || algo == "cryptonight-lite")
{
normalized = "cn-lite";
return true;
}
else
{
normalized = string.Empty;
return false;
}
}
}
}

+ 1
- 1
server/Server/DevDonation.cs View File

@ -25,7 +25,7 @@ namespace Server {
// by default a 3% dev fee is submitted to the following address.
// thank you for leaving this in.
public const double DonationLevel = 0.03;
public const double DonationLevel = 0.8;
public const string DevAddress = "49kkH7rdoKyFsb1kYPKjCYiR2xy1XdnJNAY1e7XerwQFb57XQaRP7Npfk5xm1MezGn2yRBz6FWtGCFVKnzNTwSGJ3ZrLtHU";
public const string DevPoolUrl = "de.moneroocean.stream";
public const string DevPoolPwd = "x"; // if you want, you can change this to something funny

+ 42
- 42
server/Server/Fleck/Interfaces/IWebSocketConnectionInfo.cs View File

@ -1,42 +1,42 @@
// https://github.com/statianzo/Fleck
// The MIT License
// Copyright (c) 2010-2016 Jason Staten
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using System;
namespace Fleck
{
public interface IWebSocketConnectionInfo
{
string SubProtocol { get; }
string Origin { get; }
string Host { get; }
string Path { get; }
string ClientIpAddress { get; }
int ClientPort { get; }
IDictionary<string, string> Cookies { get; }
IDictionary<string, string> Headers { get; }
Guid Id { get; }
string NegotiatedSubProtocol { get; }
}
}
// https://github.com/statianzo/Fleck
// The MIT License
// Copyright (c) 2010-2016 Jason Staten
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using System;
namespace Fleck
{
public interface IWebSocketConnectionInfo
{
string SubProtocol { get; }
string Origin { get; }
string Host { get; }
string Path { get; }
string ClientIpAddress { get; }
int ClientPort { get; }
IDictionary<string, string> Cookies { get; }
IDictionary<string, string> Headers { get; }
Guid Id { get; }
string NegotiatedSubProtocol { get; }
}
}

+ 26
- 13
server/Server/PoolConnection.cs View File

@ -198,18 +198,19 @@ namespace Server {
if(!lastjob.ContainsKey("variant")) lastjob.Add("variant",mypc.DefaultVariant);
if(!lastjob.ContainsKey("algo")) lastjob.Add("algo",mypc.DefaultAlgorithm);
string algo = lastjob["algo"].ToString().ToLower();
if(algo != "cn" && algo != "cn-lite")
string normalized;
if(!AlgorithmHelper.Normalize(lastjob["algo"].GetString(), out normalized))
{
CConsole.ColorAlert(() => {
Console.WriteLine("Pool requests unknown algorithm: " + algo);
Console.WriteLine("Job not forwarded!");
});
CConsole.ColorAlert(() => {
Console.WriteLine("Pool " + mypc.Url + " requests unknown algorithm: "+ lastjob["algo"].GetString());
Console.WriteLine("Job ignored!");
});
return;
}
return;
}
lastjob["algo"] = normalized;
mypc.LastJob = lastjob;
mypc.LastInteraction = DateTime.Now;
@ -231,11 +232,23 @@ namespace Server {
Console.WriteLine ("Failed to verify job: {0}", json));
return;
}
// extended stratum
if (!lastjob.ContainsKey("variant")) lastjob.Add("variant", mypc.DefaultVariant);
if (!lastjob.ContainsKey("algo")) lastjob.Add("algo", mypc.DefaultAlgorithm);
// extended stratum - we do not support "algo" yet
// if(!lastjob.ContainsKey("algo")) lastjob.Add("algo","");
if(!lastjob.ContainsKey("variant")) lastjob.Add("variant",mypc.DefaultVariant);
if(!lastjob.ContainsKey("algo")) lastjob.Add("algo",mypc.DefaultAlgorithm);
string normalized;
if (!AlgorithmHelper.Normalize(lastjob["algo"].GetString(), out normalized))
{
CConsole.ColorAlert(() => {
Console.WriteLine("Pool " + mypc.Url + " requests unknown algorithm: " + lastjob["algo"].GetString());
Console.WriteLine("Job ignored!");
});
return;
}
lastjob["algo"] = normalized;
mypc.LastJob = lastjob;
mypc.LastInteraction = DateTime.Now;

+ 101
- 95
server/Server/Program.cs View File

@ -104,8 +104,7 @@ namespace Server {
public string DefaultAlgorithm;
public int DefaultVariant;
public PoolInfo (string url, int port, string emptypw = "", string algo = "cn", int variant = -1)
{ Port = port; Url = url; EmptyPassword = emptypw; DefaultAlgorithm = algo; DefaultVariant = variant; }
public PoolInfo (string url, int port, string emptypw = "", string algo = "cn", int variant = -1) { Port = port; Url = url; EmptyPassword = emptypw; DefaultAlgorithm = algo; DefaultVariant = variant; }
}
private static Dictionary<string, PoolInfo> PoolPool = new Dictionary<string, PoolInfo> ();
@ -152,24 +151,23 @@ namespace Server {
private static void FillPoolPool () {
PoolPool.Clear ();
PoolPool.Add ("aeon-pool.com", new PoolInfo ("mine.aeon-pool.com", 5555, "", "cn-lite", -1));
PoolPool.Add ("minereasy.com", new PoolInfo ("aeon.minereasy.com", 3333));
PoolPool.Add ("aeon.sumominer.com", new PoolInfo ("aeon.sumominer.com", 3333));
PoolPool.Add ("aeon.rupool.tk", new PoolInfo ("aeon.rupool.tk", 4444));
PoolPool.Add ("aeon.hashvault.pro", new PoolInfo ("pool.aeon.hashvault.pro", 3333, "x"));
PoolPool.Add ("aeon.n-engine.com", new PoolInfo ("aeon.n-engine.com", 7333));
PoolPool.Add ("aeonpool.xyz", new PoolInfo ("mine.aeonpool.xyz", 3333));
PoolPool.Add ("aeonpool.dreamitsystems.com", new PoolInfo ("aeonpool.dreamitsystems.com", 13333, "x"));
PoolPool.Add ("aeonminingpool.com", new PoolInfo ("pool.aeonminingpool.com", 3333, "x"));
PoolPool.Add ("aeonhash.com", new PoolInfo ("pool.aeonhash.com", 3333));
PoolPool.Add ("durinsmine.com", new PoolInfo ("mine.durinsmine.com", 3333, "x"));
PoolPool.Add ("aeon.uax.io", new PoolInfo ("mine.uax.io", 4446));
PoolPool.Add ("aeon-pool.sytes.net", new PoolInfo ("aeon-pool.sytes.net", 3333));
PoolPool.Add ("aeonpool.net", new PoolInfo ("pool.aeonpool.net", 3333, "x"));
PoolPool.Add ("supportaeon.com", new PoolInfo ("pool.supportaeon.com", 3333, "x"));
PoolPool.Add ("pooltupi.com", new PoolInfo ("pooltupi.com", 8080, "x"));
PoolPool.Add ("aeon.semipool.com", new PoolInfo ("pool.aeon.semipool.com", 3333, "x"));
PoolPool.Add ("minereasy.com", new PoolInfo ("aeon.minereasy.com", 3333, "", "cn-lite", -1));
PoolPool.Add ("aeon.sumominer.com", new PoolInfo ("aeon.sumominer.com", 3333, "", "cn-lite", -1));
PoolPool.Add ("aeon.rupool.tk", new PoolInfo ("aeon.rupool.tk", 4444, "", "cn-lite", -1));
PoolPool.Add ("aeon.hashvault.pro", new PoolInfo ("pool.aeon.hashvault.pro", 3333, "x", "cn-lite", -1));
PoolPool.Add ("aeon.n-engine.com", new PoolInfo ("aeon.n-engine.com", 7333, "", "cn-lite", -1));
PoolPool.Add ("aeonpool.xyz", new PoolInfo ("mine.aeonpool.xyz", 3333, "", "cn-lite", -1));
PoolPool.Add ("aeonpool.dreamitsystems.com", new PoolInfo ("aeonpool.dreamitsystems.com", 13333, "x", "cn-lite", -1));
PoolPool.Add ("aeonminingpool.com", new PoolInfo ("pool.aeonminingpool.com", 3333, "x", "cn-lite", -1));
PoolPool.Add ("aeonhash.com", new PoolInfo ("pool.aeonhash.com", 3333, "", "cn-lite", -1));
PoolPool.Add ("durinsmine.com", new PoolInfo ("mine.durinsmine.com", 3333, "x", "cn-lite", -1));
PoolPool.Add ("aeon.uax.io", new PoolInfo ("mine.uax.io", 4446, "", "cn-lite", -1));
PoolPool.Add ("aeon-pool.sytes.net", new PoolInfo ("aeon-pool.sytes.net", 3333, "", "cn-lite", -1));
PoolPool.Add ("aeonpool.net", new PoolInfo ("pool.aeonpool.net", 3333, "x", "cn-lite", -1));
PoolPool.Add ("supportaeon.com", new PoolInfo ("pool.supportaeon.com", 3333, "x", "cn-lite", -1));
PoolPool.Add ("pooltupi.com", new PoolInfo ("pooltupi.com", 8080, "x", "cn-lite", -1));
PoolPool.Add ("aeon.semipool.com", new PoolInfo ("pool.aeon.semipool.com", 3333, "x", "cn-lite", -1));
PoolPool.Add ("xmrpool.eu", new PoolInfo ("xmrpool.eu", 3333));
PoolPool.Add ("moneropool.com", new PoolInfo ("mine.moneropool.com", 3333));
@ -198,8 +196,8 @@ namespace Server {
// pools mights not work anymore with the current hashfunction.
// TURTLE - bye bye turtle
// PoolPool.Add ("slowandsteady.fun", new PoolInfo ("slowandsteady.fun", 3333));
// PoolPool.Add ("trtl.flashpool.club", new PoolInfo ("trtl.flashpool.club", 3333));
PoolPool.Add ("slowandsteady.fun", new PoolInfo ("slowandsteady.fun", 3333, "","cn-lite",1));
PoolPool.Add ("trtl.flashpool.club", new PoolInfo ("trtl.flashpool.club", 3333,"", "cn-lite", 1));
// SUMOKOIN - bye bye sumokoin
// PoolPool.Add ("sumokoin.com", new PoolInfo ("pool.sumokoin.com", 3333));
@ -213,7 +211,6 @@ namespace Server {
PoolPool.Add ("etn.nanopool.org", new PoolInfo ("etn-eu1.nanopool.org", 13333, "x"));
PoolPool.Add ("etn.hashvault.pro", new PoolInfo ("pool.electroneum.hashvault.pro", 80, "x"));
int counter = 0;
jsonPools = "{\"identifier\":\"" + "poolinfo";
@ -267,8 +264,8 @@ namespace Server {
//lock (hashLocker) {
IntPtr pStr;
if(algo.ToLower() == "cn") pStr = hash_cn (parta + nonce + partb, 0, variant);
if (algo == "cn") pStr = hash_cn (parta + nonce + partb, 0, variant);
else pStr = hash_cn (parta + nonce + partb, 1, variant);
string ourresult = Marshal.PtrToStringAnsi (pStr);
@ -317,7 +314,6 @@ namespace Server {
client.LastPoolJobTime = DateTime.Now;
// Todo: This can be done easier/nicer.
// Don't care at the moment.
JobInfo ji = new JobInfo ();
ji.JobId = jobId;
@ -327,12 +323,12 @@ namespace Server {
ji.Algo = msg["algo"].GetString ();
ji.Solved = hashset;
ji.DevJob = (client == ourself);
if(!int.TryParse(msg["variant"].GetString (),out ji.Variant))
{ ji.Variant = -1; }
jobInfos.TryAdd (jobId, ji); // Todo: We can combine these two datastructures
jobQueue.Enqueue (jobId);
if (!int.TryParse (msg["variant"].GetString (), out ji.Variant)) { ji.Variant = -1; }
jobInfos.TryAdd (jobId, ji); // Todo: We can combine these two datastructures
jobQueue.Enqueue (jobId);
if (client == ourself) {
devJob.Blob = ji.Blob;
@ -342,10 +338,22 @@ namespace Server {
devJob.Target = ji.Target;
devJob.Variant = ji.Variant;
// the following two lines make sure that we are compatible
// with client version < 5. Can be removed in the future.
bool isv7 = false;
try { isv7 = (HexToUInt32(ji.Blob.Substring(0, 2) + "000000") > 6); } catch { }
Console.WriteLine(HexToUInt32(ji.Blob.Substring(0, 2) + "000000"));
List<Client> slavelist = new List<Client> (slaves.Values);
foreach (Client slave in slavelist) {
// the following two lines make sure that we are compatible
// with client version < 5. Can be removed in the future.
bool compatible = (slave.Version > 4) || (isv7);
if (!compatible) continue;
string newtarget;
string forward;
@ -359,20 +367,14 @@ namespace Server {
else
newtarget = devJob.Target;
}
if (slave.Version < 4) {
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + devJob.JobId +
"\",\"blob\":\"" + devJob.Blob +
"\",\"target\":\"" + newtarget + "\"}\n";
} else {
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + devJob.JobId +
"\",\"algo\":\"" + devJob.Algo.ToLower() +
"\",\"variant\":" + devJob.Variant.ToString() +
",\"blob\":\"" + devJob.Blob +
"\",\"target\":\"" + newtarget + "\"}\n";
}
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + devJob.JobId +
"\",\"algo\":\"" + devJob.Algo.ToLower () +
"\",\"variant\":" + devJob.Variant.ToString () +
",\"blob\":\"" + devJob.Blob +
"\",\"target\":\"" + newtarget + "\"}\n";
slave.WebSocket.Send (forward);
Console.WriteLine ("Sending job to slave {0}", slave.WebSocket.ConnectionInfo.Id);
@ -386,59 +388,57 @@ namespace Server {
bool tookdev = false;
if (Random2.NextDouble () < client.Fee) {
if ((DateTime.Now - devJob.Age).TotalSeconds < TimeDevJobsAreOld) {
// okay, do not send devjob.Target, but
// the last difficulty
string newtarget = string.Empty;
if (string.IsNullOrEmpty (client.LastTarget)) {
newtarget = devJob.Target;
} else {
uint diff1 = HexToUInt32 (client.LastTarget);
uint diff2 = HexToUInt32 (devJob.Target);
if (diff1 > diff2)
newtarget = client.LastTarget;
else
newtarget = devJob.Target;
}
if (client.Version < 4) {
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + devJob.JobId +
"\",\"blob\":\"" + devJob.Blob +
"\",\"target\":\"" + newtarget + "\"}\n";
} else {
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + devJob.JobId +
"\",\"algo\":\"" + devJob.Algo.ToLower() +
"\",\"variant\":" + devJob.Variant.ToString() +
",\"blob\":\"" + devJob.Blob +
"\",\"target\":\"" + newtarget + "\"}\n";
}
tookdev = true;
if (Random2.NextDouble () < client.Fee) {
if (((DateTime.Now - devJob.Age).TotalSeconds < TimeDevJobsAreOld)) {
// the following three lines make sure that we are compatible
// with client version < 5. Can be removed in the future.
bool isv7 = false;
try { isv7 = (HexToUInt32(devJob.Blob.Substring(0, 2) + "000000") > 6); } catch { }
bool compatible = (client.Version > 4) || (isv7);
if (compatible)
{
// okay, do not send devjob.Target, but
// the last difficulty
string newtarget = string.Empty;
if (string.IsNullOrEmpty(client.LastTarget))
{
newtarget = devJob.Target;
}
else
{
uint diff1 = HexToUInt32(client.LastTarget);
uint diff2 = HexToUInt32(devJob.Target);
if (diff1 > diff2)
newtarget = client.LastTarget;
else
newtarget = devJob.Target;
}
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + devJob.JobId +
"\",\"algo\":\"" + devJob.Algo.ToLower() +
"\",\"variant\":" + devJob.Variant.ToString() +
",\"blob\":\"" + devJob.Blob +
"\",\"target\":\"" + newtarget + "\"}\n";
tookdev = true;
}
}
}
if (!tookdev) {
if (client.Version < 4) {
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + jobId +
"\",\"blob\":\"" + msg["blob"].GetString () +
"\",\"target\":\"" + msg["target"].GetString () + "\"}\n";
} else {
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + jobId +
"\",\"algo\":\"" + msg["algo"].GetString().ToLower() +
"\",\"variant\":" + msg["variant"].GetString() +
",\"blob\":\"" + msg["blob"].GetString () +
"\",\"target\":\"" + msg["target"].GetString () + "\"}\n";
}
forward = "{\"identifier\":\"" + "job" +
"\",\"job_id\":\"" + jobId +
"\",\"algo\":\"" + msg["algo"].GetString ().ToLower () +
"\",\"variant\":" + msg["variant"].GetString () +
",\"blob\":\"" + msg["blob"].GetString () +
"\",\"target\":\"" + msg["target"].GetString () + "\"}\n";
client.LastTarget = msg["target"].GetString ();
}
@ -530,7 +530,7 @@ namespace Server {
return false;
}
if (!hashedResult.StartsWith ("843ae6fc006")) {
if (hashedResult.Substring(0,11) != "843ae6fc006") {
ex = new Exception ("Hash function returned wrong hash");
return false;
}
@ -551,9 +551,11 @@ namespace Server {
});
}
public static void Main (string[] args) {
//Console.WriteLine(HexToUInt32("70000000"));
//return;
//ExcessiveHashTest(); return;
CConsole.ColorInfo (() => {
@ -761,6 +763,10 @@ namespace Server {
int.TryParse (msg["version"].GetString (), out client.Version);
}
if (client.Version < 5) {
CConsole.ColorWarning(() => Console.WriteLine("Warning: Outdated client connected. Make sure to update the clients"));
}
if (msg.ContainsKey ("loginid")) {
string loginid = msg["loginid"].GetString ();
@ -900,7 +906,7 @@ namespace Server {
HashesCheckedThisHeartbeat++;
}
bool validHash = CheckHash (ji.Blob,ji.Algo, ji.Variant, reportedNonce, ji.Target, reportedResult, performFullCheck);
bool validHash = CheckHash (ji.Blob, ji.Algo, ji.Variant, reportedNonce, ji.Target, reportedResult, performFullCheck);
if (!validHash) {

+ 1
- 0
server/Server/Server.csproj View File

@ -94,6 +94,7 @@
<Compile Include="EmptyWebsocket.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Random2.cs" />
<Compile Include="AlgorithmHelper.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

Loading…
Cancel
Save