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.
501auto flags = label->textInteractionFlags();502label->setTextInteractionFlags(Qt::NoTextInteraction);503label->setTextInteractionFlags(flags);504}505}506}508return QObject::eventFilter(watched, event);509}511#ifdef WIN32512fs::path static StartupShortcutPath()513{514ChainType chain = gArgs.GetChainType();515if (chain == ChainType::MAIN)516return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin.lnk";517if (chain == ChainType::TESTNET) // Remove this special case when testnet CBaseChainParams::DataDir() is incremented to "testnet4"518return GetSpecialFolderPath(CSIDL_STARTUP) / "Bitcoin (testnet).lnk";519return GetSpecialFolderPath(CSIDL_STARTUP) / fs::u8path(strprintf("Bitcoin (%s).lnk", ChainTypeToString(chain)));520}522bool GetStartOnSystemStartup()523{524// check for Bitcoin*.lnk525return fs::exists(StartupShortcutPath());526}528bool SetStartOnSystemStartup(bool fAutoStart)529{530// If the shortcut exists already, remove it for updating531fs::remove(StartupShortcutPath());533if (fAutoStart)534{535CoInitialize(nullptr);537// Get a pointer to the IShellLink interface.538IShellLinkW* psl = nullptr;539HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,540CLSCTX_INPROC_SERVER, IID_IShellLinkW,541reinterpret_cast<void**>(&psl));543if (SUCCEEDED(hres))544{545// Get the current executable path546WCHAR pszExePath[MAX_PATH];547GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));549// Start client minimized550QString strArgs = "-min";551// Set -testnet /-regtest options552strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainTypeString()));554// Set the path to the shortcut target555psl->SetPath(pszExePath);556PathRemoveFileSpecW(pszExePath);557psl->SetWorkingDirectory(pszExePath);558psl->SetShowCmd(SW_SHOWMINNOACTIVE);559psl->SetArguments(strArgs.toStdWString().c_str());561// Query IShellLink for the IPersistFile interface for562// saving the shortcut in persistent storage.563IPersistFile* ppf = nullptr;564hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));565if (SUCCEEDED(hres))566{567// Save the link by calling IPersistFile::Save.568hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);569ppf->Release();570psl->Release();571CoUninitialize();572return true;573}574psl->Release();575}576CoUninitialize();577return false;578}579return true;580}581#elif defined(Q_OS_LINUX)583// Follow the Desktop Application Autostart Spec:584// https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html586fs::path static GetAutostartDir()587{588char* pszConfigHome = getenv("XDG_CONFIG_HOME");589if (pszConfigHome) return fs::path(pszConfigHome) / "autostart";590char* pszHome = getenv("HOME");591if (pszHome) return fs::path(pszHome) / ".config" / "autostart";592return fs::path();593}595fs::path static GetAutostartFilePath()596{597ChainType chain = gArgs.GetChainType();598if (chain == ChainType::MAIN)599return GetAutostartDir() / "bitcoin.desktop";600return GetAutostartDir() / fs::u8path(strprintf("bitcoin-%s.desktop", ChainTypeToString(chain)));601}603bool GetStartOnSystemStartup()604{605std::ifstream optionFile{GetAutostartFilePath().std_path()};606if (!optionFile.good())607return false;608// Scan through file for "Hidden=true":609std::string line;610while (!optionFile.eof())611{612getline(optionFile, line);613if (line.find("Hidden") != std::string::npos &&614line.find("true") != std::string::npos)615return false;616}617optionFile.close();619return true;620}622bool SetStartOnSystemStartup(bool fAutoStart)623{624if (!fAutoStart)625fs::remove(GetAutostartFilePath());626else627{628char pszExePath[MAX_PATH+1];629ssize_t r = readlink("/proc/self/exe", pszExePath, sizeof(pszExePath));630if (r == -1 || r > MAX_PATH) {631return false;632}633pszExePath[r] = '\0';635fs::create_directories(GetAutostartDir());637std::ofstream optionFile{GetAutostartFilePath().std_path(), std::ios_base::out | std::ios_base::trunc};638if (!optionFile.good())639return false;640ChainType chain = gArgs.GetChainType();641// Write a bitcoin.desktop file to the autostart directory:642optionFile << "[Desktop Entry]\n";643optionFile << "Type=Application\n";644if (chain == ChainType::MAIN)645optionFile << "Name=Bitcoin\n";646else647optionFile << strprintf("Name=Bitcoin (%s)\n", ChainTypeToString(chain));648optionFile << "Exec=" << pszExePath << strprintf(" -min -chain=%s\n", ChainTypeToString(chain));649optionFile << "Terminal=false\n";650optionFile << "Hidden=false\n";651optionFile.close();652}653return true;654}656#else658bool GetStartOnSystemStartup() { return false; }659bool SetStartOnSystemStartup(bool fAutoStart) { return false; }661#endif663void setClipboard(const QString& str)664{665QClipboard* clipboard = QApplication::clipboard();666clipboard->setText(str, QClipboard::Clipboard);667if (clipboard->supportsSelection()) {668clipboard->setText(str, QClipboard::Selection);669}670}672fs::path QStringToPath(const QString &path)673{674return fs::u8path(path.toStdString());675}677QString PathToQString(const fs::path &path)678{679return QString::fromStdString(path.utf8string());680}682QString NetworkToQString(Network net)683{684switch (net) {685case NET_UNROUTABLE: return QObject::tr("Unroutable");686//: Name of IPv4 network in peer info687case NET_IPV4: return QObject::tr("IPv4", "network name");688//: Name of IPv6 network in peer info689case NET_IPV6: return QObject::tr("IPv6", "network name");690//: Name of Tor network in peer info691case NET_ONION: return QObject::tr("Onion", "network name");692//: Name of I2P network in peer info693case NET_I2P: return QObject::tr("I2P", "network name");694//: Name of CJDNS network in peer info695case NET_CJDNS: return QObject::tr("CJDNS", "network name");696case NET_INTERNAL: return "Internal"; // should never actually happen697case NET_MAX: assert(false);698} // no default case, so the compiler can warn about missing cases699assert(false);700}702QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)703{704QString prefix;705if (prepend_direction) {706prefix = (conn_type == ConnectionType::INBOUND) ?707/*: An inbound connection from a peer. An inbound connection708is a connection initiated by a peer. */709QObject::tr("Inbound") :710/*: An outbound connection to a peer. An outbound connection711is a connection initiated by us. */712QObject::tr("Outbound") + " ";713}714switch (conn_type) {715case ConnectionType::INBOUND: return prefix;716//: Peer connection type that relays all network information.717case ConnectionType::OUTBOUND_FULL_RELAY: return prefix + QObject::tr("Full Relay");718/*: Peer connection type that relays network information about719blocks and not transactions or addresses. */720case ConnectionType::BLOCK_RELAY: return prefix + QObject::tr("Block Relay");721//: Peer connection type established manually through one of several methods.722case ConnectionType::MANUAL: return prefix + QObject::tr("Manual");723//: Short-lived peer connection type that tests the aliveness of known addresses.724case ConnectionType::FEELER: return prefix + QObject::tr("Feeler");725//: Short-lived peer connection type that solicits known addresses from a peer.726case ConnectionType::ADDR_FETCH: return prefix + QObject::tr("Address Fetch");727//: Short-lived peer connection type that is used for broadcasting privacy-sensitive data.728case ConnectionType::PRIVATE_BROADCAST: return prefix + QObject::tr("Private Broadcast");729} // no default case, so the compiler can warn about missing cases730assert(false);731}733QString formatDurationStr(std::chrono::nanoseconds dur)734{735const auto d{std::chrono::duration_cast<std::chrono::days>(dur)};736const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};737const auto m{std::chrono::duration_cast<std::chrono::minutes>(dur - d - h)};738const auto s{std::chrono::duration_cast<std::chrono::seconds>(dur - d - h - m)};739QStringList str_list;740if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));741if (auto h2{h.count()}) str_list.append(QObject::tr("%1 h").arg(h2));742if (auto m2{m.count()}) str_list.append(QObject::tr("%1 m").arg(m2));743const auto s2{s.count()};744if (s2 || str_list.empty()) str_list.append(QObject::tr("%1 s").arg(s2));745return str_list.join(" ");746}748QString FormatPeerAge(NodeClock::time_point connected)749{750const auto age{NodeClock::now() - connected};
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.