Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251* resolved.252*/253std::vector<CService> Lookup(const std::string& name, uint16_t portDefault, bool fAllowLookup, unsigned int nMaxSolutions, DNSLookupFn dns_lookup_function = g_dns_lookup);255/**256* Resolve a service string to its first corresponding service.257*258* @see Lookup(const std::string&, uint16_t, bool, unsigned int, DNSLookupFn)259* for additional parameter descriptions.260*/261std::optional<CService> Lookup(const std::string& name, uint16_t portDefault, bool fAllowLookup, DNSLookupFn dns_lookup_function = g_dns_lookup);263/**264* Resolve a service string with a numeric IP to its first corresponding265* service.266*267* @returns The resulting CService if the resolution was successful, [::]:0 otherwise.268*269* @see Lookup(const std::string&, uint16_t, bool, unsigned int, DNSLookupFn)270* for additional parameter descriptions.271*/272CService LookupNumeric(const std::string& name, uint16_t portDefault = 0, DNSLookupFn dns_lookup_function = g_dns_lookup);274/**275* Parse and resolve a specified subnet string into the appropriate internal276* representation.277*278* @param[in] subnet_str A string representation of a subnet of the form279* `network address [ "/", ( CIDR-style suffix | netmask ) ]`280* e.g. "2001:db8::/32", "192.0.2.0/255.255.255.0" or "8.8.8.8".281* @returns a CSubNet object (that may or may not be valid).282*/283CSubNet LookupSubNet(const std::string& subnet_str);285/**286* Create a real socket from the operating system.287* @param[in] domain Communications domain, first argument to the socket(2) syscall.288* @param[in] type Type of the socket, second argument to the socket(2) syscall.289* @param[in] protocol The particular protocol to be used with the socket, third argument to the socket(2) syscall.290* @return pointer to the created Sock object or unique_ptr that owns nothing in case of failure291*/292std::unique_ptr<Sock> CreateSockOS(int domain, int type, int protocol);294/**295* Socket factory. Defaults to `CreateSockOS()`, but can be overridden by unit tests.296*/297extern std::function<std::unique_ptr<Sock>(int, int, int)> CreateSock;299/**300* Create a socket and try to connect to the specified service.301*302* @param[in] dest The service to which to connect.303* @param[in] manual_connection Whether or not the connection was manually requested (e.g. through the addnode RPC)304*305* @returns the connected socket if the operation succeeded, empty unique_ptr otherwise306*/307std::unique_ptr<Sock> ConnectDirectly(const CService& dest, bool manual_connection);309/** Create a socket and try to connect to the specified service, using the provided timeout. */310std::unique_ptr<Sock> ConnectDirectly(const CService& dest,311bool manual_connection,312std::chrono::milliseconds timeout);314/**315* Connect to a specified destination service through a SOCKS5 proxy by first316* connecting to the SOCKS5 proxy.317*318* @param[in] proxy The SOCKS5 proxy.319* @param[in] dest The destination service to which to connect.320* @param[in] port The destination port.321* @param[out] proxy_connection_failed Whether or not the connection to the SOCKS5 proxy failed.322*323* @returns the connected socket if the operation succeeded. Otherwise an empty unique_ptr.324*/325std::unique_ptr<Sock> ConnectThroughProxy(const Proxy& proxy,326const std::string& dest,327uint16_t port,328bool& proxy_connection_failed);330/**331* Interrupt SOCKS5 reads or writes.332*/333extern CThreadInterrupt g_socks5_interrupt;335/**336* Connect to a specified destination service through an already connected337* SOCKS5 proxy.338*339* @param strDest The destination fully-qualified domain name.340* @param port The destination port.341* @param auth The credentials with which to authenticate with the specified342* SOCKS5 proxy.343* @param socket The SOCKS5 proxy socket.344*345* @returns Whether or not the operation succeeded.346*347* @note The specified SOCKS5 proxy socket must already be connected to the348* SOCKS5 proxy.349*350* @see <a href="https://www.ietf.org/rfc/rfc1928.txt">RFC1928: SOCKS Protocol351* Version 5</a>352*/353bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* auth, const Sock& socket);355/**356* Determine if a port is "bad" from the perspective of attempting to connect357* to a node on that port.358* @see doc/p2p-bad-ports.md359* @param[in] port Port to check.360* @returns whether the port is bad361*/362bool IsBadPort(uint16_t port);364/**365* If an IPv6 address belongs to the address range used by the CJDNS network and366* the CJDNS network is reachable (-cjdnsreachable config is set), then change367* the type from NET_IPV6 to NET_CJDNS.368* @param[in] service Address to potentially convert.369* @return a copy of `service` either unmodified or changed to CJDNS.370*/371CService MaybeFlipIPv6toCJDNS(const CService& service);373/** Get the bind address for a socket as CService. */374CService GetBindAddress(const Sock& sock);376#endif // BITCOIN_NETBASE_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.