Dash Core  0.12.2.1
P2P Digital Currency
netbase.cpp File Reference
#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
 

Functions

static std::atomic< bool > interruptSocks5Recv (false)
 
enum Network ParseNetwork (std::string net)
 
std::string GetNetworkName (enum Network net)
 
void SplitHostPort (std::string in, int &portOut, std::string &hostOut)
 
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)
 
static bool InterruptibleRecv (char *data, size_t len, int timeout, SOCKET &hSocket)
 
static bool Socks5 (const std::string &strDest, int port, const ProxyCredentials *auth, SOCKET &hSocket)
 
static bool ConnectSocketDirectly (const CService &addrConnect, SOCKET &hSocketRet, 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)
 
static bool ConnectThroughProxy (const proxyType &proxy, const std::string &strDest, int port, SOCKET &hSocketRet, int nTimeout, bool *outProxyConnectionFailed)
 
bool ConnectSocket (const CService &addrDest, SOCKET &hSocketRet, int nTimeout, bool *outProxyConnectionFailed)
 
bool ConnectSocketByName (CService &addr, SOCKET &hSocketRet, const char *pszDest, int portDefault, int nTimeout, bool *outProxyConnectionFailed)
 
bool LookupSubNet (const char *pszName, CSubNet &ret)
 
std::string NetworkErrorString (int err)
 
bool CloseSocket (SOCKET &hSocket)
 
bool SetSocketNonBlocking (SOCKET &hSocket, bool fNonBlocking)
 
void InterruptSocks5 (bool interrupt)
 

Variables

static proxyType proxyInfo [NET_MAX]
 
static proxyType nameProxy
 
static CCriticalSection cs_proxyInfos
 
int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT
 
bool fNameLookup = DEFAULT_NAME_LOOKUP
 
static const int SOCKS5_RECV_TIMEOUT = 20 * 1000
 

Function Documentation

◆ CloseSocket()

bool CloseSocket ( SOCKET hSocket)

◆ ConnectSocket()

bool ConnectSocket ( const CService addrDest,
SOCKET hSocketRet,
int  nTimeout,
bool *  outProxyConnectionFailed 
)

Definition at line 600 of file netbase.cpp.

Referenced by CConnman::ConnectNode(), and ConnectSocketByName().

◆ ConnectSocketByName()

bool ConnectSocketByName ( CService addr,
SOCKET hSocketRet,
const char *  pszDest,
int  portDefault,
int  nTimeout,
bool *  outProxyConnectionFailed 
)

Definition at line 612 of file netbase.cpp.

Referenced by CConnman::ConnectNode().

◆ ConnectSocketDirectly()

static bool ConnectSocketDirectly ( const CService addrConnect,
SOCKET hSocketRet,
int  nTimeout 
)
static

Definition at line 438 of file netbase.cpp.

Referenced by ConnectSocket(), and ConnectThroughProxy().

◆ ConnectThroughProxy()

static bool ConnectThroughProxy ( const proxyType proxy,
const std::string &  strDest,
int  port,
SOCKET hSocketRet,
int  nTimeout,
bool *  outProxyConnectionFailed 
)
static

Definition at line 575 of file netbase.cpp.

Referenced by ConnectSocket(), and ConnectSocketByName().

◆ GetNameProxy()

bool GetNameProxy ( proxyType nameProxyOut)

Definition at line 553 of file netbase.cpp.

Referenced by ConnectSocketByName().

◆ GetNetworkName()

std::string GetNetworkName ( enum Network  net)

Definition at line 51 of file netbase.cpp.

Referenced by GetNetworksInfo().

◆ GetProxy()

bool GetProxy ( enum Network  net,
proxyType proxyInfoOut 
)

◆ HaveNameProxy()

bool HaveNameProxy ( )

Definition at line 561 of file netbase.cpp.

Referenced by ConnectSocketByName(), and CConnman::ThreadDNSAddressSeed().

◆ InterruptibleRecv()

static bool InterruptibleRecv ( char *  data,
size_t  len,
int  timeout,
SOCKET hSocket 
)
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
dataBuffer to receive into
lenLength of data to receive
timeoutTimeout in milliseconds for receive operation
Note
This function requires that hSocket is in non-blocking mode.

Definition at line 257 of file netbase.cpp.

Referenced by Socks5().

◆ InterruptSocks5()

void InterruptSocks5 ( bool  interrupt)

Definition at line 753 of file netbase.cpp.

Referenced by CConnman::Interrupt(), and CConnman::Start().

◆ interruptSocks5Recv()

static std::atomic<bool> interruptSocks5Recv ( false  )
static

◆ IsProxy()

bool IsProxy ( const CNetAddr addr)

Definition at line 566 of file netbase.cpp.

◆ Lookup() [1/2]

bool Lookup ( const char *  pszName,
std::vector< CService > &  vAddr,
int  portDefault,
bool  fAllowLookup,
unsigned int  nMaxSolutions 
)

◆ Lookup() [2/2]

bool Lookup ( const char *  pszName,
CService addr,
int  portDefault,
bool  fAllowLookup 
)

Definition at line 218 of file netbase.cpp.

◆ LookupHost() [1/2]

bool LookupHost ( const char *  pszName,
std::vector< CNetAddr > &  vIP,
unsigned int  nMaxSolutions,
bool  fAllowLookup 
)

◆ LookupHost() [2/2]

bool LookupHost ( const char *  pszName,
CNetAddr addr,
bool  fAllowLookup 
)

Definition at line 190 of file netbase.cpp.

◆ LookupIntern()

static bool LookupIntern ( const char *  pszName,
std::vector< CNetAddr > &  vIP,
unsigned int  nMaxSolutions,
bool  fAllowLookup 
)
static

Definition at line 80 of file netbase.cpp.

Referenced by Lookup(), and LookupHost().

◆ LookupNumeric()

◆ LookupSubNet()

bool LookupSubNet ( const char *  pszName,
CSubNet ret 
)

Definition at line 640 of file netbase.cpp.

Referenced by AppInit2(), 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 238 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 694 of file netbase.cpp.

Referenced by CConnman::AcceptConnection(), CConnman::BindListenPort(), ConnectSocketDirectly(), CConnman::SocketSendData(), CConnman::Stop(), and CConnman::ThreadSocketHandler().

◆ ParseNetwork()

enum Network ParseNetwork ( std::string  net)

Definition at line 43 of file netbase.cpp.

Referenced by AppInit2().

◆ SetNameProxy()

bool SetNameProxy ( const proxyType addrProxy)

Definition at line 545 of file netbase.cpp.

Referenced by AppInit2().

◆ SetProxy()

bool SetProxy ( enum Network  net,
const proxyType addrProxy 
)

Definition at line 527 of file netbase.cpp.

Referenced by AppInit2(), and TorController::auth_cb().

◆ SetSocketNonBlocking()

bool SetSocketNonBlocking ( SOCKET hSocket,
bool  fNonBlocking 
)

Disable or enable blocking-mode for a socket

Definition at line 724 of file netbase.cpp.

Referenced by CConnman::BindListenPort(), and ConnectSocketDirectly().

◆ Socks5()

static bool Socks5 ( const std::string &  strDest,
int  port,
const ProxyCredentials auth,
SOCKET hSocket 
)
static

Connect using SOCKS5 (as described in RFC1928)

Definition at line 303 of file netbase.cpp.

Referenced by ConnectThroughProxy().

◆ SplitHostPort()

void SplitHostPort ( std::string  in,
int &  portOut,
std::string &  hostOut 
)

Variable Documentation

◆ cs_proxyInfos

CCriticalSection cs_proxyInfos
static

Definition at line 35 of file netbase.cpp.

Referenced by GetNameProxy(), GetProxy(), HaveNameProxy(), IsProxy(), SetNameProxy(), and SetProxy().

◆ fNameLookup

bool fNameLookup = DEFAULT_NAME_LOOKUP

Definition at line 37 of file netbase.cpp.

Referenced by AppInit2(), and ConnectSocketByName().

◆ nameProxy

proxyType nameProxy
static

Definition at line 34 of file netbase.cpp.

Referenced by ConnectSocketByName(), GetNameProxy(), HaveNameProxy(), and SetNameProxy().

◆ nConnectTimeout

int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT

Definition at line 36 of file netbase.cpp.

Referenced by AppInit2(), and CConnman::ConnectNode().

◆ proxyInfo

proxyType proxyInfo[NET_MAX]
static

Definition at line 33 of file netbase.cpp.

Referenced by GetProxy(), IsProxy(), and SetProxy().

◆ SOCKS5_RECV_TIMEOUT

const int SOCKS5_RECV_TIMEOUT = 20 * 1000
static

Definition at line 40 of file netbase.cpp.

Referenced by Socks5().