Sync changes with proxy.

This commit is contained in:
XMRig 2018-04-25 14:48:32 +07:00
parent b9fec2fcc4
commit ca149d2eed
22 changed files with 436 additions and 328 deletions

View file

@ -0,0 +1,158 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "common/crypto/Algorithm.h"
#ifdef _MSC_VER
# define strncasecmp _strnicmp
# define strcasecmp _stricmp
#endif
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#endif
struct AlgoData
{
const char *name;
const char *shortName;
xmrig::Algo algo;
xmrig::Variant variant;
};
static AlgoData const algorithms[] = {
{ "cryptonight", "cn", xmrig::CRYPTONIGHT, xmrig::VARIANT_AUTO },
{ "cryptonight/0", "cn/0", xmrig::CRYPTONIGHT, xmrig::VARIANT_0 },
{ "cryptonight/1", "cn/1", xmrig::CRYPTONIGHT, xmrig::VARIANT_1 },
{ "cryptonight/xtl", "cn/xtl", xmrig::CRYPTONIGHT, xmrig::VARIANT_XTL },
# ifndef XMRIG_NO_AEON
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
{ "cryptonight-lite/0", "cn-lite/0", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_0 },
{ "cryptonight-lite/1", "cn-lite/1", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_1 },
{ "cryptonight-lite/ipbc", "cn-lite/ipbc", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_IBPC },
# endif
# ifndef XMRIG_NO_SUMO
{ "cryptonight-heavy", "cn-heavy", xmrig::CRYPTONIGHT_HEAVY, xmrig::VARIANT_0 },
# endif
};
static const char *variants[] = {
"0",
"1",
"ipbc",
"xtl"
};
const char *xmrig::Algorithm::variantName() const
{
if (m_variant == VARIANT_AUTO) {
return "auto";
}
return variants[m_variant];
}
void xmrig::Algorithm::parseAlgorithm(const char *algo)
{
m_algo = INVALID_ALGO;
m_variant = VARIANT_AUTO;
for (size_t i = 0; i < ARRAY_SIZE(algorithms); i++) {
if ((strcasecmp(algo, algorithms[i].name) == 0) || (strcasecmp(algo, algorithms[i].shortName) == 0)) {
m_algo = algorithms[i].algo;
m_variant = algorithms[i].variant;
break;
}
}
if (m_algo == INVALID_ALGO) {
assert(false);
}
}
void xmrig::Algorithm::parseVariant(const char *variant)
{
if (m_algo == CRYPTONIGHT_HEAVY) {
return;
}
m_variant = VARIANT_AUTO;
for (size_t i = 0; i < ARRAY_SIZE(variants); i++) {
if (strcasecmp(variant, variants[i]) == 0) {
m_variant = static_cast<Variant>(i);
break;
}
}
}
void xmrig::Algorithm::parseVariant(int variant)
{
if (variant >= VARIANT_AUTO && variant <= VARIANT_XTL) {
m_variant = static_cast<Variant>(variant);
}
else {
assert(false);
}
}
void xmrig::Algorithm::setAlgo(Algo algo)
{
m_algo = algo;
if (m_algo == CRYPTONIGHT_HEAVY) {
m_variant = VARIANT_0;
}
}
const char *xmrig::Algorithm::name(bool shortName) const
{
for (size_t i = 0; i < ARRAY_SIZE(algorithms); i++) {
if (algorithms[i].algo == m_algo && algorithms[i].variant == m_variant) {
return shortName ? algorithms[i].shortName : algorithms[i].name;
}
}
return "invalid";
}