Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
#include <netbase.h>
#include <hash.h>
#include <sync.h>
#include <uint256.h>
#include <random.h>
#include <util.h>
#include <utilstrencodings.h>
#include <atomic>
#include <fcntl.h>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
Go to the source code of this file.
Classes | |
struct | ProxyCredentials |
Credentials for proxy authentication. More... | |
Macros | |
#define | MSG_NOSIGNAL 0 |
Enumerations | |
enum | SOCKSVersion : uint8_t { SOCKS4 = 0x04, SOCKS5 = 0x05 } |
SOCKS version. More... | |
enum | SOCKS5Method : uint8_t { NOAUTH = 0x00, GSSAPI = 0x01, USER_PASS = 0x02, NO_ACCEPTABLE = 0xff } |
Values defined for METHOD in RFC1928. More... | |
enum | SOCKS5Command : uint8_t { CONNECT = 0x01, BIND = 0x02, UDP_ASSOCIATE = 0x03 } |
Values defined for CMD in RFC1928. More... | |
enum | SOCKS5Reply : uint8_t { SUCCEEDED = 0x00, GENFAILURE = 0x01, NOTALLOWED = 0x02, NETUNREACHABLE = 0x03, HOSTUNREACHABLE = 0x04, CONNREFUSED = 0x05, TTLEXPIRED = 0x06, CMDUNSUPPORTED = 0x07, ATYPEUNSUPPORTED = 0x08 } |
Values defined for REP in RFC1928. More... | |
enum | SOCKS5Atyp : uint8_t { IPV4 = 0x01, DOMAINNAME = 0x03, IPV6 = 0x04 } |
Values defined for ATYPE in RFC1928. More... | |
enum | IntrRecvError { IntrRecvError::OK, IntrRecvError::Timeout, IntrRecvError::Disconnected, IntrRecvError::NetworkError, IntrRecvError::Interrupted } |
Status codes that can be returned by InterruptibleRecv. More... | |
Functions | |
static proxyType proxyInfo [NET_MAX] | GUARDED_BY (cs_proxyInfos) |
static std::atomic< bool > | interruptSocks5Recv (false) |
enum Network | ParseNetwork (std::string net) |
std::string | GetNetworkName (enum Network net) |
static bool | LookupIntern (const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup) |
bool | LookupHost (const char *pszName, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup) |
bool | LookupHost (const char *pszName, CNetAddr &addr, bool fAllowLookup) |
bool | Lookup (const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions) |
bool | Lookup (const char *pszName, CService &addr, int portDefault, bool fAllowLookup) |
CService | LookupNumeric (const char *pszName, int portDefault) |
struct timeval | MillisToTimeval (int64_t nTimeout) |
Convert milliseconds to a struct timeval for e.g. More... | |
static IntrRecvError | InterruptibleRecv (uint8_t *data, size_t len, int timeout, const SOCKET &hSocket) |
Read bytes from socket. More... | |
std::string | Socks5ErrorString (uint8_t err) |
Convert SOCKS5 reply to an error message. More... | |
static bool | Socks5 (const std::string &strDest, int port, const ProxyCredentials *auth, const SOCKET &hSocket) |
Connect using SOCKS5 (as described in RFC1928) More... | |
SOCKET | CreateSocket (const CService &addrConnect) |
bool | ConnectSocketDirectly (const CService &addrConnect, const SOCKET &hSocket, int nTimeout) |
bool | SetProxy (enum Network net, const proxyType &addrProxy) |
bool | GetProxy (enum Network net, proxyType &proxyInfoOut) |
bool | SetNameProxy (const proxyType &addrProxy) |
bool | GetNameProxy (proxyType &nameProxyOut) |
bool | HaveNameProxy () |
bool | IsProxy (const CNetAddr &addr) |
bool | ConnectThroughProxy (const proxyType &proxy, const std::string &strDest, int port, const SOCKET &hSocket, int nTimeout, bool *outProxyConnectionFailed) |
bool | LookupSubNet (const char *pszName, CSubNet &ret) |
std::string | NetworkErrorString (int err) |
Return readable error string for a network error code. More... | |
bool | CloseSocket (SOCKET &hSocket) |
Close socket and set hSocket to INVALID_SOCKET. More... | |
bool | SetSocketNonBlocking (const SOCKET &hSocket, bool fNonBlocking) |
Disable or enable blocking-mode for a socket. More... | |
bool | SetSocketNoDelay (const SOCKET &hSocket) |
Set the TCP_NODELAY flag on a socket. More... | |
void | InterruptSocks5 (bool interrupt) |
Variables | |
static CCriticalSection | cs_proxyInfos |
int | nConnectTimeout = DEFAULT_CONNECT_TIMEOUT |
bool | fNameLookup = DEFAULT_NAME_LOOKUP |
static const int | SOCKS5_RECV_TIMEOUT = 20 * 1000 |
Macro Definition Documentation
◆ MSG_NOSIGNAL
#define MSG_NOSIGNAL 0 |
Definition at line 28 of file netbase.cpp.
Referenced by Socks5().
Enumeration Type Documentation
◆ IntrRecvError
|
strong |
Status codes that can be returned by InterruptibleRecv.
Enumerator | |
---|---|
OK | |
Timeout | |
Disconnected | |
NetworkError | |
Interrupted |
Definition at line 228 of file netbase.cpp.
◆ SOCKS5Atyp
enum SOCKS5Atyp : uint8_t |
Values defined for ATYPE in RFC1928.
Enumerator | |
---|---|
IPV4 | |
DOMAINNAME | |
IPV6 |
Definition at line 221 of file netbase.cpp.
◆ SOCKS5Command
enum SOCKS5Command : uint8_t |
Values defined for CMD in RFC1928.
Enumerator | |
---|---|
CONNECT | |
BIND | |
UDP_ASSOCIATE |
Definition at line 201 of file netbase.cpp.
◆ SOCKS5Method
enum SOCKS5Method : uint8_t |
Values defined for METHOD in RFC1928.
Enumerator | |
---|---|
NOAUTH | |
GSSAPI | No authentication required. |
USER_PASS | GSSAPI. |
NO_ACCEPTABLE | Username/password. |
Definition at line 193 of file netbase.cpp.
◆ SOCKS5Reply
enum SOCKS5Reply : uint8_t |
Values defined for REP in RFC1928.
Definition at line 208 of file netbase.cpp.
◆ SOCKSVersion
enum SOCKSVersion : uint8_t |
Function Documentation
◆ CloseSocket()
bool CloseSocket | ( | SOCKET & | hSocket | ) |
Close socket and set hSocket to INVALID_SOCKET.
Definition at line 690 of file netbase.cpp.
References INVALID_SOCKET, LogPrintf, NetworkErrorString(), SOCKET_ERROR, and WSAGetLastError.
Referenced by CConnman::AcceptConnection(), CConnman::BindListenPort(), CNode::CloseSocketDisconnect(), CConnman::ConnectNode(), CreateSocket(), CActiveMasternodeManager::Init(), CConnman::Stop(), and CNode::~CNode().
◆ ConnectSocketDirectly()
Definition at line 482 of file netbase.cpp.
References CService::GetSockAddr(), INVALID_SOCKET, LogPrint, LogPrintf, MillisToTimeval(), BCLog::NET, NetworkErrorString(), SOCKET_ERROR, CService::ToString(), WSAEINPROGRESS, WSAEINVAL, WSAEWOULDBLOCK, and WSAGetLastError.
Referenced by CConnman::ConnectNode(), ConnectThroughProxy(), and CActiveMasternodeManager::Init().
◆ ConnectThroughProxy()
bool ConnectThroughProxy | ( | const proxyType & | proxy, |
const std::string & | strDest, | ||
int | port, | ||
const SOCKET & | hSocket, | ||
int | nTimeout, | ||
bool * | outProxyConnectionFailed | ||
) |
Definition at line 595 of file netbase.cpp.
References ConnectSocketDirectly(), ProxyCredentials::password, proxyType::proxy, proxyType::randomize_credentials, Socks5(), strprintf, and ProxyCredentials::username.
Referenced by CConnman::ConnectNode().
◆ CreateSocket()
Definition at line 446 of file netbase.cpp.
References CloseSocket(), CService::GetSockAddr(), INVALID_SOCKET, IsSelectableSocket(), LogPrintf, NetworkErrorString(), SetSocketNoDelay(), SetSocketNonBlocking(), CService::ToString(), and WSAGetLastError.
Referenced by CConnman::BindListenPort(), CConnman::ConnectNode(), and CActiveMasternodeManager::Init().
◆ GetNameProxy()
bool GetNameProxy | ( | proxyType & | nameProxyOut | ) |
Definition at line 573 of file netbase.cpp.
References cs_proxyInfos, and LOCK.
Referenced by CConnman::ConnectNode().
◆ GetNetworkName()
std::string GetNetworkName | ( | enum Network | net | ) |
Definition at line 50 of file netbase.cpp.
References NET_IPV4, NET_IPV6, and NET_TOR.
Referenced by GetNetworksInfo().
◆ GetProxy()
Definition at line 556 of file netbase.cpp.
References cs_proxyInfos, LOCK, and NET_MAX.
Referenced by CConnman::ConnectNode(), GetNetworksInfo(), OptionsModel::getProxySettings(), and OptionsDialog::updateDefaultProxyNets().
◆ GUARDED_BY()
|
static |
◆ HaveNameProxy()
bool HaveNameProxy | ( | ) |
Definition at line 581 of file netbase.cpp.
References cs_proxyInfos, and LOCK.
Referenced by CConnman::ConnectNode(), and CConnman::ThreadDNSAddressSeed().
◆ InterruptibleRecv()
|
static |
Read bytes from socket.
This will either read the full number of bytes requested or return False on error or timeout. This function can be interrupted by calling InterruptSocks5()
- Parameters
-
data Buffer to receive into len Length of data to receive timeout Timeout in milliseconds for receive operation
- Note
- This function requires that hSocket is in non-blocking mode.
Definition at line 247 of file netbase.cpp.
References Disconnected, GetTimeMillis(), Interrupted, interruptSocks5Recv(), IsSelectableSocket(), MillisToTimeval(), NetworkError, OK, SOCKET_ERROR, Timeout, WSAEINPROGRESS, WSAEINVAL, WSAEWOULDBLOCK, and WSAGetLastError.
Referenced by Socks5().
◆ InterruptSocks5()
void InterruptSocks5 | ( | bool | interrupt | ) |
Definition at line 740 of file netbase.cpp.
References interruptSocks5Recv().
Referenced by CConnman::Interrupt(), and CConnman::Start().
◆ interruptSocks5Recv()
|
static |
Referenced by InterruptibleRecv(), and InterruptSocks5().
◆ IsProxy()
bool IsProxy | ( | const CNetAddr & | addr | ) |
Definition at line 586 of file netbase.cpp.
References cs_proxyInfos, LOCK, and NET_MAX.
◆ Lookup() [1/2]
bool Lookup | ( | const char * | pszName, |
std::vector< CService > & | vAddr, | ||
int | portDefault, | ||
bool | fAllowLookup, | ||
unsigned int | nMaxSolutions | ||
) |
Definition at line 140 of file netbase.cpp.
References LookupIntern(), and SplitHostPort().
Referenced by AppInitMain(), CConnman::ConnectNode(), CActiveMasternodeManager::GetLocalAddress(), Lookup(), LookupNumeric(), and masternode_connect().
◆ Lookup() [2/2]
bool Lookup | ( | const char * | pszName, |
CService & | addr, | ||
int | portDefault, | ||
bool | fAllowLookup | ||
) |
Definition at line 158 of file netbase.cpp.
References Lookup().
◆ LookupHost() [1/2]
bool LookupHost | ( | const char * | pszName, |
std::vector< CNetAddr > & | vIP, | ||
unsigned int | nMaxSolutions, | ||
bool | fAllowLookup | ||
) |
Definition at line 117 of file netbase.cpp.
References LookupIntern().
Referenced by Discover(), CActiveMasternodeManager::GetLocalAddress(), InitHTTPAllowList(), LookupHost(), LookupSubNet(), setban(), and CConnman::ThreadDNSAddressSeed().
◆ LookupHost() [2/2]
bool LookupHost | ( | const char * | pszName, |
CNetAddr & | addr, | ||
bool | fAllowLookup | ||
) |
Definition at line 130 of file netbase.cpp.
References LookupHost().
◆ LookupIntern()
|
static |
Definition at line 60 of file netbase.cpp.
References CNetAddr::IsInternal(), and CNetAddr::SetSpecial().
Referenced by Lookup(), and LookupHost().
◆ LookupNumeric()
CService LookupNumeric | ( | const char * | pszName, |
int | portDefault | ||
) |
Definition at line 168 of file netbase.cpp.
References Lookup().
Referenced by TorController::add_onion_cb(), AdvertiseLocal(), TorController::auth_cb(), CConnman::GetAddedNodeInfo(), HTTPRequest::GetPeer(), and ProxyAddressValidator::validate().
◆ LookupSubNet()
bool LookupSubNet | ( | const char * | pszName, |
CSubNet & | ret | ||
) |
Definition at line 618 of file netbase.cpp.
References CSubNet::IsValid(), LookupHost(), and ParseInt32().
Referenced by AppInitMain(), InitHTTPAllowList(), setban(), and RPCConsole::unbanSelectedNode().
◆ MillisToTimeval()
struct timeval MillisToTimeval | ( | int64_t | nTimeout | ) |
Convert milliseconds to a struct timeval for e.g.
select.
Definition at line 178 of file netbase.cpp.
Referenced by ConnectSocketDirectly(), TorController::disconnected_cb(), and InterruptibleRecv().
◆ NetworkErrorString()
std::string NetworkErrorString | ( | int | err | ) |
Return readable error string for a network error code.
Definition at line 672 of file netbase.cpp.
References strprintf.
Referenced by CConnman::AcceptConnection(), CConnman::BindListenPort(), CloseSocket(), ConnectSocketDirectly(), CreateSocket(), CConnman::RegisterEvents(), CConnman::SocketEventsSelect(), CConnman::SocketRecvData(), CConnman::SocketSendData(), CConnman::Start(), CConnman::Stop(), and CConnman::UnregisterEvents().
◆ ParseNetwork()
enum Network ParseNetwork | ( | std::string | net | ) |
Definition at line 42 of file netbase.cpp.
References NET_IPV4, NET_IPV6, NET_TOR, and NET_UNROUTABLE.
Referenced by AppInitMain().
◆ SetNameProxy()
bool SetNameProxy | ( | const proxyType & | addrProxy | ) |
Definition at line 565 of file netbase.cpp.
References cs_proxyInfos, proxyType::IsValid(), and LOCK.
Referenced by AppInitMain().
◆ SetProxy()
Definition at line 547 of file netbase.cpp.
References cs_proxyInfos, proxyType::IsValid(), LOCK, and NET_MAX.
Referenced by AppInitMain(), and TorController::auth_cb().
◆ SetSocketNoDelay()
bool SetSocketNoDelay | ( | const SOCKET & | hSocket | ) |
Set the TCP_NODELAY flag on a socket.
Definition at line 733 of file netbase.cpp.
Referenced by CConnman::AcceptConnection(), and CreateSocket().
◆ SetSocketNonBlocking()
bool SetSocketNonBlocking | ( | const SOCKET & | hSocket, |
bool | fNonBlocking | ||
) |
Disable or enable blocking-mode for a socket.
Definition at line 706 of file netbase.cpp.
References SOCKET_ERROR.
Referenced by CreateSocket().
◆ Socks5()
|
static |
Connect using SOCKS5 (as described in RFC1928)
Definition at line 327 of file netbase.cpp.
References CONNECT, DOMAINNAME, error(), InterruptibleRecv(), IPV4, IPV6, LogPrint, LogPrintf, MSG_NOSIGNAL, BCLog::NET, NOAUTH, OK, ProxyCredentials::password, BCLog::PROXY, SOCKS5, SOCKS5_RECV_TIMEOUT, Socks5ErrorString(), SUCCEEDED, Timeout, USER_PASS, and ProxyCredentials::username.
Referenced by ConnectThroughProxy().
◆ Socks5ErrorString()
std::string Socks5ErrorString | ( | uint8_t | err | ) |
Convert SOCKS5 reply to an error message.
Definition at line 302 of file netbase.cpp.
References ATYPEUNSUPPORTED, CMDUNSUPPORTED, CONNREFUSED, GENFAILURE, HOSTUNREACHABLE, NETUNREACHABLE, NOTALLOWED, and TTLEXPIRED.
Referenced by Socks5().
Variable Documentation
◆ cs_proxyInfos
|
static |
Definition at line 32 of file netbase.cpp.
Referenced by GetNameProxy(), GetProxy(), HaveNameProxy(), IsProxy(), SetNameProxy(), and SetProxy().
◆ fNameLookup
bool fNameLookup = DEFAULT_NAME_LOOKUP |
Definition at line 36 of file netbase.cpp.
Referenced by AppInitMain(), and CConnman::ConnectNode().
◆ nConnectTimeout
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT |
Definition at line 35 of file netbase.cpp.
Referenced by AppInitParameterInteraction(), CConnman::ConnectNode(), and CActiveMasternodeManager::Init().
◆ SOCKS5_RECV_TIMEOUT
|
static |
Definition at line 39 of file netbase.cpp.
Referenced by Socks5().