Skip to content

Commit

Permalink
Merge branch 'refs/heads/mtrlt'
Browse files Browse the repository at this point in the history
Conflicts:
	.gitignore
	App.cpp
	CMakeLists.txt
	Curl.cpp
	Curl.h
	README.md
  • Loading branch information
p2k committed Nov 10, 2011
2 parents f391052 + 5466ea7 commit 8c2235e
Show file tree
Hide file tree
Showing 62 changed files with 8,195 additions and 1,024 deletions.
105 changes: 81 additions & 24 deletions App.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void SubmitShare(Curl& curl, vector<uchar>& w)
}
try
{
string ret = curl.SetWork(VectorToHexString(w));
string ret = curl.TestWork(VectorToHexString(w));
Json::Value root;
Json::Reader reader;
bool parse_success = reader.parse(ret, root);
Expand Down Expand Up @@ -211,12 +211,47 @@ void* LongPollThread(void* param)
curl.SetHost(parent_curl->GetHost());
curl.SetPort(parent_curl->GetPort());

string LP_url = Curl::longpoll_url;
string LP_path;
{//parsing LP address
vector<string> exploded = Explode(LP_url, '/');
if (exploded.size() >= 2 && exploded[0] == "http:")
{
vector<string> exploded2 = Explode(exploded[1], ':');
if (exploded2.size() != 2)
goto couldnt_parse;
cout << "LP Host: " << exploded2[0] << endl;
curl.SetHost(exploded2[0]);
cout << "LP Port: " << exploded2[1] << endl;
curl.SetPort(exploded2[1]);
if (exploded.size() <= 2)
LP_path = '/';
else
LP_path = "/" + exploded[2];
cout << "LP Path: " << LP_path << endl;
}
else if (LP_url.length() > 0 && LP_url[0] == '/')
{
LP_path = LP_url;
cout << "LP Path: " << LP_path << endl;
}
else
{
goto couldnt_parse;
}
}

while(!shutdown_now)
{
p->app->Parse(curl.GetWork(Curl::longpoll_url, 60, false));
p->app->Parse(curl.GetWork_LP(LP_path, 60));
}
pthread_exit(NULL);
return NULL;

couldnt_parse:
cout << "Couldn't parse long polling URL [" << LP_url << "]. turning LP off." << endl;
pthread_exit(NULL);
return NULL;
}

bool shutdown_now=false;
Expand All @@ -240,24 +275,36 @@ using std::stringstream;

void App::Main(vector<string> args)
{
cout << "\\||||||||||||||||||||||||||||||||||||||/" << endl;
cout << "- Reaper " << REAPER_VERSION << " " << REAPER_PLATFORM << ", coded by mtrlt -" << endl;
cout << "- Donations are welcome! Thanks! -" << endl;
cout << "- sPuLn5UqBWMBdZF4JVx9GGfFiX55rpKQwR -" << endl;
cout << "/||||||||||||||||||||||||||||||||||||||\\" << endl;
cout << "\\|||||||||||||||||||||/" << endl;
cout << "- Reaper " << REAPER_VERSION << " " << REAPER_PLATFORM << " -" << endl;
cout << "- coded by mtrlt -" << endl;
cout << "/|||||||||||||||||||||\\" << endl;
cout << endl;
if (args.size() < 5)
string config_name = "reaper.conf";
bool old_args = false;
if (args.size() < 5) // new arg format
{
cout << "Syntax: " << args[0] << " host port user pass [config_filename]" << endl;
return;
if (args.size() >= 2)
config_name = args[1];
}
string config_name = "reaper.conf";
if (args.size() >= 6)
else //old arg format
{
config_name = args[5];
if (args.size() >= 6)
{
config_name = args[5];
}
old_args = true;
}
getworks = 0;
config.Load(config_name);
if (!old_args)
{
if (config.GetValue<string>("host") == "" ||
config.GetValue<string>("port") == "" ||
config.GetValue<string>("user") == "" ||
config.GetValue<string>("pass") == "")
throw string("The config is missing one of host/port/user/pass.");
}
globalconfs.local_worksize = config.GetValue<uint>("worksize");
{
if (config.GetValue<string>("aggression") == "max")
Expand Down Expand Up @@ -289,6 +336,7 @@ void App::Main(vector<string> args)
#endif
if (globalconfs.cputhreads == 0 && globalconfs.threads_per_gpu == 0)
{
throw string("No CPU or GPU mining threads.. please set either cpu_mining_threads or threads_per_gpu to something other than 0.");
}
globalconfs.platform = config.GetValue<uint>("platform");

Expand All @@ -303,10 +351,21 @@ void App::Main(vector<string> args)

Curl::GlobalInit();
curl.Init();
curl.SetHost(args[1]);
curl.SetPort(args[2]);
curl.SetUsername(args[3]);
curl.SetPassword(args[4]);
if (old_args)
{
curl.SetHost(args[1]);
curl.SetPort(args[2]);
curl.SetUsername(args[3]);
curl.SetPassword(args[4]);
}
else
{
curl.SetHost(config.GetValue<string>("host"));
curl.SetPort(config.GetValue<string>("port"));
curl.SetUsername(config.GetValue<string>("user"));
curl.SetPassword(config.GetValue<string>("pass"));
}
curl.proxy = config.GetValue<string>("proxy");

pthread_t sharethread;
pthread_create(&sharethread, NULL, ShareThread, &curl);
Expand All @@ -316,20 +375,18 @@ void App::Main(vector<string> args)

Parse(curl.GetWork());

int work_update_period_ms = 2000;

#ifdef LONGPOLLING
const int work_update_period_ms = 20000;

pthread_t longpollthread;
LongPollThreadParams lp_params;
if (Curl::longpoll_active)
if (config.GetValue<bool>("long_polling") && Curl::longpoll_active)
{
cout << "Activating long polling." << endl;
work_update_period_ms = 20000;
lp_params.app = this;
lp_params.curl = &curl;
pthread_create(&longpollthread, NULL, LongPollThread, &lp_params);
}
#endif

if (config.GetValue<bool>("enable_graceful_shutdown"))
{
Expand Down Expand Up @@ -422,7 +479,7 @@ void App::Parse(string data)
workupdate = ticker();
if (data == "")
{
cout << humantime() << "Couldn't connect to pool. Trying again in a few seconds... " << endl;
cout << humantime() << "Couldn't connect to server. Trying again in a few seconds... " << endl;
return;
}
Json::Value root, result, error;
Expand Down Expand Up @@ -477,6 +534,6 @@ void App::Parse(string data)
cout << humantime() << "Code " << error["code"].asInt() << ", \"" << error["message"].asString() << "\"" << endl;
}
got_error:
cout << humantime() << "Error with pool: " << data << endl;
cout << humantime() << "Error with server: " << data << endl;
return;
}
Empty file modified App.h
100644 → 100755
Empty file.
17 changes: 9 additions & 8 deletions AppOpenCL.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,22 @@ void* Reap_GPU(void* param)

Work tempwork;

uchar tempdata[512];
memset(tempdata, 0, 512);
uchar tempdata[1024];
memset(tempdata, 0, 1024);

clEnqueueWriteBuffer(state->commandQueue, state->CLbuffer[0], true, 0, KERNEL_INPUT_SIZE, tempdata, 0, NULL, NULL);
clEnqueueWriteBuffer(state->commandQueue, state->CLbuffer[1], true, 0, KERNEL_OUTPUT_SIZE*sizeof(uint), tempdata, 0, NULL, NULL);
clEnqueueWriteBuffer(state->commandQueue, state->padbuffer32, true, 0, 1024*1024*4*sizeof(uint), BlockHash_1_MemoryPAD32, 0, NULL, NULL);

uint kernel_output[KERNEL_OUTPUT_SIZE] = {};

bool write_kernel_output = true;
bool write_kernel_input = true;

size_t base = 0;

clSetKernelArg(state->kernel, 2, sizeof(cl_mem), &state->padbuffer32);

bool errorfree = true;

deque<uint> runtimes;

while(!shutdown_now)
{
if (globalconfs.max_aggression && !runtimes.empty())
Expand Down Expand Up @@ -403,7 +399,7 @@ void OpenCL::Init()

if (filebinary == NULL)
{
cout << "Compiling kernel.." << endl;
cout << "Compiling kernel... this could take up to 2 minutes." << endl;
GPUstate.program = clCreateProgramWithSource(clState.context, 1, (const char **)&see, &sourcesizes[0], &status);
if(status != CL_SUCCESS)
throw string("Error creating OpenCL program from source");
Expand Down Expand Up @@ -478,15 +474,20 @@ void OpenCL::Init()
cout << "Kernel build not successful: " << status << endl;
throw string("Error creating OpenCL kernel");
}
cl_mem padbuffer32 = clCreateBuffer(clState.context, CL_MEM_READ_ONLY, 1024*1024*4*sizeof(uint), NULL, &status);
for(uint thread_id = 0; thread_id < globalconfs.threads_per_gpu; ++thread_id)
{
GPUstate.commandQueue = clCreateCommandQueue(clState.context, devices[device_id], 0, &status);
if (thread_id == 0)
{
clEnqueueWriteBuffer(GPUstate.commandQueue, padbuffer32, true, 0, 1024*1024*4*sizeof(uint), BlockHash_1_MemoryPAD32, 0, NULL, NULL);
}
if(status != CL_SUCCESS)
throw string("Error creating OpenCL command queue");

GPUstate.CLbuffer[0] = clCreateBuffer(clState.context, CL_MEM_READ_ONLY, KERNEL_INPUT_SIZE, NULL, &status);
GPUstate.CLbuffer[1] = clCreateBuffer(clState.context, CL_MEM_WRITE_ONLY, KERNEL_OUTPUT_SIZE*sizeof(uint), NULL, &status);
GPUstate.padbuffer32 = clCreateBuffer(clState.context, CL_MEM_READ_ONLY, 1024*1024*4*sizeof(uint), NULL, &status);
GPUstate.padbuffer32 = padbuffer32;

if(status != CL_SUCCESS)
{
Expand Down
Empty file modified AppOpenCL.h
100644 → 100755
Empty file.
7 changes: 4 additions & 3 deletions Blake512.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "Global.h"
#include <cstring>
#include <cstdio>
#include <cstdint>

#include <iostream>
using std::cout;
Expand Down
2 changes: 1 addition & 1 deletion Blake512.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef BLAKE512_H
#define BLAKE512_H

#include <stdint.h>
#include <cstdint>
void blake512_hash(uint8_t *out, const uint8_t *in);

#endif
8 changes: 8 additions & 0 deletions CMakeConf.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CMAKECONF_H
#define CMAKECONF_H

#define REAPER_VERSION "@REAPER_VERSION@"
#cmakedefine CPU_MINING_ONLY
#cmakedefine LONGPOLLING

#endif
63 changes: 49 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,101 @@ project(reaper)

## Version ##

set(REAPER_VERSION "v10")
set(REAPER_VERSION "v11")

## Options ##

option(CPU_MINING_ONLY "Do not compile the GPU mining part" OFF)
option(LONGPOLLING "Enable experimental long polling support" OFF)

if(LONGPOLLING)
add_definitions(-DLONGPOLLING)
endif(LONGPOLLING)

## Global config ##

configure_file(
"${PROJECT_SOURCE_DIR}/Global.h.in"
"${PROJECT_BINARY_DIR}/Global.h"
"${PROJECT_SOURCE_DIR}/CMakeConf.h.in"
"${PROJECT_BINARY_DIR}/CMakeConf.h"
)

## Source files ##

set(SOURCES
App.cpp
AppOpenCL.cpp
Blake512.cpp
CPUMiner.cpp
Config.cpp
Curl.cpp
json_reader.cpp
json_value.cpp
json_writer.cpp
main.cpp
AppOpenCL.cpp
RSHash.cpp
ServerSettings.cpp
SHA256.cpp
Util.cpp
CPUMiner.cpp
)

set(HEADERS
App.h
AppOpenCL.h
Blake512.h
CPUMiner.h
Config.h
Curl.h
Global.h
RSHash.h
ServerSettings.h
SHA256.h
Util.h
)

## Targets ##

add_executable(reaper ${SOURCES})
add_executable(reaper ${SOURCES} ${HEADERS})

include_directories(${PROJECT_BINARY_DIR})

set_target_properties(reaper PROPERTIES COMPILE_FLAGS -O2)

## Hack. Windows needs path_suffix x86 or x86_64
## We supply it through LIB_SUBDIRECTORY_NAME
## But if we compile on non-Windows and it is not defined,
## bad things might happen, so we must define it here

if(NOT LIB_SUBDIRECTORY_NAME)
set(LIB_SUBDIRECTORY_NAME ".")
endif(NOT LIB_SUBDIRECTORY_NAME)

## OpenCL detection ##
if(NOT CPU_MINING_ONLY)

find_library(OPENCL_LIBRARY OpenCL)
find_library(OPENCL_LIBRARY OpenCL PATH_SUFFIXES ${LIB_SUBDIRECTORY_NAME})

find_path(OPENCL_INCLUDE_DIR NAMES cl.h PATH_SUFFIXES CL)

mark_as_advanced(OPENCL_INCLUDE_DIR OPENCL_LIBRARY)

include_directories(${OPENCL_INCLUDE_DIR})
include_directories(${OPENCL_INCLUDE_DIR}/..)

endif(NOT CPU_MINING_ONLY)

## Detection of the rest of the libs ##

find_library(PTHREAD_LIBRARY pthread PATH_SUFFIXES ${LIB_SUBDIRECTORY_NAME})
find_path(PTHREAD_INCLUDE_DIR NAMES pthread.h)
include_directories(${PTHREAD_INCLUDE_DIR})
link_directories(${PTHREAD_LIBRARY})

find_library(CURL_LIBRARY libcurl PATH_SUFFIXES ${LIB_SUBDIRECTORY_NAME})
find_path(CURL_INCLUDE_DIR NAMES curl.h PATH_SUFFIXES curl)
include_directories(${CURL_INCLUDE_DIR})
include_directories(${CURL_INCLUDE_DIR}/..)
link_directories(${CURL_LIBRARY})

## Library configuration ##

if(CPU_MINING_ONLY)
add_definitions(-DCPU_MINING_ONLY)
target_link_libraries(reaper pthread curl)
target_link_libraries(reaper ${PTHREAD_LIBRARY} ${CURL_LIBRARY})
else(CPU_MINING_ONLY)
target_link_libraries(reaper pthread curl ${OPENCL_LIBRARY})
target_link_libraries(reaper ${PTHREAD_LIBRARY} ${CURL_LIBRARY} ${OPENCL_LIBRARY})
endif(CPU_MINING_ONLY)
Loading

0 comments on commit 8c2235e

Please sign in to comment.