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.
4251break;4252}4253}4254return found != nullptr && NodeFullyConnected(found) && func(found);4255}4257CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const4258{4259return CSipHasher(nSeed0, nSeed1).Write(id);4260}4262uint64_t CConnman::CalculateKeyedNetGroup(const CNetAddr& address) const4263{4264std::vector<unsigned char> vchNetGroup(m_netgroupman.GetGroup(address));4266return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup).Finalize();4267}4269void CConnman::PerformReconnections()4270{4271AssertLockNotHeld(m_nodes_mutex);4272AssertLockNotHeld(m_reconnections_mutex);4273AssertLockNotHeld(m_unused_i2p_sessions_mutex);4274while (true) {4275// Move first element of m_reconnections to todo (avoiding an allocation inside the lock).4276decltype(m_reconnections) todo;4277{4278LOCK(m_reconnections_mutex);4279if (m_reconnections.empty()) break;4280todo.splice(todo.end(), m_reconnections, m_reconnections.begin());4281}4283auto& item = *todo.begin();4284OpenNetworkConnection(item.addr_connect,4285// We only reconnect if the first attempt to connect succeeded at4286// connection time, but then failed after the CNode object was4287// created. Since we already know connecting is possible, do not4288// count failure to reconnect.4289/*fCountFailure=*/false,4290std::move(item.grant),4291item.destination.empty() ? nullptr : item.destination.c_str(),4292item.conn_type,4293item.use_v2transport,4294item.proxy_override);4295}4296}4298void CConnman::ASMapHealthCheck()4299{4300const std::vector<CAddress> v4_addrs{GetAddressesUnsafe(/*max_addresses=*/0, /*max_pct=*/0, Network::NET_IPV4, /*filtered=*/false)};4301const std::vector<CAddress> v6_addrs{GetAddressesUnsafe(/*max_addresses=*/0, /*max_pct=*/0, Network::NET_IPV6, /*filtered=*/false)};4302std::vector<CNetAddr> clearnet_addrs;4303clearnet_addrs.reserve(v4_addrs.size() + v6_addrs.size());4304std::transform(v4_addrs.begin(), v4_addrs.end(), std::back_inserter(clearnet_addrs),4305[](const CAddress& addr) { return static_cast<CNetAddr>(addr); });4306std::transform(v6_addrs.begin(), v6_addrs.end(), std::back_inserter(clearnet_addrs),4307[](const CAddress& addr) { return static_cast<CNetAddr>(addr); });4308m_netgroupman.ASMapHealthCheck(clearnet_addrs);4309}4311// Dump binary message to file, with timestamp.4312static void CaptureMessageToFile(const CAddress& addr,4313const std::string& msg_type,4314std::span<const unsigned char> data,4315bool is_incoming)4316{4317// Note: This function captures the message at the time of processing,4318// not at socket receive/send time.4319// This ensures that the messages are always in order from an application4320// layer (processing) perspective.4321auto now = GetTime<std::chrono::microseconds>();4323// Windows folder names cannot include a colon4324std::string clean_addr = addr.ToStringAddrPort();4325std::replace(clean_addr.begin(), clean_addr.end(), ':', '_');4327fs::path base_path = gArgs.GetDataDirNet() / "message_capture" / fs::u8path(clean_addr);4328fs::create_directories(base_path);4330fs::path path = base_path / (is_incoming ? "msgs_recv.dat" : "msgs_sent.dat");4331AutoFile f{fsbridge::fopen(path, "ab")};4333ser_writedata64(f, now.count());4334f << std::span{msg_type};4335for (auto i = msg_type.length(); i < CMessageHeader::MESSAGE_TYPE_SIZE; ++i) {4336f << uint8_t{'\0'};4337}4338uint32_t size = data.size();4339ser_writedata32(f, size);4340f << data;4342if (f.fclose() != 0) {4343throw std::ios_base::failure(4344strprintf("Error closing %s after write, file contents are likely incomplete", fs::PathToString(path)));4345}4346}4348std::function<void(const CAddress& addr,4349const std::string& msg_type,4350std::span<const unsigned char> data,4351bool is_incoming)>4352CaptureMessage = CaptureMessageToFile;