![]() |
Bitcoin Core
26.1.0
P2P Digital Currency
|
#include <netbase.h>#include <compat/compat.h>#include <logging.h>#include <sync.h>#include <tinyformat.h>#include <util/sock.h>#include <util/strencodings.h>#include <util/string.h>#include <util/time.h>#include <atomic>#include <chrono>#include <cstdint>#include <functional>#include <limits>#include <memory>Go to the source code of this file.
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 Proxy proxyInfo [NET_MAX] | GUARDED_BY (g_proxyinfo_mutex) |
| static std::atomic< bool > | interruptSocks5Recv (false) |
| std::vector< CNetAddr > | WrappedGetAddrInfo (const std::string &name, bool allow_lookup) |
| Wrapper for getaddrinfo(3). More... | |
| enum Network | ParseNetwork (const std::string &net_in) |
| std::string | GetNetworkName (enum Network net) |
| std::vector< std::string > | GetNetworkNames (bool append_unroutable) |
| Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE. More... | |
| static std::vector< CNetAddr > | LookupIntern (const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function) |
| std::vector< CNetAddr > | LookupHost (const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function) |
| Resolve a host string to its corresponding network addresses. More... | |
| std::optional< CNetAddr > | LookupHost (const std::string &name, bool fAllowLookup, DNSLookupFn dns_lookup_function) |
| Resolve a host string to its first corresponding network address. More... | |
| std::vector< CService > | Lookup (const std::string &name, uint16_t portDefault, bool fAllowLookup, unsigned int nMaxSolutions, DNSLookupFn dns_lookup_function) |
| Resolve a service string to its corresponding service. More... | |
| std::optional< CService > | Lookup (const std::string &name, uint16_t portDefault, bool fAllowLookup, DNSLookupFn dns_lookup_function) |
| Resolve a service string to its first corresponding service. More... | |
| CService | LookupNumeric (const std::string &name, uint16_t portDefault, DNSLookupFn dns_lookup_function) |
| Resolve a service string with a numeric IP to its first corresponding service. More... | |
| static IntrRecvError | InterruptibleRecv (uint8_t *data, size_t len, std::chrono::milliseconds timeout, const Sock &sock) |
| Try to read a specified number of bytes from a socket. More... | |
| static std::string | Socks5ErrorString (uint8_t err) |
| Convert SOCKS5 reply to an error message. More... | |
| bool | Socks5 (const std::string &strDest, uint16_t port, const ProxyCredentials *auth, const Sock &sock) |
| Connect to a specified destination service through an already connected SOCKS5 proxy. More... | |
| std::unique_ptr< Sock > | CreateSockTCP (const CService &address_family) |
| Create a TCP socket in the given address family. More... | |
| template<typename... Args> | |
| static void | LogConnectFailure (bool manual_connection, const char *fmt, const Args &... args) |
| bool | ConnectSocketDirectly (const CService &addrConnect, const Sock &sock, int nTimeout, bool manual_connection) |
| Try to connect to the specified service on the specified socket. More... | |
| bool | SetProxy (enum Network net, const Proxy &addrProxy) |
| bool | GetProxy (enum Network net, Proxy &proxyInfoOut) |
| bool | SetNameProxy (const Proxy &addrProxy) |
| Set the name proxy to use for all connections to nodes specified by a hostname. More... | |
| bool | GetNameProxy (Proxy &nameProxyOut) |
| bool | HaveNameProxy () |
| bool | IsProxy (const CNetAddr &addr) |
| bool | ConnectThroughProxy (const Proxy &proxy, const std::string &strDest, uint16_t port, const Sock &sock, int nTimeout, bool &outProxyConnectionFailed) |
| Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 proxy. More... | |
| bool | LookupSubNet (const std::string &subnet_str, CSubNet &subnet_out) |
| Parse and resolve a specified subnet string into the appropriate internal representation. More... | |
| void | InterruptSocks5 (bool interrupt) |
| bool | IsBadPort (uint16_t port) |
| Determine if a port is "bad" from the perspective of attempting to connect to a node on that port. More... | |
| CService | MaybeFlipIPv6toCJDNS (const CService &service) |
| If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is reachable (-cjdnsreachable config is set), then change the type from NET_IPV6 to NET_CJDNS. More... | |
Variables | |
| static GlobalMutex | g_proxyinfo_mutex |
| int | nConnectTimeout = DEFAULT_CONNECT_TIMEOUT |
| bool | fNameLookup = DEFAULT_NAME_LOOKUP |
| std::chrono::milliseconds | g_socks5_recv_timeout = 20s |
| ReachableNets | g_reachable_nets |
| DNSLookupFn | g_dns_lookup {WrappedGetAddrInfo} |
| std::function< std::unique_ptr< Sock >const CService &)> | CreateSock = CreateSockTCP |
| Socket factory. More... | |
|
strong |
Status codes that can be returned by InterruptibleRecv.
| Enumerator | |
|---|---|
| OK | |
| Timeout | |
| Disconnected | |
| NetworkError | |
| Interrupted | |
Definition at line 253 of file netbase.cpp.
| enum SOCKS5Atyp : uint8_t |
Values defined for ATYPE in RFC1928.
| Enumerator | |
|---|---|
| IPV4 | |
| DOMAINNAME | |
| IPV6 | |
Definition at line 246 of file netbase.cpp.
| enum SOCKS5Command : uint8_t |
Values defined for CMD in RFC1928.
| Enumerator | |
|---|---|
| CONNECT | |
| BIND | |
| UDP_ASSOCIATE | |
Definition at line 226 of file netbase.cpp.
| enum SOCKS5Method : uint8_t |
Values defined for METHOD in RFC1928.
| Enumerator | |
|---|---|
| NOAUTH | No authentication required. |
| GSSAPI | GSSAPI. |
| USER_PASS | Username/password. |
| NO_ACCEPTABLE | No acceptable methods. |
Definition at line 218 of file netbase.cpp.
| enum SOCKS5Reply : uint8_t |
Values defined for REP in RFC1928.
Definition at line 233 of file netbase.cpp.
| enum SOCKSVersion : uint8_t |
| bool ConnectSocketDirectly | ( | const CService & | addrConnect, |
| const Sock & | sock, | ||
| int | nTimeout, | ||
| bool | manual_connection | ||
| ) |
Try to connect to the specified service on the specified socket.
| addrConnect | The service to which to connect. |
| sock | The socket on which to connect. |
| nTimeout | Wait this many milliseconds for the connection to be established. |
| manual_connection | Whether or not the connection was manually requested (e.g. through the addnode RPC) |
Definition at line 514 of file netbase.cpp.
| bool ConnectThroughProxy | ( | const Proxy & | proxy, |
| const std::string & | strDest, | ||
| uint16_t | port, | ||
| const Sock & | sock, | ||
| int | nTimeout, | ||
| bool & | outProxyConnectionFailed | ||
| ) |
Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 proxy.
| proxy | The SOCKS5 proxy. | |
| strDest | The destination service to which to connect. | |
| port | The destination port. | |
| sock | The socket on which to connect to the SOCKS5 proxy. | |
| nTimeout | Wait this many milliseconds for the connection to the SOCKS5 proxy to be established. | |
| [out] | outProxyConnectionFailed | Whether or not the connection to the SOCKS5 proxy failed. |
Definition at line 625 of file netbase.cpp.
Create a TCP socket in the given address family.
| [in] | address_family | The socket is created in the same address family as this address. |
Definition at line 453 of file netbase.cpp.
| bool GetNameProxy | ( | Proxy & | nameProxyOut | ) |
| std::string GetNetworkName | ( | enum Network | net | ) |
Definition at line 99 of file netbase.cpp.
| std::vector<std::string> GetNetworkNames | ( | bool | append_unroutable = false | ) |
Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE.
Definition at line 115 of file netbase.cpp.
Definition at line 586 of file netbase.cpp.
|
static |
| bool HaveNameProxy | ( | ) |
|
static |
Try to read a specified number of bytes from a socket.
Please read the "see also" section for more detail.
| data | The buffer where the read bytes should be stored. |
| len | The number of bytes to read into the specified buffer. |
| timeout | The total timeout for this read. |
| sock | The socket (has to be in non-blocking mode) from which to read bytes. |
Definition at line 277 of file netbase.cpp.
| void InterruptSocks5 | ( | bool | interrupt | ) |
Definition at line 684 of file netbase.cpp.
|
static |
| bool IsBadPort | ( | uint16_t | port | ) |
Determine if a port is "bad" from the perspective of attempting to connect to a node on that port.
| [in] | port | Port to check. |
Definition at line 689 of file netbase.cpp.
| bool IsProxy | ( | const CNetAddr & | addr | ) |
Definition at line 616 of file netbase.cpp.
|
static |
Definition at line 505 of file netbase.cpp.
| std::vector<CService> Lookup | ( | const std::string & | name, |
| uint16_t | portDefault, | ||
| bool | fAllowLookup, | ||
| unsigned int | nMaxSolutions, | ||
| DNSLookupFn | dns_lookup_function = g_dns_lookup |
||
| ) |
Resolve a service string to its corresponding service.
| name | The 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 uint16_t port number. (e.g. example.com:8333 or |
| portDefault | The default port for resulting services if not specified by the service string. |
| fAllowLookup | Whether or not hostname lookups are permitted. If yes, external queries may be performed. |
| nMaxSolutions | The maximum number of results we want, specifying 0 means "as many solutions as we get." |
Definition at line 176 of file netbase.cpp.
| std::optional<CService> Lookup | ( | const std::string & | name, |
| uint16_t | portDefault, | ||
| bool | fAllowLookup, | ||
| DNSLookupFn | dns_lookup_function = g_dns_lookup |
||
| ) |
Resolve a service string to its first corresponding service.
Definition at line 194 of file netbase.cpp.
| std::vector<CNetAddr> LookupHost | ( | const std::string & | name, |
| unsigned int | nMaxSolutions, | ||
| bool | fAllowLookup, | ||
| DNSLookupFn | dns_lookup_function = g_dns_lookup |
||
| ) |
Resolve a host string to its corresponding network addresses.
| name | The string representing a host. Could be a name or a numerical IP address (IPv6 addresses in their bracketed form are allowed). |
Definition at line 158 of file netbase.cpp.
| std::optional<CNetAddr> LookupHost | ( | const std::string & | name, |
| bool | fAllowLookup, | ||
| DNSLookupFn | dns_lookup_function = g_dns_lookup |
||
| ) |
Resolve a host string to its first corresponding network address.
Definition at line 170 of file netbase.cpp.
|
static |
Definition at line 129 of file netbase.cpp.
| CService LookupNumeric | ( | const std::string & | name, |
| uint16_t | portDefault = 0, |
||
| DNSLookupFn | dns_lookup_function = g_dns_lookup |
||
| ) |
Resolve a service string with a numeric IP to its first corresponding service.
Definition at line 201 of file netbase.cpp.
| bool LookupSubNet | ( | const std::string & | subnet_str, |
| CSubNet & | subnet_out | ||
| ) |
Parse and resolve a specified subnet string into the appropriate internal representation.
| [in] | subnet_str | A 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". |
| [out] | subnet_out | Internal subnet representation, if parsable/resolvable from subnet_str. |
Definition at line 648 of file netbase.cpp.
If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is reachable (-cjdnsreachable config is set), then change the type from NET_IPV6 to NET_CJDNS.
| [in] | service | Address to potentially convert. |
service either unmodified or changed to CJDNS. Definition at line 779 of file netbase.cpp.
| enum Network ParseNetwork | ( | const std::string & | net_in | ) |
Definition at line 81 of file netbase.cpp.
| bool SetNameProxy | ( | const Proxy & | 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.
Definition at line 595 of file netbase.cpp.
Definition at line 577 of file netbase.cpp.
| bool Socks5 | ( | const std::string & | strDest, |
| uint16_t | port, | ||
| const ProxyCredentials * | auth, | ||
| const Sock & | socket | ||
| ) |
Connect to a specified destination service through an already connected SOCKS5 proxy.
| strDest | The destination fully-qualified domain name. |
| port | The destination port. |
| auth | The credentials with which to authenticate with the specified SOCKS5 proxy. |
| socket | The SOCKS5 proxy socket. |
Definition at line 334 of file netbase.cpp.
|
static |
Convert SOCKS5 reply to an error message.
Definition at line 310 of file netbase.cpp.
| std::vector<CNetAddr> WrappedGetAddrInfo | ( | const std::string & | name, |
| bool | allow_lookup | ||
| ) |
Wrapper for getaddrinfo(3).
Do not use directly: call Lookup/LookupHost/LookupNumeric/LookupSubNet.
Definition at line 37 of file netbase.cpp.
| std::function<std::unique_ptr<Sock>const CService&)> CreateSock = CreateSockTCP |
Socket factory.
Defaults to CreateSockTCP(), but can be overridden by unit tests.
Definition at line 502 of file netbase.cpp.
| bool fNameLookup = DEFAULT_NAME_LOOKUP |
Definition at line 29 of file netbase.cpp.
| DNSLookupFn g_dns_lookup {WrappedGetAddrInfo} |
Definition at line 79 of file netbase.cpp.
|
static |
Definition at line 25 of file netbase.cpp.
| ReachableNets g_reachable_nets |
Definition at line 35 of file netbase.cpp.
| std::chrono::milliseconds g_socks5_recv_timeout = 20s |
Definition at line 32 of file netbase.cpp.
| int nConnectTimeout = DEFAULT_CONNECT_TIMEOUT |
Definition at line 28 of file netbase.cpp.
1.8.14