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.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/peertablesortproxy.h>7#include <qt/peertablemodel.h>8#include <util/check.h>10#include <QModelIndex>11#include <QString>12#include <QVariant>14PeerTableSortProxy::PeerTableSortProxy(QObject* parent)15: QSortFilterProxyModel(parent)16{17}19bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelIndex& right_index) const20{21const CNodeStats left_stats = Assert(sourceModel()->data(left_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;22const CNodeStats right_stats = Assert(sourceModel()->data(right_index, PeerTableModel::StatsRole).value<CNodeCombinedStats*>())->nodeStats;24switch (static_cast<PeerTableModel::ColumnIndex>(left_index.column())) {25case PeerTableModel::NetNodeId:26return left_stats.nodeid < right_stats.nodeid;27case PeerTableModel::Age:28return left_stats.m_connected > right_stats.m_connected;29case PeerTableModel::Address:30return left_stats.m_addr_name.compare(right_stats.m_addr_name) < 0;31case PeerTableModel::Direction:32return left_stats.fInbound > right_stats.fInbound; // default sort Inbound, then Outbound33case PeerTableModel::ConnectionType:34return left_stats.m_conn_type < right_stats.m_conn_type;35case PeerTableModel::Network:36return left_stats.m_network < right_stats.m_network;37case PeerTableModel::Ping:38return left_stats.m_min_ping_time < right_stats.m_min_ping_time;39case PeerTableModel::Sent:40return left_stats.nSendBytes < right_stats.nSendBytes;41case PeerTableModel::Received:42return left_stats.nRecvBytes < right_stats.nRecvBytes;43case PeerTableModel::Subversion:44return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;45} // no default case, so the compiler can warn about missing cases46assert(false);47}
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.