Skip to content

Commit

Permalink
initial commit v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tevador committed Feb 8, 2020
0 parents commit 19e3239
Show file tree
Hide file tree
Showing 22 changed files with 5,136 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bin/
obj/
*.user
*.suo
.vs
x64/
Release/
Debug/
build/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "RandomX"]
path = RandomX
url = https://github.com/tevador/RandomX
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2020, tevador <tevador@gmail.com>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

cmake_minimum_required(VERSION 2.8.7)

project(randomx-service)

add_subdirectory("RandomX")

if(NOT Threads_FOUND AND UNIX AND NOT APPLE)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
endif()

add_executable(${PROJECT_NAME}
src/main.cpp
src/service.cpp
src/service_worker.cpp
src/thread_pool.cpp)

set_property(TARGET randomx-service PROPERTY CXX_STANDARD 11)

target_link_libraries(${PROJECT_NAME}
PRIVATE randomx
PRIVATE ${CMAKE_THREAD_LIBS_INIT})
51 changes: 51 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Copyright (c) 2020, tevador <tevador@gmail.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
HTTPLIB is licensed under the MIT license:

Copyright (c) 2019 Yuji Hirose.
Copyright (c) 2020 tevador <tevador@gmail.com>

All rights reserved.

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.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# RandomX Service

RandomX Service provides a simple HTTP API to calculate [RandomX](https://github.com/tevador/RandomX) proof of work (PoW).

## Use cases

* Fast PoW verification for Node.js based pools
* Web-mining with explicit user consent (see below)
* Access to RandomX for clients who cannot link directly to librandomx

## Building

### Linux
Prerequisites: cmake, make, gcc
```
git clone --recursive https://github.com/tevador/randomx-service
cd randomx-service
./build.sh
```

### Windows
Prerequisites: cmake, Visual Studio
```
git clone --recursive https://github.com/tevador/randomx-service
cd randomx-service
build.cmd
```

## Usage

```
Usage: ./randomx-service [OPTIONS]
Supported options:
-host <string> Bind to a specific address (default: localhost)
-port <number> Bind to a specific port (default: 39093)
-threads <number> Use a specific number of threads (default: all CPU threads)
-flags <number> Use specific RandomX flags (default: auto)
-origin <string> Allow cross-origin requests from a specific web page
-log Log all HTTP requests to stdout
-help Display this message
```

## RandomX Service API

The service provides the following API methods:

* `GET /info`
* `POST /seed`
* `POST /hash`
* `POST /batch`

Refer to [doc/API.md](doc/API.md).

## Web-mining

To allow requests from the browser, use the `-origin` command line option. For example, to allow the site https://example.com to access the service, this command line option should be used:

```
./randomx-service -origin https://example.com
```

### Notes
* using the `/batch` API, web-miners are able to reach similar performance as native miners
* HTTP requests to localhost from HTTP websites are currently blocked by [Firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=1488740) and [Safari](https://bugs.webkit.org/show_bug.cgi?id=171934), but this behavior may change in the future (refer to the linked bugtrackers).

## Donations

XMR:
```
845xHUh5GvfHwc2R8DVJCE7BT2sd4YEcmjG8GNSdmeNsP5DTEjXd1CNgxTcjHjiFuthRHAoVEJjM7GyKzQKLJtbd56xbh7V
```
1 change: 1 addition & 0 deletions RandomX
Submodule RandomX added at ac574e
31 changes: 31 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@echo off

set BUILD_DIR=build

set MSBUILD="c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
if not exist %MSBUILD% set MSBUILD="c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
if not exist %MSBUILD% set MSBUILD="c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
if not exist %MSBUILD% set MSBUILD="c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Current\Bin\MSBuild.exe"
if not exist %MSBUILD% set MSBUILD="c:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Current\Bin\MSBuild.exe"
if not exist %MSBUILD% set MSBUILD="C:\Program Files (x86)\MSBuild\14.0\Bin\MsBuild.exe"
if not exist %MSBUILD% goto msbuild_not_found

if not exist %BUILD_DIR% mkdir %BUILD_DIR%

cd %BUILD_DIR%

cmake ..
if errorlevel 1 goto end

%MSBUILD% /nologo /fl /restore /p:Configuration=Release randomx-service.sln
if errorlevel 1 goto end

echo.
Release\randomx-service.exe -help
goto end

:msbuild_not_found
echo ERROR: MSBuild not found

:end
pause
25 changes: 25 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

BUILD=build

if [[ ! -d "$BUILD" ]]
then
mkdir "$BUILD"
fi

cd "$BUILD"
cmake ..

if [ $? -ne 0 ]
then
exit 1
fi

make

if [ $? -ne 0 ]
then
exit 1
fi

./randomx-service -help
Loading

0 comments on commit 19e3239

Please sign in to comment.