|
|
@ -519,9 +519,11 @@ bool IsProxy(const CNetAddr &addr) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout) |
|
|
|
bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout, bool *outProxyConnectionFailed) |
|
|
|
{ |
|
|
|
{ |
|
|
|
proxyType proxy; |
|
|
|
proxyType proxy; |
|
|
|
|
|
|
|
if (outProxyConnectionFailed) |
|
|
|
|
|
|
|
*outProxyConnectionFailed = false; |
|
|
|
// no proxy needed (none set for target network)
|
|
|
|
// no proxy needed (none set for target network)
|
|
|
|
if (!GetProxy(addrDest.GetNetwork(), proxy)) |
|
|
|
if (!GetProxy(addrDest.GetNetwork(), proxy)) |
|
|
|
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout); |
|
|
|
return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout); |
|
|
@ -529,8 +531,11 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout) |
|
|
|
SOCKET hSocket = INVALID_SOCKET; |
|
|
|
SOCKET hSocket = INVALID_SOCKET; |
|
|
|
|
|
|
|
|
|
|
|
// first connect to proxy server
|
|
|
|
// first connect to proxy server
|
|
|
|
if (!ConnectSocketDirectly(proxy, hSocket, nTimeout)) |
|
|
|
if (!ConnectSocketDirectly(proxy, hSocket, nTimeout)) { |
|
|
|
|
|
|
|
if (outProxyConnectionFailed) |
|
|
|
|
|
|
|
*outProxyConnectionFailed = true; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
// do socks negotiation
|
|
|
|
// do socks negotiation
|
|
|
|
if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket)) |
|
|
|
if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -539,10 +544,14 @@ bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault, int nTimeout) |
|
|
|
bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest, int portDefault, int nTimeout, bool *outProxyConnectionFailed) |
|
|
|
{ |
|
|
|
{ |
|
|
|
string strDest; |
|
|
|
string strDest; |
|
|
|
int port = portDefault; |
|
|
|
int port = portDefault; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (outProxyConnectionFailed) |
|
|
|
|
|
|
|
*outProxyConnectionFailed = false; |
|
|
|
|
|
|
|
|
|
|
|
SplitHostPort(string(pszDest), port, strDest); |
|
|
|
SplitHostPort(string(pszDest), port, strDest); |
|
|
|
|
|
|
|
|
|
|
|
SOCKET hSocket = INVALID_SOCKET; |
|
|
|
SOCKET hSocket = INVALID_SOCKET; |
|
|
@ -561,8 +570,11 @@ bool ConnectSocketByName(CService &addr, SOCKET& hSocketRet, const char *pszDest |
|
|
|
if (!HaveNameProxy()) |
|
|
|
if (!HaveNameProxy()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
// first connect to name proxy server
|
|
|
|
// first connect to name proxy server
|
|
|
|
if (!ConnectSocketDirectly(nameProxy, hSocket, nTimeout)) |
|
|
|
if (!ConnectSocketDirectly(nameProxy, hSocket, nTimeout)) { |
|
|
|
|
|
|
|
if (outProxyConnectionFailed) |
|
|
|
|
|
|
|
*outProxyConnectionFailed = true; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
// do socks negotiation
|
|
|
|
// do socks negotiation
|
|
|
|
if (!Socks5(strDest, (unsigned short)port, hSocket)) |
|
|
|
if (!Socks5(strDest, (unsigned short)port, hSocket)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|