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.
1751* attempt to make block-relay-only connections to them.1752*/1753std::vector<CAddress> m_anchors;1755/** SipHasher seeds for deterministic randomness */1756const uint64_t nSeed0, nSeed1;1758/** flag for waking the message processor. */1759bool fMsgProcWake GUARDED_BY(mutexMsgProc);1761std::condition_variable condMsgProc;1762Mutex mutexMsgProc;1763std::atomic<bool> flagInterruptMsgProc{false};1765/**1766* This is signaled when network activity should cease.1767* A copy of this is saved in `m_i2p_sam_session`.1768*/1769const std::shared_ptr<CThreadInterrupt> m_interrupt_net;1771/**1772* I2P SAM session.1773* Used to accept incoming and make outgoing I2P connections from a persistent1774* address.1775*/1776std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;1778std::thread threadDNSAddressSeed;1779std::thread threadSocketHandler;1780std::thread threadOpenAddedConnections;1781std::thread threadOpenConnections;1782std::thread threadMessageHandler;1783std::thread threadI2PAcceptIncoming;1784std::thread threadPrivateBroadcast;1786/** flag for deciding to connect to an extra outbound peer,1787* in excess of m_max_outbound_full_relay1788* This takes the place of a feeler connection */1789std::atomic_bool m_try_another_outbound_peer;1791/** flag for initiating extra block-relay-only peer connections.1792* this should only be enabled after initial chain sync has occurred,1793* as these connections are intended to be short-lived and low-bandwidth.1794*/1795std::atomic_bool m_start_extra_block_relay_peers{false};1797/**1798* A vector of -bind=<address>:<port>=onion arguments each of which is1799* an address and port that are designated for incoming Tor connections.1800*/1801std::vector<CService> m_onion_binds;1803/**1804* flag for adding 'forcerelay' permission to whitelisted inbound1805* and manual peers with default permissions.1806*/1807bool whitelist_forcerelay;1809/**1810* flag for adding 'relay' permission to whitelisted inbound1811* and manual peers with default permissions.1812*/1813bool whitelist_relay;1815/**1816* flag for whether messages are captured1817*/1818bool m_capture_messages{false};1820/**1821* Mutex protecting m_i2p_sam_sessions.1822*/1823Mutex m_unused_i2p_sessions_mutex;1825/**1826* A pool of created I2P SAM transient sessions that should be used instead1827* of creating new ones in order to reduce the load on the I2P network.1828* Creating a session in I2P is not cheap, thus if this is not empty, then1829* pick an entry from it instead of creating a new session. If connecting to1830* a host fails, then the created session is put to this pool for reuse.1831*/1832std::queue<std::unique_ptr<i2p::sam::Session>> m_unused_i2p_sessions GUARDED_BY(m_unused_i2p_sessions_mutex);1834/**1835* Mutex protecting m_reconnections.1836*/1837Mutex m_reconnections_mutex;1839/** Struct for entries in m_reconnections. */1840struct ReconnectionInfo1841{1842std::optional<Proxy> proxy_override;1843CAddress addr_connect;1844CountingSemaphoreGrant<> grant;1845std::string destination;1846ConnectionType conn_type;1847bool use_v2transport;1848};1850/**1851* List of reconnections we have to make.1852*/1853std::list<ReconnectionInfo> m_reconnections GUARDED_BY(m_reconnections_mutex);1855/** Attempt reconnections, if m_reconnections non-empty. */1856void PerformReconnections()1857EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex, !m_reconnections_mutex, !m_unused_i2p_sessions_mutex);1859/**1860* Cap on the size of `m_unused_i2p_sessions`, to ensure it does not1861* unexpectedly use too much memory.1862*/1863static constexpr size_t MAX_UNUSED_I2P_SESSIONS_SIZE{10};1865/**1866* RAII helper to atomically create a copy of `m_nodes` and add a reference1867* to each of the nodes. The nodes are released when this object is destroyed.1868*/1869class NodesSnapshot1870{1871public:1872explicit NodesSnapshot(const CConnman& connman, bool shuffle)1873EXCLUSIVE_LOCKS_REQUIRED(!connman.m_nodes_mutex)1874{1875{1876LOCK(connman.m_nodes_mutex);1877m_nodes_copy = connman.m_nodes;1878for (auto& node : m_nodes_copy) {1879node->AddRef();1880}1881}1882if (shuffle) {1883std::shuffle(m_nodes_copy.begin(), m_nodes_copy.end(), FastRandomContext{});1884}1885}1887~NodesSnapshot()1888{1889for (auto& node : m_nodes_copy) {1890node->Release();1891}1892}1894const std::vector<CNode*>& Nodes() const1895{1896return m_nodes_copy;1897}1899private:1900std::vector<CNode*> m_nodes_copy;1901};1903const CChainParams& m_params;1905friend struct ConnmanTestMsg;1906};1908/** Defaults to `CaptureMessageToFile()`, but can be overridden by unit tests. */1909extern std::function<void(const CAddress& addr,1910const std::string& msg_type,1911std::span<const unsigned char> data,1912bool is_incoming)>1913CaptureMessage;1915#endif // BITCOIN_NET_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.