Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit e6f23dc

Browse files
committedNov 22, 2018
Allow passing "." as username or workername using %2e.
As we split username and workername by "." we have to do it before an urlDecode() is called as otherwise it is not clear which part is username and which is workername. Previous this commit: -P username%2e246891.rigname%2e01:x@HOST:PORT Username = username, Workername = 246891.rigname.01 -P username%2erigname:x@HOST:PORT Username = username, Workername = rigname With this commit -P username%2e246891.rigname%2e01:x@HOST:PORT Username = username.246891, Workername = rigname.01 -P username%2erigname:x@HOST:PORT Username = username.rigname, Workername = But: this commit breaks a syntax of username%2erigname:x@HOST:PORT as now this results in a Username = username.rigname against previous Username = username, Workername = rigname Thinking nobody used such a syntax. This commit should fix #1687 #1075
1 parent 16e2144 commit e6f23dc

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed
 

‎libpoolprotocols/PoolURI.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,24 @@ URI::URI(const std::string uri)
156156
tmpstr++;
157157
len = tmpstr - curstr;
158158
m_username.append(curstr, len);
159+
160+
// Expect we got a uri "username%2e246891.rigname%2e01:x@eu-01.miningrigrentals.com:3344"
161+
// which should mean: username = "username.246891"
162+
// workername = "rigname.01"
163+
// we must split username and workername before urlDecode() is called !
164+
auto p = m_username.find_first_of(".");
165+
if (p != std::string::npos)
166+
{
167+
// There should be at least one char after dot
168+
// returned p is zero based
169+
if (p < (m_username.length() - 1))
170+
m_workername = m_username.substr(p+1);
171+
172+
m_username = m_username.substr(0, p);
173+
}
159174
m_username = urlDecode(m_username);
175+
m_workername = urlDecode(m_workername);
176+
160177
// Look for password
161178
curstr = tmpstr;
162179
if (':' == *curstr)

‎libpoolprotocols/PoolURI.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class URI
5858
unsigned short Port() const { return m_port; }
5959
std::string User() const { return m_username; }
6060
std::string Pass() const { return m_password; }
61+
std::string Workername() const { return m_workername; }
6162
SecureLevel SecLevel() const;
6263
ProtocolFamily Family() const;
6364
UriHostNameType HostNameType() const;
@@ -88,6 +89,7 @@ class URI
8889
std::string m_fragment;
8990
std::string m_username;
9091
std::string m_password;
92+
std::string m_workername;
9193
std::string m_uri;
9294
unsigned short m_stratumMode = 999; // Initial value 999 means not tested yet
9395
unsigned short m_port = 0;

‎libpoolprotocols/stratum/EthStratumClient.cpp

+5-19
Original file line numberDiff line numberDiff line change
@@ -611,23 +611,9 @@ void EthStratumClient::connect_handler(const boost::system::error_code& ec)
611611
m_sendBuffer.consume(4096);
612612
clear_response_pleas();
613613

614-
// Extract user and worker
615-
size_t p;
616-
m_worker.clear();
617-
p = m_conn->User().find_first_of(".");
618-
if (p != string::npos)
619-
{
620-
m_user = m_conn->User().substr(0, p);
621-
622-
// There should be at least one char after dot
623-
// returned p is zero based
624-
if (p < (m_conn->User().length() - 1))
625-
m_worker = m_conn->User().substr(++p);
626-
}
627-
else
628-
{
629-
m_user = m_conn->User();
630-
}
614+
// user and worker
615+
m_user = m_conn->User();
616+
m_worker = m_conn->Workername();
631617

632618
/*
633619
@@ -1430,7 +1416,7 @@ void EthStratumClient::onRecvSocketDataCompleted(
14301416

14311417
if (!ec && bytes_transferred > 0)
14321418
{
1433-
1419+
14341420
// DO NOT DO THIS !!!!!
14351421
// std::istream is(&m_recvBuffer);
14361422
// std::string message;
@@ -1511,7 +1497,7 @@ void EthStratumClient::onRecvSocketDataCompleted(
15111497
}
15121498
}
15131499

1514-
void EthStratumClient::send(Json::Value const& jReq)
1500+
void EthStratumClient::send(Json::Value const& jReq)
15151501
{
15161502
std::string* line = new std::string(Json::writeString(m_jSwBuilder, jReq));
15171503
m_txQueue.push(line);

0 commit comments

Comments
 (0)
This repository has been archived.