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+
223268void P2PoolManager::exit ()
224269{
225270 qDebug (" P2PoolManager: exit()" );
0 commit comments