Bitcoin Core 28.99.0
P2P Digital Currency
|
#include <compat/compat.h>
#include <netaddress.h>
#include <serialize.h>
#include <util/sock.h>
#include <util/threadinterrupt.h>
#include <functional>
#include <memory>
#include <stdint.h>
#include <string>
#include <type_traits>
#include <unordered_set>
#include <vector>
Go to the source code of this file.
Classes | |
class | Proxy |
struct | ProxyCredentials |
Credentials for proxy authentication. More... | |
class | ReachableNets |
List of reachable networks. More... | |
Typedefs | |
using | DNSLookupFn = std::function< std::vector< CNetAddr >(const std::string &, bool)> |
Enumerations | |
enum class | ConnectionDirection { None = 0 , In = (1U << 0) , Out = (1U << 1) , Both = (In | Out) } |
Functions | |
static ConnectionDirection & | operator|= (ConnectionDirection &a, ConnectionDirection b) |
static bool | operator& (ConnectionDirection a, ConnectionDirection b) |
bool | IsUnixSocketPath (const std::string &name) |
Check if a string is a valid UNIX domain socket path. More... | |
std::vector< CNetAddr > | WrappedGetAddrInfo (const std::string &name, bool allow_lookup) |
Wrapper for getaddrinfo(3). More... | |
enum Network | ParseNetwork (const std::string &net) |
std::string | GetNetworkName (enum Network net) |
std::vector< std::string > | GetNetworkNames (bool append_unroutable=false) |
Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE. More... | |
bool | SetProxy (enum Network net, const Proxy &addrProxy) |
bool | GetProxy (enum Network net, Proxy &proxyInfoOut) |
bool | IsProxy (const CNetAddr &addr) |
bool | SetNameProxy (const Proxy &addrProxy) |
Set the name proxy to use for all connections to nodes specified by a hostname. More... | |
bool | HaveNameProxy () |
bool | GetNameProxy (Proxy &nameProxyOut) |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
CSubNet | LookupSubNet (const std::string &subnet_str) |
Parse and resolve a specified subnet string into the appropriate internal representation. More... | |
std::unique_ptr< Sock > | CreateSockOS (int domain, int type, int protocol) |
Create a real socket from the operating system. More... | |
std::unique_ptr< Sock > | ConnectDirectly (const CService &dest, bool manual_connection) |
Create a socket and try to connect to the specified service. More... | |
std::unique_ptr< Sock > | ConnectThroughProxy (const Proxy &proxy, const std::string &dest, uint16_t port, bool &proxy_connection_failed) |
Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 proxy. More... | |
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. More... | |
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 | |
int | nConnectTimeout |
bool | fNameLookup |
static const int | DEFAULT_CONNECT_TIMEOUT = 5000 |
-timeout default More... | |
static const int | DEFAULT_NAME_LOOKUP = true |
-dns default More... | |
const std::string | ADDR_PREFIX_UNIX = "unix:" |
Prefix for unix domain socket addresses (which are local filesystem paths) More... | |
ReachableNets | g_reachable_nets |
DNSLookupFn | g_dns_lookup |
std::function< std::unique_ptr< Sock >(int, int, int)> | CreateSock |
Socket factory. More... | |
CThreadInterrupt | g_socks5_interrupt |
Interrupt SOCKS5 reads or writes. More... | |
using DNSLookupFn = std::function<std::vector<CNetAddr>(const std::string&, bool)> |
|
strong |
Create a socket and try to connect to the specified service.
[in] | dest | The service to which to connect. |
[in] | manual_connection | Whether or not the connection was manually requested (e.g. through the addnode RPC) |
Definition at line 625 of file netbase.cpp.
std::unique_ptr< Sock > ConnectThroughProxy | ( | const Proxy & | proxy, |
const std::string & | dest, | ||
uint16_t | port, | ||
bool & | proxy_connection_failed | ||
) |
Connect to a specified destination service through a SOCKS5 proxy by first connecting to the SOCKS5 proxy.
[in] | proxy | The SOCKS5 proxy. |
[in] | dest | The destination service to which to connect. |
[in] | port | The destination port. |
[out] | proxy_connection_failed | Whether or not the connection to the SOCKS5 proxy failed. |
Definition at line 728 of file netbase.cpp.
std::unique_ptr< Sock > CreateSockOS | ( | int | domain, |
int | type, | ||
int | protocol | ||
) |
Create a real socket from the operating system.
[in] | domain | Communications domain, first argument to the socket(2) syscall. |
[in] | type | Type of the socket, second argument to the socket(2) syscall. |
[in] | protocol | The particular protocol to be used with the socket, third argument to the socket(2) syscall. |
Definition at line 502 of file netbase.cpp.
bool GetNameProxy | ( | Proxy & | nameProxyOut | ) |
std::string GetNetworkName | ( | enum Network | net | ) |
Definition at line 118 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 134 of file netbase.cpp.
Definition at line 689 of file netbase.cpp.
bool HaveNameProxy | ( | ) |
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 792 of file netbase.cpp.
bool IsProxy | ( | const CNetAddr & | addr | ) |
Definition at line 719 of file netbase.cpp.
bool IsUnixSocketPath | ( | const std::string & | name | ) |
Check if a string is a valid UNIX domain socket path.
name | The string provided by the user representing a local path |
Definition at line 230 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 213 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 195 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 189 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 177 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 220 of file netbase.cpp.
CSubNet LookupSubNet | ( | const std::string & | subnet_str | ) |
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". |
Definition at line 756 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 563 of file netbase.cpp.
|
inlinestatic |
|
inlinestatic |
enum Network ParseNetwork | ( | const std::string & | net | ) |
Definition at line 100 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 698 of file netbase.cpp.
Definition at line 680 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 372 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 45 of file netbase.cpp.
const std::string ADDR_PREFIX_UNIX = "unix:" |
|
extern |
Socket factory.
Defaults to CreateSockOS()
, but can be overridden by unit tests.
Definition at line 557 of file netbase.cpp.
|
static |
|
extern |
Definition at line 37 of file netbase.cpp.
|
extern |
Definition at line 98 of file netbase.cpp.
|
extern |
Definition at line 43 of file netbase.cpp.
|
extern |
Interrupt SOCKS5 reads or writes.
Definition at line 41 of file netbase.cpp.
|
extern |
Definition at line 36 of file netbase.cpp.