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+
223266void P2PoolManager::exit ()
224267{
225268 qDebug (" P2PoolManager: exit()" );
0 commit comments