5#ifndef BITCOIN_NETBASE_H
6#define BITCOIN_NETBASE_H
19#include <unordered_set>
40 using underlying =
typename std::underlying_type<ConnectionDirection>::type;
45 using underlying =
typename std::underlying_type<ConnectionDirection>::type;
46 return (underlying(a) & underlying(b));
88 std::unique_ptr<Sock>
Connect()
const;
107 m_reachable.insert(net);
114 m_reachable.erase(net);
128 return m_reachable.count(net) > 0;
168std::vector<std::string>
GetNetworkNames(
bool append_unroutable =
false);
192using DNSLookupFn = std::function<std::vector<CNetAddr>(
const std::string&,
bool)>;
239std::vector<CService>
Lookup(
const std::string&
name, uint16_t portDefault,
bool fAllowLookup,
unsigned int nMaxSolutions,
DNSLookupFn dns_lookup_function =
g_dns_lookup);
278std::unique_ptr<Sock>
CreateSockOS(
int domain,
int type,
int protocol);
283extern std::function<std::unique_ptr<Sock>(
int,
int,
int)>
CreateSock;
307 const std::string& dest,
309 bool& proxy_connection_failed);
A combination of a network address (CNetAddr) and a (TCP) port.
sa_family_t GetSAFamily() const
Get the address family.
std::string ToStringAddrPort() const
A helper class for interruptible sleeps.
Proxy(const CService &_proxy, bool _randomize_credentials=false)
std::string ToString() const
bool m_randomize_credentials
std::unique_ptr< Sock > Connect() const
sa_family_t GetFamily() const
Proxy(const std::string path, bool _randomize_credentials=false)
std::string m_unix_socket_path
List of reachable networks.
std::unordered_set< Network > All() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
void Add(Network net) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
bool Contains(Network net) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
void Remove(Network net) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
void RemoveAll() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
std::unordered_set< Network > m_reachable GUARDED_BY(m_mutex)
bool Contains(const CNetAddr &addr) const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
RAII helper class that manages a socket and closes it automatically when it goes out of scope.
@ NET_ONION
TOR (v2 or v3)
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
CSubNet LookupSubNet(const std::string &subnet_str)
Parse and resolve a specified subnet string into the appropriate internal representation.
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)
CThreadInterrupt g_socks5_interrupt
Interrupt SOCKS5 reads or writes.
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)
bool SetProxy(enum Network net, const Proxy &addrProxy)
CService MaybeFlipIPv6toCJDNS(const CService &service)
If an IPv6 address belongs to the address range used by the CJDNS network and the CJDNS network is re...
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::function< std::vector< CNetAddr >(const std::string &, bool)> DNSLookupFn
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.
ReachableNets g_reachable_nets
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)
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).
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.
#define AssertLockNotHeld(cs)
#define EXCLUSIVE_LOCKS_REQUIRED(...)