Skip to content

Commit 1f1deb2

Browse files
committed
P2PoolManager: add proxy support
1 parent 8df248d commit 1f1deb2

4 files changed

Lines changed: 57 additions & 6 deletions

File tree

pages/Mining.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ Rectangle {
309309
confirmationDialog.cancelText = qsTr("No") + translationManager.emptyString;
310310
confirmationDialog.okText = qsTr("Yes") + translationManager.emptyString;
311311
confirmationDialog.onAcceptedCallback = function() {
312+
p2poolManager.proxyAddress = persistentSettings.getProxyAddress();
312313
p2poolManager.download();
313314
statusMessageText.text = "Downloading P2Pool...";
314315
statusMessage.visible = true
@@ -652,6 +653,7 @@ allArgs = allArgs.filter( ( el ) => !defaultArgs.includes( el.split(" ")[0] ) )
652653
chain = "nano"
653654
}
654655
var p2poolArgs = persistentSettings.p2poolFlags;
656+
p2poolManager.proxyAddress = persistentSettings.getProxyAddress();
655657
var success = p2poolManager.start(p2poolArgs, address, chain, threads);
656658
if (success)
657659
{

pages/settings/SettingsLayout.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Rectangle {
275275
}
276276
text: qsTr("Socks5 proxy (%1%2)")
277277
.arg(appWindow.walletMode >= 2 ? qsTr("remote node connections, ") : "")
278-
.arg(qsTr("updates downloading, fetching price sources")) + translationManager.emptyString
278+
.arg(qsTr("updates downloading, fetching price sources, P2Pool")) + translationManager.emptyString
279279
}
280280

281281
MoneroComponents.RemoteNodeEdit {

src/p2pool/P2PoolManager.cpp

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828

2929
#include "P2PoolManager.h"
30-
#include "net/http_client.h"
30+
#include "net/http.h"
3131
#include "common/util.h"
3232
#include "main/oshelper.h"
3333
#include "qt/utils.h"
@@ -72,11 +72,23 @@ void P2PoolManager::download() {
7272
validHash = "a358489a4b1a6addfcc86ff235a0ce50210899f5e3a6dc93ce0eb69e0d181564";
7373
#endif
7474
QFile file(fileName);
75-
epee::net_utils::http::http_simple_client http_client;
75+
net::http::client http_client;
76+
QString proxyAddress;
77+
{
78+
QMutexLocker locker(&m_proxyMutex);
79+
proxyAddress = m_proxyAddress;
80+
}
81+
82+
if (!proxyAddress.isEmpty() && !http_client.set_proxy(proxyAddress.toStdString())) {
83+
qCritical() << "Failed to set p2pool download proxy address" << proxyAddress;
84+
emit p2poolDownloadFailure(ConnectionIssue);
85+
return;
86+
}
87+
7688
const epee::net_utils::http::http_response_info* response = NULL;
7789
std::string userAgent = randomUserAgent().toStdString();
7890
std::chrono::milliseconds timeout = std::chrono::seconds(10);
79-
http_client.set_server(url.host().toStdString(), "443", {});
91+
http_client.set_server(url.host().toStdString(), "443", {}, epee::net_utils::ssl_options_t{epee::net_utils::ssl_support_t::e_ssl_support_enabled});
8092
bool success = http_client.invoke_get(url.path().toStdString(), timeout, {}, std::addressof(response), {{"User-Agent", userAgent}});
8193
if (success && response->m_response_code == 404) {
8294
emit p2poolDownloadFailure(BinaryNotAvailable);
@@ -86,9 +98,12 @@ void P2PoolManager::download() {
8698
for (std::pair<std::string, std::string> i : fields) {
8799
if (i.first == "Location") {
88100
url = QString::fromStdString(i.second);
89-
http_client.set_server(url.host().toStdString(), "443", {});
101+
http_client.set_server(url.host().toStdString(), "443", {}, epee::net_utils::ssl_options_t{epee::net_utils::ssl_support_t::e_ssl_support_enabled});
90102
std::string query = url.query(QUrl::FullyEncoded).toStdString();
91-
std::string path = url.path().toStdString() + "?" + query;
103+
std::string path = url.path().toStdString();
104+
if (url.hasQuery()) {
105+
path += "?" + url.query(QUrl::FullyEncoded).toStdString();
106+
}
92107
http_client.wipe_response();
93108
success = http_client.invoke_get(path, timeout, {}, std::addressof(response), {{"User-Agent", userAgent}});
94109
}
@@ -196,6 +211,15 @@ bool P2PoolManager::start(const QString &flags, const QString &address, const QS
196211
arguments << "--wallet" << address;
197212
}
198213

214+
{
215+
QMutexLocker locker(&m_proxyMutex);
216+
if (!m_proxyAddress.isEmpty()) {
217+
if (!arguments.contains("--socks5")) {
218+
arguments << "--socks5" << m_proxyAddress;
219+
}
220+
}
221+
}
222+
199223
qDebug() << "starting p2pool " + m_p2pool;
200224
qDebug() << "With command line arguments " << arguments;
201225

@@ -220,6 +244,25 @@ bool P2PoolManager::start(const QString &flags, const QString &address, const QS
220244
return true;
221245
}
222246

247+
QString P2PoolManager::proxyAddress() const
248+
{
249+
QMutexLocker locker(&m_proxyMutex);
250+
return m_proxyAddress;
251+
}
252+
253+
void P2PoolManager::setProxyAddress(QString address)
254+
{
255+
{
256+
QMutexLocker locker(&m_proxyMutex);
257+
if (m_proxyAddress == address) {
258+
return;
259+
}
260+
m_proxyAddress = address;
261+
}
262+
263+
emit proxyAddressChanged();
264+
}
265+
223266
void P2PoolManager::exit()
224267
{
225268
qDebug("P2PoolManager: exit()");

src/p2pool/P2PoolManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
class P2PoolManager : public QObject
4242
{
4343
Q_OBJECT
44+
Q_PROPERTY(QString proxyAddress READ proxyAddress WRITE setProxyAddress NOTIFY proxyAddressChanged)
4445

4546
public:
4647
explicit P2PoolManager(QObject *parent = 0);
@@ -63,17 +64,22 @@ class P2PoolManager : public QObject
6364
private:
6465

6566
bool running(NetworkType::Type nettype) const;
67+
QString proxyAddress() const;
68+
void setProxyAddress(QString address);
6669
signals:
6770
void p2poolStartFailure() const;
6871
void p2poolStatus(bool isMining, int hashrate) const;
6972
void p2poolDownloadFailure(int errorCode) const;
7073
void p2poolDownloadSuccess() const;
74+
void proxyAddressChanged() const;
7175

7276
private:
7377
std::unique_ptr<QProcess> m_p2poold;
7478
QMutex m_p2poolMutex;
7579
QString m_p2pool;
7680
QString m_p2poolPath;
81+
QString m_proxyAddress;
82+
mutable QMutex m_proxyMutex;
7783
bool started = false;
7884

7985
mutable FutureScheduler m_scheduler;

0 commit comments

Comments
 (0)