Browse Source

config: introduce set_nfactor() and use it to call set_algorithm_nfactor().

Had two bugs:

1. Will not compile due to unknown algorithm_t size.
2. nfactor is set to 0 (bad calling, fix later).

So squashed two commits:

1. algorithm: move algorithm_t definition to header.
2. config: if --nfactor is specified, properly set algorithm->nfactor.
build-mingw
Noel Maersk 11 years ago
parent
commit
a0c52bf67c
  1. 5
      algorithm.c
  2. 5
      algorithm.h
  3. 18
      sgminer.c

5
algorithm.c

@ -12,11 +12,6 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
typedef struct algorithm_t {
char name[20]; /* Human-readable identifier */
uint8_t nfactor; /* N factor (CPU/Memory tradeoff parameter) */
} algorithm_t;
void set_algorithm(algorithm_t* algo, const char* newname) { void set_algorithm(algorithm_t* algo, const char* newname) {
strncpy(algo->name, newname, sizeof(algo->name)); strncpy(algo->name, newname, sizeof(algo->name));
algo->name[sizeof(algo->name) - 1] = '\0'; algo->name[sizeof(algo->name) - 1] = '\0';

5
algorithm.h

@ -6,7 +6,10 @@
/* Describes the Scrypt parameters and hashing functions used to mine /* Describes the Scrypt parameters and hashing functions used to mine
* a specific coin. * a specific coin.
*/ */
typedef struct algorithm_t algorithm_t; typedef struct _algorithm_t {
char name[20]; /* Human-readable identifier */
uint8_t nfactor; /* N factor (CPU/Memory tradeoff parameter) */
} algorithm_t;
/* Set default parameters based on name. */ /* Set default parameters based on name. */
void set_algorithm(algorithm_t* algo, const char* name); void set_algorithm(algorithm_t* algo, const char* name);

18
sgminer.c

@ -1018,6 +1018,12 @@ static char *set_algo(const char *arg)
return NULL; return NULL;
} }
static char *set_nfactor(const char *arg)
{
set_algorithm_nfactor(algorithm, (uint8_t)atoi(arg));
return NULL;
}
static char *set_api_allow(const char *arg) static char *set_api_allow(const char *arg)
{ {
opt_set_charp(arg, &opt_api_allow); opt_set_charp(arg, &opt_api_allow);
@ -1069,7 +1075,7 @@ static char *set_null(const char __maybe_unused *arg)
static struct opt_table opt_config_table[] = { static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--algorithm", OPT_WITH_ARG("--algorithm",
set_algo, NULL, NULL, set_algo, NULL, NULL,
"Set mining algorithm to most common defaults, default: static"), "Set mining algorithm and most common defaults, default: static"),
OPT_WITH_ARG("--api-allow", OPT_WITH_ARG("--api-allow",
set_api_allow, NULL, NULL, set_api_allow, NULL, NULL,
"Allow API access only to the given list of [G:]IP[/Prefix] addresses[/subnets]"), "Allow API access only to the given list of [G:]IP[/Prefix] addresses[/subnets]"),
@ -1122,9 +1128,6 @@ static struct opt_table opt_config_table[] = {
opt_set_bool, &opt_compact, opt_set_bool, &opt_compact,
"Use compact display without per device statistics"), "Use compact display without per device statistics"),
#endif #endif
OPT_WITH_ARG("--nfactor",
set_int_0_to_9999, opt_show_intval, &opt_nfactor,
"Set scrypt N-factor parameter, default: 10. Currently use 11 for vertcoin!"),
OPT_WITHOUT_ARG("--debug|-D", OPT_WITHOUT_ARG("--debug|-D",
enable_debug, &opt_debug, enable_debug, &opt_debug,
"Enable debug output"), "Enable debug output"),
@ -1228,6 +1231,9 @@ static struct opt_table opt_config_table[] = {
OPT_WITHOUT_ARG("--net-delay", OPT_WITHOUT_ARG("--net-delay",
opt_set_bool, &opt_delaynet, opt_set_bool, &opt_delaynet,
"Impose small delays in networking to not overload slow routers"), "Impose small delays in networking to not overload slow routers"),
OPT_WITH_ARG("--nfactor",
set_nfactor, NULL, NULL,
"Override default scrypt N-factor parameter."),
#ifdef HAVE_ADL #ifdef HAVE_ADL
OPT_WITHOUT_ARG("--no-adl", OPT_WITHOUT_ARG("--no-adl",
opt_set_bool, &opt_noadl, opt_set_bool, &opt_noadl,
@ -7764,7 +7770,7 @@ int main(int argc, char *argv[])
int i, j; int i, j;
char *s; char *s;
/* This dangerous functions tramples random dynamically allocated /* This dangerous function tramples random dynamically allocated
* variables so do it before anything at all */ * variables so do it before anything at all */
if (unlikely(curl_global_init(CURL_GLOBAL_ALL))) if (unlikely(curl_global_init(CURL_GLOBAL_ALL)))
quit(1, "Failed to curl_global_init"); quit(1, "Failed to curl_global_init");
@ -7842,6 +7848,8 @@ int main(int argc, char *argv[])
strcat(sgminer_path, "\\"); strcat(sgminer_path, "\\");
#endif #endif
algorithm = (algorithm_t *)alloca(sizeof(algorithm_t));
devcursor = 8; devcursor = 8;
logstart = devcursor + 1; logstart = devcursor + 1;
logcursor = logstart + 1; logcursor = logstart + 1;

Loading…
Cancel
Save