Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Functions | Variables
netbase.h File Reference
#include <compat.h>
#include <netaddress.h>
#include <serialize.h>
#include <stdint.h>
#include <string>
#include <vector>
Include dependency graph for netbase.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  proxyType
 

Functions

enum Network ParseNetwork (const std::string &net)
 
std::string GetNetworkName (enum Network net)
 
bool SetProxy (enum Network net, const proxyType &addrProxy)
 
bool GetProxy (enum Network net, proxyType &proxyInfoOut)
 
bool IsProxy (const CNetAddr &addr)
 
bool SetNameProxy (const proxyType &addrProxy)
 Set the name proxy to use for all connections to nodes specified by a hostname. More...
 
bool HaveNameProxy ()
 
bool GetNameProxy (proxyType &nameProxyOut)
 
bool LookupHost (const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup)
 Resolve a host string to its corresponding network addresses. More...
 
bool LookupHost (const std::string &name, CNetAddr &addr, bool fAllowLookup)
 Resolve a host string to its first corresponding network address. More...
 
bool Lookup (const std::string &name, CService &addr, int portDefault, bool fAllowLookup)
 Resolve a service string to its first corresponding service. More...
 
bool Lookup (const std::string &name, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
 Resolve a service string to its corresponding service. More...
 
CService LookupNumeric (const std::string &name, int portDefault=0)
 Resolve a service string with a numeric IP to its first corresponding service. More...
 
bool LookupSubNet (const std::string &strSubnet, CSubNet &subnet)
 Parse and resolve a specified subnet string into the appropriate internal representation. More...
 
SOCKET CreateSocket (const CService &addrConnect)
 Try to create a socket file descriptor with specific properties in the communications domain (address family) of the specified service. More...
 
bool ConnectSocketDirectly (const CService &addrConnect, const SOCKET &hSocketRet, int nTimeout, bool manual_connection)
 Try to connect to the specified service on the specified socket. More...
 
bool ConnectThroughProxy (const proxyType &proxy, const std::string &strDest, int port, const SOCKET &hSocketRet, int nTimeout, bool &outProxyConnectionFailed)
 Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 proxy. More...
 
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...
 
struct timeval MillisToTimeval (int64_t nTimeout)
 Convert milliseconds to a struct timeval for e.g. More...
 
void InterruptSocks5 (bool interrupt)
 

Variables

int nConnectTimeout
 
bool fNameLookup
 
static const int DEFAULT_CONNECT_TIMEOUT = 5000
 -timeout default More...
 
static const int DEFAULT_NAME_LOOKUP = true
 -dns default More...
 

Function Documentation

◆ CloseSocket()

bool CloseSocket ( SOCKET hSocket)

Close socket and set hSocket to INVALID_SOCKET.

Definition at line 899 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConnectSocketDirectly()

bool ConnectSocketDirectly ( const CService addrConnect,
const SOCKET hSocket,
int  nTimeout,
bool  manual_connection 
)

Try to connect to the specified service on the specified socket.

Parameters
addrConnectThe service to which to connect.
hSocketThe socket on which to connect.
nTimeoutWait this many milliseconds for the connection to be established.
manual_connectionWhether or not the connection was manually requested (e.g. through the addnode RPC)
Returns
Whether or not a connection was successfully made.

Definition at line 630 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConnectThroughProxy()

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

Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 proxy.

Parameters
proxyThe SOCKS5 proxy.
strDestThe destination service to which to connect.
portThe destination port.
hSocketThe socket on which to connect to the SOCKS5 proxy.
nTimeoutWait this many milliseconds for the connection to the SOCKS5 proxy to be established.
[out]outProxyConnectionFailedWhether or not the connection to the SOCKS5 proxy failed.
Returns
Whether or not the operation succeeded.

Definition at line 789 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateSocket()

SOCKET CreateSocket ( const CService addrConnect)

Try to create a socket file descriptor with specific properties in the communications domain (address family) of the specified service.

For details on the desired properties, see the inline comments in the source code.

Definition at line 567 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNameProxy()

bool GetNameProxy ( proxyType nameProxyOut)

Definition at line 752 of file netbase.cpp.

Here is the caller graph for this function:

◆ GetNetworkName()

std::string GetNetworkName ( enum Network  net)

Definition at line 53 of file netbase.cpp.

Here is the caller graph for this function:

◆ GetProxy()

bool GetProxy ( enum Network  net,
proxyType proxyInfoOut 
)

Definition at line 719 of file netbase.cpp.

Here is the caller graph for this function:

◆ HaveNameProxy()

bool HaveNameProxy ( )

Definition at line 760 of file netbase.cpp.

Here is the caller graph for this function:

◆ InterruptSocks5()

void InterruptSocks5 ( bool  interrupt)

Definition at line 949 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsProxy()

bool IsProxy ( const CNetAddr addr)

Definition at line 765 of file netbase.cpp.

◆ Lookup() [1/2]

bool Lookup ( const std::string &  name,
CService addr,
int  portDefault,
bool  fAllowLookup 
)

Resolve a service string to its first corresponding service.

See also
Lookup(const char *, std::vector<CService>&, int, bool, unsigned int) for additional parameter descriptions.

Definition at line 230 of file netbase.cpp.

Here is the call graph for this function:

◆ Lookup() [2/2]

bool Lookup ( const std::string &  name,
std::vector< CService > &  vAddr,
int  portDefault,
bool  fAllowLookup,
unsigned int  nMaxSolutions 
)

Resolve a service string to its corresponding service.

Parameters
nameThe string representing a service. Could be a name or a numerical IP address (IPv6 addresses should be in their disambiguated bracketed form), optionally followed by a port number. (e.g. example.com:8333 or
[out]vAddrThe resulting services to which the specified service string resolved.
portDefaultThe default port for resulting services if not specified by the service string.
fAllowLookupWhether or not hostname lookups are permitted. If yes, external queries may be performed.
nMaxSolutionsThe maximum number of results we want, specifying 0 means "as many solutions as we get."
Returns
Whether or not the service string successfully resolved to any resulting services.

Definition at line 205 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LookupHost() [1/2]

bool LookupHost ( const std::string &  name,
std::vector< CNetAddr > &  vIP,
unsigned int  nMaxSolutions,
bool  fAllowLookup 
)

Resolve a host string to its corresponding network addresses.

Parameters
nameThe string representing a host. Could be a name or a numerical IP address (IPv6 addresses in their bracketed form are allowed).
[out]vIPThe resulting network addresses to which the specified host string resolved.
Returns
Whether or not the specified host string successfully resolved to any resulting network addresses.
See also
Lookup(const char *, std::vector<CService>&, int, bool, unsigned int) for additional parameter descriptions.

Definition at line 151 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LookupHost() [2/2]

bool LookupHost ( const std::string &  name,
CNetAddr addr,
bool  fAllowLookup 
)

Resolve a host string to its first corresponding network address.

See also
LookupHost(const std::string&, std::vector<CNetAddr>&, unsigned int, bool) for additional parameter descriptions.

Definition at line 172 of file netbase.cpp.

Here is the call graph for this function:

◆ LookupNumeric()

CService LookupNumeric ( const std::string &  name,
int  portDefault 
)

Resolve a service string with a numeric IP to its first corresponding service.

Returns
The resulting CService if the resolution was successful, [::]:0 otherwise.
See also
Lookup(const char *, CService&, int, bool) for additional parameter descriptions.

Definition at line 253 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LookupSubNet()

bool LookupSubNet ( const std::string &  strSubnet,
CSubNet ret 
)

Parse and resolve a specified subnet string into the appropriate internal representation.

Parameters
strSubnetA string representation of a subnet of the form network address [ "/", ( CIDR-style suffix | netmask ) ](e.g. 2001:db8::/32, 192.0.2.0/255.255.255.0, or 8.8.8.8).
retThe resulting internal representation of a subnet.
Returns
Whether the operation succeeded or not.

Definition at line 823 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MillisToTimeval()

struct timeval MillisToTimeval ( int64_t  nTimeout)

Convert milliseconds to a struct timeval for e.g.

select.

Definition at line 266 of file netbase.cpp.

Here is the caller graph for this function:

◆ NetworkErrorString()

std::string NetworkErrorString ( int  err)

Return readable error string for a network error code.

Definition at line 881 of file netbase.cpp.

Here is the caller graph for this function:

◆ ParseNetwork()

enum Network ParseNetwork ( const std::string &  net)

Definition at line 41 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetNameProxy()

bool SetNameProxy ( const proxyType addrProxy)

Set the name proxy to use for all connections to nodes specified by a hostname.

After setting this proxy, connecting to a node specified by a hostname won't result in a local lookup of said hostname, rather, connect to the node by asking the name proxy for a proxy connection to the hostname, effectively delegating the hostname lookup to the specified proxy.

This delegation increases privacy for those who set the name proxy as they no longer leak their external hostname queries to their DNS servers.

Returns
Whether or not the operation succeeded.
Note
SOCKS5's support for UDP-over-SOCKS5 has been considered, but no SOCK5 server in common use (most notably Tor) actually implements UDP support, and a DNS resolver is beyond the scope of this project.

Definition at line 744 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetProxy()

bool SetProxy ( enum Network  net,
const proxyType addrProxy 
)

Definition at line 710 of file netbase.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetSocketNoDelay()

bool SetSocketNoDelay ( const SOCKET hSocket)

Set the TCP_NODELAY flag on a socket.

Definition at line 942 of file netbase.cpp.

Here is the caller graph for this function:

◆ SetSocketNonBlocking()

bool SetSocketNonBlocking ( const SOCKET hSocket,
bool  fNonBlocking 
)

Disable or enable blocking-mode for a socket.

Definition at line 915 of file netbase.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ DEFAULT_CONNECT_TIMEOUT

const int DEFAULT_CONNECT_TIMEOUT = 5000
static

-timeout default

Definition at line 24 of file netbase.h.

◆ DEFAULT_NAME_LOOKUP

const int DEFAULT_NAME_LOOKUP = true
static

-dns default

Definition at line 26 of file netbase.h.

◆ fNameLookup

bool fNameLookup

Definition at line 35 of file netbase.cpp.

◆ nConnectTimeout

int nConnectTimeout

Definition at line 34 of file netbase.cpp.