Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: algorithm plugins #80

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
add minimal example for algorithm
Olaf Leidinger committed May 26, 2014
commit f3657c405abd4f8a219e1ba01d7ee96069d11fdb
5 changes: 5 additions & 0 deletions algorithms/example/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
noinst_LIBRARIES= libexample.a


libexample_a_SOURCES = plugin.c

67 changes: 67 additions & 0 deletions algorithms/example/plugin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <string.h>

#include "miner.h"

typedef struct {
int N;
double x;
} example_param_t;

static example_param_t default_param;

int init_EXAMPLE() {
default_param.N = 1023;
default_param.x = 12.1;

return 0; // 0 == success
}

void* thread_init_EXAMPLE(int* error, void *extra_param) {
example_param_t *p = (example_param_t*) extra_param;

void *buff = malloc((size_t)p->N * 1234);
*error = (buff == NULL);
return buff;
}


int scanhash_EXAMPLE(int thr_id, uint32_t *pdata,
unsigned char *scratchbuf, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done, void *extra_param) {

example_param_t *p = (example_param_t*) extra_param;

// c.f. scrypt or sha256d code for usage of other parameters
return 0;
}

void *param_default_EXAMPLE() {
return (void*) &default_param;
}

void *param_parse_EXAMPLE(const char *str, int *error) {
static example_param_t p;
const char *delim = ",";
char *pch = strtok (str, delim);
int i = 0;

while( pch ) {
switch(i) {
case 0:
p.N = strtol(pch, NULL, 10);
applog(LOG_INFO, "example: Setting parameter N to %i", p.N);
break;
case 1:
p.x = strtod(pch, NULL);
applog(LOG_INFO, "example: Setting parameter x to %f", p.x);
break;
default:
applog(LOG_ERR, "Too many parameters specified to example algorithm: %s", str);
*error = 1;
return NULL;
}
i++;
pch = strtok (NULL, delim);
}
return (void*) &p;
}
18 changes: 18 additions & 0 deletions algorithms/example/plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef EXAMPLE_PLUGIN_H
#define EXAMPLE_PLUGIN_H

#define PLUGIN_NAME_EXAMPLE "example"
#define PLUGIN_DESC_EXAMPLE "example(N, x), default: N=1024, x=12.1"

int init_EXAMPLE();
void* thread_init_EXAMPLE(int* error, void *extra_param);

int scanhash_EXAMPLE(int thr_id, uint32_t *pdata,
void *thread_local_data, const uint32_t *ptarget,
uint32_t max_nonce, unsigned long *hashes_done, void* extra_param);

void *param_default_EXAMPLE();

void *param_parse_EXAMPLE( const char *str, int *error);

#endif // EXAMPLE_PLUGIN_H