Skip to content

Commit 9b4b048

Browse files
committed
Support Cookie Authentication.
Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
1 parent d885b7e commit 9b4b048

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

Client.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class NetworkedClient : public Client {
7272
class GBTClient : public NetworkedClient {
7373
// Options
7474
const std::vector<std::string> _rules;
75-
const std::string _host, _url, _credentials;
75+
const std::string _host, _url, _cookie;
76+
std::string _credentials;
7677
const std::vector<uint8_t> _scriptPubKey;
7778
// Client State Variables
7879
CURL *_curl;
@@ -103,6 +104,7 @@ class GBTClient : public NetworkedClient {
103104
_rules(options.rules),
104105
_host(options.host),
105106
_url("http://" + options.host + ":" + std::to_string(options.port) + "/"),
107+
_cookie(options.cookie),
106108
_credentials(options.username + ":" + options.password),
107109
_scriptPubKey(bech32ToScriptPubKey(options.payoutAddress)),
108110
_curl(curl_easy_init()) {}

GBTClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ bool GBTClient::_fetchJob() {
204204

205205
void GBTClient::connect() {
206206
if (!_connected) {
207+
if (_cookie != "") {
208+
std::ifstream file(_cookie, std::ios::in);
209+
if (!file) {
210+
logger.log("Could not open Cookie '"s + _cookie + "'!\n"s
211+
"Check that the Server is running, that the Cookie does exist at this path, and that this instance of rieMiner can read it.\n"s, MessageType::ERROR);
212+
return;
213+
}
214+
std::getline(file, _credentials);
215+
}
207216
_currentJobTemplate = JobTemplate();
208217
_pendingBlocks = {};
209218
process();

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ rieMiner proposes the following Modes depending on what you want to do. Use the
203203
* `Port`: port of the Riecoin server (same as rpcport in riecoin.conf for solo mining). Default: 28332 (default RPC port for Riecoin Core);
204204
* `Username`: username used to connect to the server (same as rpcuser in riecoin.conf for solo mining). Default: empty;
205205
* `Password`: password used to connect to the server (same as rpcpassword in riecoin.conf for solo mining). Default: empty;
206+
* `Cookie`: for solo mining, cookie file containing the credentials, overriding `Username` and `Password`. Default: empty/none;
206207
* `PayoutAddress`: payout address for solo mining. You can use Bech32 "ric1" addresses (only lowercase). Default: a donation address;
207208
* `Rules`: for solo mining, add consensus rules in the GetBlockTemplate RPC call, each separated by a comma. `segwit` must be present. You should not touch this unless a major Riecoin upgrade is upcoming and it is said to use this option. Default: segwit.
208209

main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ bool Configuration::parse(const int argc, char** argv, std::string &parsingMessa
107107
}
108108
else if (key == "Username") _options.username = value;
109109
else if (key == "Password") _options.password = value;
110+
else if (key == "Cookie") _options.cookie = value;
110111
else if (key == "PayoutAddress") _options.payoutAddress = value;
111112
else if (key == "Threads") {
112113
try {_options.stellaConfig.threads = std::stoi(value);}
@@ -342,8 +343,12 @@ int main(int argc, char** argv) {
342343
else
343344
logger.log("Pooled mining"s);
344345
logger.log(" via host "s + configuration.options().host + ", port "s + std::to_string(configuration.options().port) + "\n"s);
345-
logger.log("Username: "s + configuration.options().username + "\n"s);
346-
logger.log("Password: <"s + std::to_string(configuration.options().password.size()) + " character(s)>\n"s);
346+
if (configuration.options().mode == "Solo" && configuration.options().cookie != "")
347+
logger.log("Cookie: "s + configuration.options().cookie + "\n"s);
348+
else {
349+
logger.log("Username: "s + configuration.options().username + "\n"s);
350+
logger.log("Password: <"s + std::to_string(configuration.options().password.size()) + " character(s)>\n"s);
351+
}
347352
if (configuration.options().mode == "Solo") {
348353
std::vector<uint8_t> scriptPubKey(bech32ToScriptPubKey(configuration.options().payoutAddress));
349354
logger.log("Payout address: "s + configuration.options().payoutAddress + "\n"s);

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{""}, mode{"Benchmark"}, payoutAddress{"ric1pstellap55ue6keg3ta2qwlxr0h58g66fd7y4ea78hzkj3r4lstrsk4clvn"}, tuplesFile{"Tuples.txt"};
41+
std::string host{"127.0.0.1"}, 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)