5#ifndef BITCOIN_NETBASE_H
6#define BITCOIN_NETBASE_H
8#if defined(HAVE_CONFIG_H)
9#include <config/bitcoin-config.h>
46 using underlying =
typename std::underlying_type<ConnectionDirection>::type;
52 using underlying =
typename std::underlying_type<ConnectionDirection>::type;
53 return (underlying(a) & underlying(b));
70 explicit Proxy(
const CService &_proxy,
bool randomize_credentials =
false)
73 explicit Proxy(
const std::string path,
bool randomize_credentials =
false)
103 std::unique_ptr<Sock>
Connect()
const;
125std::vector<std::string>
GetNetworkNames(
bool append_unroutable =
false);
151 std::function<std::vector<CNetAddr>(
const std::string &,
bool)>;
181std::optional<CNetAddr>
203std::vector<CService>
Lookup(
const std::string &
name, uint16_t portDefault,
204 bool fAllowLookup,
unsigned int nMaxSolutions,
213std::optional<CService>
Lookup(
const std::string &
name, uint16_t portDefault,
255std::unique_ptr<Sock>
CreateSockOS(
int domain,
int type,
int protocol);
261extern std::function<std::unique_ptr<Sock>(
int,
int,
int)>
CreateSock;
274 bool manual_connection);
290 const std::string &dest,
292 bool &proxy_connection_failed);
296bool Socks5(
const std::string &strDest, uint16_t port,
A combination of a network address (CNetAddr) and a (TCP) port.
sa_family_t GetSAFamily() const
Get the address family.
std::string ToStringAddrPort() const
std::string ToString() const
bool m_randomize_credentials
std::unique_ptr< Sock > Connect() const
sa_family_t GetFamily() const
Proxy(const CService &_proxy, bool randomize_credentials=false)
Proxy(const std::string path, bool randomize_credentials=false)
std::string m_unix_socket_path
RAII helper class that manages a socket and closes it automatically when it goes out of scope.
std::unique_ptr< Sock > ConnectDirectly(const CService &dest, bool manual_connection)
Create a socket and try to connect to the specified service.
static const int DEFAULT_NAME_LOOKUP
-dns default
std::string GetNetworkName(enum Network net)
bool SetNameProxy(const Proxy &addrProxy)
Set the name proxy to use for all connections to nodes specified by a hostname.
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.
std::vector< std::string > GetNetworkNames(bool append_unroutable=false)
Return a vector of publicly routable Network names; optionally append NET_UNROUTABLE.
const std::string ADDR_PREFIX_UNIX
Prefix for unix domain socket addresses (which are local filesystem paths)
void InterruptSocks5(bool interrupt)
bool SetProxy(enum Network net, const Proxy &addrProxy)
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.
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.
std::unique_ptr< Sock > CreateSockOS(int domain, int type, int protocol)
Create a real socket from the operating system.
static bool operator&(ConnectionDirection a, ConnectionDirection b)
bool GetProxy(enum Network net, Proxy &proxyInfoOut)
bool LookupSubNet(const std::string &strSubnet, CSubNet &subnet, DNSLookupFn dns_lookup_function=g_dns_lookup)
Parse and resolve a specified subnet string into the appropriate internal representation.
static ConnectionDirection & operator|=(ConnectionDirection &a, ConnectionDirection b)
enum Network ParseNetwork(const std::string &net)
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 p...
std::function< std::unique_ptr< Sock >(int, int, int)> CreateSock
Socket factory.
bool IsUnixSocketPath(const std::string &name)
Check if a string is a valid UNIX domain socket path.
bool GetNameProxy(Proxy &nameProxyOut)
bool IsProxy(const CNetAddr &addr)
bool IsBadPort(uint16_t port)
Determine if a port is "bad" from the perspective of attempting to connect to a node on that port.
std::vector< CNetAddr > WrappedGetAddrInfo(const std::string &name, bool allow_lookup)
Wrapper for getaddrinfo(3).
std::function< std::vector< CNetAddr >(const std::string &, bool)> DNSLookupFn
static const int DEFAULT_CONNECT_TIMEOUT
-timeout default
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.
Credentials for proxy authentication.