Skip to content

Commit bee2ac9

Browse files
committed
Support Proxy Connections.
Requested Feature, though I don't use Proxies myself so untested... But I don't see why it would not work... Also remove Http Prefix for GetBlockTemplate so something else could be used... Omitting it will fallback to Http so it should not affect existing Configuration Files. Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
1 parent dde8dad commit bee2ac9

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

Client.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class NetworkedClient : public Client {
7272
class GBTClient : public NetworkedClient {
7373
// Options
7474
const std::vector<std::string> _rules;
75-
const std::string _host, _url, _cookie;
75+
const std::string _host, _url, _proxy, _cookie;
7676
std::string _credentials;
7777
const std::vector<uint8_t> _scriptPubKey;
7878
// Client State Variables
@@ -103,7 +103,8 @@ class GBTClient : public NetworkedClient {
103103
GBTClient(const Options &options) :
104104
_rules(options.rules),
105105
_host(options.host),
106-
_url("http://" + options.host + ":" + std::to_string(options.port) + "/"),
106+
_url(options.host + ":" + std::to_string(options.port)),
107+
_proxy(options.proxy),
107108
_cookie(options.cookie),
108109
_credentials(options.username + ":" + options.password),
109110
_scriptPubKey(bech32ToScriptPubKey(options.payoutAddress)),
@@ -121,7 +122,7 @@ class GBTClient : public NetworkedClient {
121122
// Client for the Stratum protocol (pooled mining), working for the current Riecoin pools
122123
class StratumClient : public NetworkedClient {
123124
// Options
124-
const std::string _username, _password, _host;
125+
const std::string _username, _password, _host, _proxy;
125126
const uint16_t _port;
126127
// Client State Variables
127128
CURL *_curl;
@@ -152,7 +153,7 @@ class StratumClient : public NetworkedClient {
152153

153154
void _processMessage(const std::string&); // Processes a message received from the pool
154155
public:
155-
StratumClient(const Options &options) : _username(options.username), _password(options.password), _host(options.host), _port(options.port), _curl(curl_easy_init()) {}
156+
StratumClient(const Options &options) : _username(options.username), _password(options.password), _host(options.host), _proxy(options.proxy), _port(options.port), _curl(curl_easy_init()) {}
156157
void connect(); // Also sends mining.subscribe
157158
void process(); // Get messages from the server and calls _processMessage to handle them
158159
std::optional<ClientInfo> info() const;

GBTClient.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ nlohmann::json GBTClient::_sendRequestToWallet(const std::string &method, const
118118
const nlohmann::json request{{"jsonrpc", "2.0"}, {"method", method}, {"params", params}, {"id", id++}};
119119
const std::string requestStr(request.dump());
120120
curl_easy_setopt(_curl, CURLOPT_URL, _url.c_str());
121+
if (_proxy != "")
122+
curl_easy_setopt(_curl, CURLOPT_PROXY, _proxy.c_str());
121123
curl_easy_setopt(_curl, CURLOPT_POSTFIELDSIZE, requestStr.size());
122124
curl_easy_setopt(_curl, CURLOPT_POSTFIELDS, requestStr.c_str());
123125
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ rieMiner proposes the following Modes depending on what you want to do. Use the
199199

200200
### Solo and Pooled Mining options
201201

202-
* `Host`: IP of the Riecoin server. Default: 127.0.0.1 (your computer);
202+
* `Host`: URL of the Riecoin server. Default: 127.0.0.1 (your computer);
203203
* `Port`: port of the Riecoin server (same as rpcport in riecoin.conf for solo mining). Default: 28332 (default RPC port for Riecoin Core);
204+
* `Proxy`: URL of a Proxy (can be suffixed by the port, example `socks5://example.com:1080` - see [Curl Documentation](https://curl.se/libcurl/c/CURLOPT_PROXY.html)), optional. Default: none;
204205
* `Username`: username used to connect to the server (same as rpcuser in riecoin.conf for solo mining). Default: empty;
205206
* `Password`: password used to connect to the server (same as rpcpassword in riecoin.conf for solo mining). Default: empty;
206207
* `Cookie`: for solo mining, cookie file containing the credentials, overriding `Username` and `Password`. Default: empty/none;

StratumClient.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ void StratumClient::connect() {
248248
return;
249249
}
250250
curl_easy_setopt(_curl, CURLOPT_URL, (_host + ":" + std::to_string(_port) + "/").c_str());
251+
if (_proxy != "")
252+
curl_easy_setopt(_curl, CURLOPT_PROXY, _proxy.c_str());
251253
curl_easy_setopt(_curl, CURLOPT_CONNECT_ONLY, 1L);
252254
CURLcode cc(curl_easy_perform(_curl));
253255
if (cc != CURLE_OK) {

main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ bool Configuration::parse(const int argc, char** argv, std::string &parsingMessa
105105
try {_options.port = std::stoi(value);}
106106
catch (...) {_options.port = 28332;}
107107
}
108+
else if (key == "Proxy") _options.proxy = value;
108109
else if (key == "Username") _options.username = value;
109110
else if (key == "Password") _options.password = value;
110111
else if (key == "Cookie") _options.cookie = value;
@@ -343,6 +344,8 @@ int main(int argc, char** argv) {
343344
else
344345
logger.log("Pooled mining"s);
345346
logger.log(" via host "s + configuration.options().host + ", port "s + std::to_string(configuration.options().port) + "\n"s);
347+
if (configuration.options().proxy != "")
348+
logger.log("Using Proxy: "s + configuration.options().proxy + "\n"s);
346349
if (configuration.options().mode == "Solo" && configuration.options().cookie != "")
347350
logger.log("Cookie: "s + configuration.options().cookie + "\n"s);
348351
else {

main.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern std::string confPath;
3838
struct Options {
3939
Stella::Configuration stellaConfig;
4040
uint16_t tupleLengthMin{0U};
41-
std::string host{"127.0.0.1"}, username{""}, password{""}, cookie{""}, mode{"Benchmark"}, payoutAddress{"ric1pstellap55ue6keg3ta2qwlxr0h58g66fd7y4ea78hzkj3r4lstrsk4clvn"}, tuplesFile{"Tuples.txt"};
41+
std::string host{"127.0.0.1"}, proxy{""}, username{""}, password{""}, cookie{""}, mode{"Benchmark"}, payoutAddress{"ric1pstellap55ue6keg3ta2qwlxr0h58g66fd7y4ea78hzkj3r4lstrsk4clvn"}, tuplesFile{"Tuples.txt"};
4242
uint64_t filePrimeTableLimit{0ULL};
4343
uint16_t port{28332U};
4444
double refreshInterval{30.}, difficulty{1024.}, benchmarkBlockInterval{150.}, benchmarkTimeLimit{960.};

0 commit comments

Comments
 (0)