Skip to content

Commit 5a6ba7d

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

4 files changed

Lines changed: 60 additions & 7 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: 51 additions & 6 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,26 @@ 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+
const epee::net_utils::ssl_options_t sslOptions{
92+
epee::net_utils::ssl_support_t::e_ssl_support_enabled
93+
};
94+
http_client.set_server(url.host().toStdString(), "443", {}, sslOptions);
8095
bool success = http_client.invoke_get(url.path().toStdString(), timeout, {}, std::addressof(response), {{"User-Agent", userAgent}});
8196
if (success && response->m_response_code == 404) {
8297
emit p2poolDownloadFailure(BinaryNotAvailable);
@@ -86,9 +101,11 @@ void P2PoolManager::download() {
86101
for (std::pair<std::string, std::string> i : fields) {
87102
if (i.first == "Location") {
88103
url = QString::fromStdString(i.second);
89-
http_client.set_server(url.host().toStdString(), "443", {});
90-
std::string query = url.query(QUrl::FullyEncoded).toStdString();
91-
std::string path = url.path().toStdString() + "?" + query;
104+
http_client.set_server(url.host().toStdString(), "443", {}, sslOptions);
105+
std::string path = url.path().toStdString();
106+
if (url.hasQuery()) {
107+
path += "?" + url.query(QUrl::FullyEncoded).toStdString();
108+
}
92109
http_client.wipe_response();
93110
success = http_client.invoke_get(path, timeout, {}, std::addressof(response), {{"User-Agent", userAgent}});
94111
}
@@ -196,6 +213,15 @@ bool P2PoolManager::start(const QString &flags, const QString &address, const QS
196213
arguments << "--wallet" << address;
197214
}
198215

216+
{
217+
QMutexLocker locker(&m_proxyMutex);
218+
if (!m_proxyAddress.isEmpty()) {
219+
if (!arguments.contains("--socks5")) {
220+
arguments << "--socks5" << m_proxyAddress;
221+
}
222+
}
223+
}
224+
199225
qDebug() << "starting p2pool " + m_p2pool;
200226
qDebug() << "With command line arguments " << arguments;
201227

@@ -220,6 +246,25 @@ bool P2PoolManager::start(const QString &flags, const QString &address, const QS
220246
return true;
221247
}
222248

249+
QString P2PoolManager::proxyAddress() const
250+
{
251+
QMutexLocker locker(&m_proxyMutex);
252+
return m_proxyAddress;
253+
}
254+
255+
void P2PoolManager::setProxyAddress(QString address)
256+
{
257+
{
258+
QMutexLocker locker(&m_proxyMutex);
259+
if (m_proxyAddress == address) {
260+
return;
261+
}
262+
m_proxyAddress = address;
263+
}
264+
265+
emit proxyAddressChanged();
266+
}
267+
223268
void P2PoolManager::exit()
224269
{
225270
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)