Skip to content

Commit 0127a9b

Browse files
author
Philip Kaufmann
committed
remove SOCKS4 support from core and GUI
- now we support SOCKS5 only
1 parent 4ed2315 commit 0127a9b

File tree

9 files changed

+47
-172
lines changed

9 files changed

+47
-172
lines changed

src/init.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,8 @@ std::string HelpMessage(HelpMessageMode mode)
238238
strUsage += " -onion=<ip:port> " + _("Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)") + "\n";
239239
strUsage += " -onlynet=<net> " + _("Only connect to nodes in network <net> (IPv4, IPv6 or Tor)") + "\n";
240240
strUsage += " -port=<port> " + _("Listen for connections on <port> (default: 8333 or testnet: 18333)") + "\n";
241-
strUsage += " -proxy=<ip:port> " + _("Connect through SOCKS proxy") + "\n";
241+
strUsage += " -proxy=<ip:port> " + _("Connect through SOCKS5 proxy") + "\n";
242242
strUsage += " -seednode=<ip> " + _("Connect to a node to retrieve peer addresses, and disconnect") + "\n";
243-
strUsage += " -socks=<n> " + _("Select SOCKS version for -proxy (4 or 5, default: 5)") + "\n";
244243
strUsage += " -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n";
245244
#ifdef USE_UPNP
246245
#if USE_UPNP
@@ -745,10 +744,6 @@ bool AppInit2(boost::thread_group& threadGroup)
745744

746745
RegisterNodeSignals(GetNodeSignals());
747746

748-
int nSocksVersion = GetArg("-socks", 5);
749-
if (nSocksVersion != 4 && nSocksVersion != 5)
750-
return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion));
751-
752747
if (mapArgs.count("-onlynet")) {
753748
std::set<enum Network> nets;
754749
BOOST_FOREACH(std::string snet, mapMultiArgs["-onlynet"]) {
@@ -772,12 +767,10 @@ bool AppInit2(boost::thread_group& threadGroup)
772767
return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"]));
773768

774769
if (!IsLimited(NET_IPV4))
775-
SetProxy(NET_IPV4, addrProxy, nSocksVersion);
776-
if (nSocksVersion > 4) {
777-
if (!IsLimited(NET_IPV6))
778-
SetProxy(NET_IPV6, addrProxy, nSocksVersion);
779-
SetNameProxy(addrProxy, nSocksVersion);
780-
}
770+
SetProxy(NET_IPV4, addrProxy);
771+
if (!IsLimited(NET_IPV6))
772+
SetProxy(NET_IPV6, addrProxy);
773+
SetNameProxy(addrProxy);
781774
fProxy = true;
782775
}
783776

@@ -791,7 +784,7 @@ bool AppInit2(boost::thread_group& threadGroup)
791784
addrOnion = CService(mapArgs["-onion"], 9050);
792785
if (!addrOnion.IsValid())
793786
return InitError(strprintf(_("Invalid -onion address: '%s'"), mapArgs["-onion"]));
794-
SetProxy(NET_TOR, addrOnion, 5);
787+
SetProxy(NET_TOR, addrOnion);
795788
SetReachable(NET_TOR);
796789
}
797790

src/netbase.cpp

Lines changed: 27 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using namespace std;
3737

3838
// Settings
3939
static proxyType proxyInfo[NET_MAX];
40-
static proxyType nameproxyInfo;
40+
static CService nameProxy;
4141
static CCriticalSection cs_proxyInfos;
4242
int nConnectTimeout = 5000;
4343
bool fNameLookup = false;
@@ -214,50 +214,6 @@ bool LookupNumeric(const char *pszName, CService& addr, int portDefault)
214214
return Lookup(pszName, addr, portDefault, false);
215215
}
216216

217-
bool static Socks4(const CService &addrDest, SOCKET& hSocket)
218-
{
219-
LogPrintf("SOCKS4 connecting %s\n", addrDest.ToString());
220-
if (!addrDest.IsIPv4())
221-
{
222-
closesocket(hSocket);
223-
return error("Proxy destination is not IPv4");
224-
}
225-
char pszSocks4IP[] = "\4\1\0\0\0\0\0\0user";
226-
struct sockaddr_in addr;
227-
socklen_t len = sizeof(addr);
228-
if (!addrDest.GetSockAddr((struct sockaddr*)&addr, &len) || addr.sin_family != AF_INET)
229-
{
230-
closesocket(hSocket);
231-
return error("Cannot get proxy destination address");
232-
}
233-
memcpy(pszSocks4IP + 2, &addr.sin_port, 2);
234-
memcpy(pszSocks4IP + 4, &addr.sin_addr, 4);
235-
char* pszSocks4 = pszSocks4IP;
236-
int nSize = sizeof(pszSocks4IP);
237-
238-
int ret = send(hSocket, pszSocks4, nSize, MSG_NOSIGNAL);
239-
if (ret != nSize)
240-
{
241-
closesocket(hSocket);
242-
return error("Error sending to proxy");
243-
}
244-
char pchRet[8];
245-
if (recv(hSocket, pchRet, 8, 0) != 8)
246-
{
247-
closesocket(hSocket);
248-
return error("Error reading proxy response");
249-
}
250-
if (pchRet[1] != 0x5a)
251-
{
252-
closesocket(hSocket);
253-
if (pchRet[1] != 0x5b)
254-
LogPrintf("ERROR: Proxy returned error %d\n", pchRet[1]);
255-
return false;
256-
}
257-
LogPrintf("SOCKS4 connected %s\n", addrDest.ToString());
258-
return true;
259-
}
260-
261217
bool static Socks5(string strDest, int port, SOCKET& hSocket)
262218
{
263219
LogPrintf("SOCKS5 connecting %s\n", strDest);
@@ -468,53 +424,49 @@ bool static ConnectSocketDirectly(const CService &addrConnect, SOCKET& hSocketRe
468424
return true;
469425
}
470426

471-
bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion) {
427+
bool SetProxy(enum Network net, CService addrProxy) {
472428
assert(net >= 0 && net < NET_MAX);
473-
if (nSocksVersion != 0 && nSocksVersion != 4 && nSocksVersion != 5)
474-
return false;
475-
if (nSocksVersion != 0 && !addrProxy.IsValid())
429+
if (!addrProxy.IsValid())
476430
return false;
477431
LOCK(cs_proxyInfos);
478-
proxyInfo[net] = std::make_pair(addrProxy, nSocksVersion);
432+
proxyInfo[net] = addrProxy;
479433
return true;
480434
}
481435

482436
bool GetProxy(enum Network net, proxyType &proxyInfoOut) {
483437
assert(net >= 0 && net < NET_MAX);
484438
LOCK(cs_proxyInfos);
485-
if (!proxyInfo[net].second)
439+
if (!proxyInfo[net].IsValid())
486440
return false;
487441
proxyInfoOut = proxyInfo[net];
488442
return true;
489443
}
490444

491-
bool SetNameProxy(CService addrProxy, int nSocksVersion) {
492-
if (nSocksVersion != 0 && nSocksVersion != 5)
493-
return false;
494-
if (nSocksVersion != 0 && !addrProxy.IsValid())
445+
bool SetNameProxy(CService addrProxy) {
446+
if (!addrProxy.IsValid())
495447
return false;
496448
LOCK(cs_proxyInfos);
497-
nameproxyInfo = std::make_pair(addrProxy, nSocksVersion);
449+
nameProxy = addrProxy;
498450
return true;
499451
}
500452

501-
bool GetNameProxy(proxyType &nameproxyInfoOut) {
453+
bool GetNameProxy(CService &nameProxyOut) {
502454
LOCK(cs_proxyInfos);
503-
if (!nameproxyInfo.second)
455+
if(!nameProxy.IsValid())
504456
return false;
505-
nameproxyInfoOut = nameproxyInfo;
457+
nameProxyOut = nameProxy;
506458
return true;
507459
}
508460

509461
bool HaveNameProxy() {
510462
LOCK(cs_proxyInfos);
511-
return nameproxyInfo.second != 0;
463+
return nameProxy.IsValid();
512464
}
513465

514466
bool IsProxy(const CNetAddr &addr) {
515467
LOCK(cs_proxyInfos);
516468
for (int i = 0; i < NET_MAX; i++) {
517-
if (proxyInfo[i].second && (addr == (CNetAddr)proxyInfo[i].first))
469+
if (addr == (CNetAddr)proxyInfo[i])
518470
return true;
519471
}
520472
return false;
@@ -523,31 +475,18 @@ bool IsProxy(const CNetAddr &addr) {
523475
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
524476
{
525477
proxyType proxy;
526-
527-
// no proxy needed
478+
// no proxy needed (none set for target network)
528479
if (!GetProxy(addrDest.GetNetwork(), proxy))
529480
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);
530481

531482
SOCKET hSocket = INVALID_SOCKET;
532483

533484
// first connect to proxy server
534-
if (!ConnectSocketDirectly(proxy.first, hSocket, nTimeout))
485+
if (!ConnectSocketDirectly(proxy, hSocket, nTimeout))
535486
return false;
536-
537487
// do socks negotiation
538-
switch (proxy.second) {
539-
case 4:
540-
if (!Socks4(addrDest, hSocket))
541-
return false;
542-
break;
543-
case 5:
544-
if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket))
545-
return false;
546-
break;
547-
default:
548-
closesocket(hSocket);
488+
if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket))
549489
return false;
550-
}
551490

552491
hSocketRet = hSocket;
553492
return true;
@@ -561,30 +500,25 @@ bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest
561500

562501
SOCKET hSocket = INVALID_SOCKET;
563502

564-
proxyType nameproxy;
565-
GetNameProxy(nameproxy);
503+
CService nameProxy;
504+
GetNameProxy(nameProxy);
566505

567-
CService addrResolved(CNetAddr(strDest, fNameLookup && !nameproxy.second), port);
506+
CService addrResolved(CNetAddr(strDest, fNameLookup && !HaveNameProxy()), port);
568507
if (addrResolved.IsValid()) {
569508
addr = addrResolved;
570509
return ConnectSocket(addr, hSocketRet, nTimeout);
571510
}
511+
572512
addr = CService("0.0.0.0:0");
573-
if (!nameproxy.second)
513+
514+
if (!HaveNameProxy())
574515
return false;
575-
if (!ConnectSocketDirectly(nameproxy.first, hSocket, nTimeout))
516+
// first connect to name proxy server
517+
if (!ConnectSocketDirectly(nameProxy, hSocket, nTimeout))
518+
return false;
519+
// do socks negotiation
520+
if (!Socks5(strDest, (unsigned short)port, hSocket))
576521
return false;
577-
578-
switch(nameproxy.second) {
579-
default:
580-
case 4:
581-
closesocket(hSocket);
582-
return false;
583-
case 5:
584-
if (!Socks5(strDest, port, hSocket))
585-
return false;
586-
break;
587-
}
588522

589523
hSocketRet = hSocket;
590524
return true;

src/netbase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ class CService : public CNetAddr
161161
)
162162
};
163163

164-
typedef std::pair<CService, int> proxyType;
164+
typedef CService proxyType;
165165

166166
enum Network ParseNetwork(std::string net);
167167
void SplitHostPort(std::string in, int &portOut, std::string &hostOut);
168-
bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion = 5);
168+
bool SetProxy(enum Network net, CService addrProxy);
169169
bool GetProxy(enum Network net, proxyType &proxyInfoOut);
170170
bool IsProxy(const CNetAddr &addr);
171-
bool SetNameProxy(CService addrProxy, int nSocksVersion = 5);
171+
bool SetNameProxy(CService addrProxy);
172172
bool HaveNameProxy();
173173
bool LookupHost(const char *pszName, std::vector<CNetAddr>& vIP, unsigned int nMaxSolutions = 0, bool fAllowLookup = true);
174174
bool Lookup(const char *pszName, CService& addr, int portDefault = 0, bool fAllowLookup = true);

src/qt/forms/optionsdialog.ui

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -328,26 +328,6 @@
328328
</property>
329329
</widget>
330330
</item>
331-
<item>
332-
<widget class="QLabel" name="socksVersionLabel">
333-
<property name="text">
334-
<string>SOCKS &amp;Version:</string>
335-
</property>
336-
<property name="textFormat">
337-
<enum>Qt::PlainText</enum>
338-
</property>
339-
<property name="buddy">
340-
<cstring>socksVersion</cstring>
341-
</property>
342-
</widget>
343-
</item>
344-
<item>
345-
<widget class="QValueComboBox" name="socksVersion">
346-
<property name="toolTip">
347-
<string>SOCKS version of the proxy (e.g. 5)</string>
348-
</property>
349-
</widget>
350-
</item>
351331
<item>
352332
<spacer name="horizontalSpacer_1_Network">
353333
<property name="orientation">

src/qt/optionsdialog.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,8 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
5252
ui->proxyPort->setEnabled(false);
5353
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
5454

55-
/** SOCKS version is only selectable for default proxy and is always 5 for IPv6 and Tor */
56-
ui->socksVersion->setEnabled(false);
57-
ui->socksVersion->addItem("5", 5);
58-
ui->socksVersion->addItem("4", 4);
59-
ui->socksVersion->setCurrentIndex(0);
60-
6155
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
6256
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));
63-
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->socksVersion, SLOT(setEnabled(bool)));
6457

6558
ui->proxyIp->installEventFilter(this);
6659

@@ -182,7 +175,6 @@ void OptionsDialog::setMapper()
182175
mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse);
183176
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
184177
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);
185-
mapper->addMapping(ui->socksVersion, OptionsModel::ProxySocksVersion);
186178

187179
/* Window */
188180
#ifndef Q_OS_MAC

src/qt/optionsmodel.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ void OptionsModel::Init()
122122
// Only try to set -proxy, if user has enabled fUseProxy
123123
if (settings.value("fUseProxy").toBool() && !SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
124124
addOverriddenOption("-proxy");
125-
if (!settings.contains("nSocksVersion"))
126-
settings.setValue("nSocksVersion", 5);
127-
// Only try to set -socks, if user has enabled fUseProxy
128-
if (settings.value("fUseProxy").toBool() && !SoftSetArg("-socks", settings.value("nSocksVersion").toString().toStdString()))
129-
addOverriddenOption("-socks");
130125

131126
// Display
132127
if (!settings.contains("language"))
@@ -188,8 +183,6 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
188183
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
189184
return strlIpPort.at(1);
190185
}
191-
case ProxySocksVersion:
192-
return settings.value("nSocksVersion", 5);
193186

194187
#ifdef ENABLE_WALLET
195188
case Fee: {
@@ -284,13 +277,6 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
284277
}
285278
}
286279
break;
287-
case ProxySocksVersion: {
288-
if (settings.value("nSocksVersion") != value) {
289-
settings.setValue("nSocksVersion", value.toInt());
290-
setRestartRequired(true);
291-
}
292-
}
293-
break;
294280
#ifdef ENABLE_WALLET
295281
case Fee: { // core option - can be changed on-the-fly
296282
// Todo: Add is valid check and warn via message, if not
@@ -378,20 +364,16 @@ bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
378364
// GUI settings can be overridden with -proxy.
379365
proxyType curProxy;
380366
if (GetProxy(NET_IPV4, curProxy)) {
381-
if (curProxy.second == 5) {
382-
proxy.setType(QNetworkProxy::Socks5Proxy);
383-
proxy.setHostName(QString::fromStdString(curProxy.first.ToStringIP()));
384-
proxy.setPort(curProxy.first.GetPort());
367+
proxy.setType(QNetworkProxy::Socks5Proxy);
368+
proxy.setHostName(QString::fromStdString(curProxy.ToStringIP()));
369+
proxy.setPort(curProxy.GetPort());
385370

386-
return true;
387-
}
388-
else
389-
return false;
371+
return true;
390372
}
391373
else
392374
proxy.setType(QNetworkProxy::NoProxy);
393375

394-
return true;
376+
return false;
395377
}
396378

397379
void OptionsModel::setRestartRequired(bool fRequired)

0 commit comments

Comments
 (0)