Skip to content

Commit

Permalink
Show I2P peer addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
glassez committed Apr 12, 2023
1 parent cd6753b commit 242f8e5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
21 changes: 20 additions & 1 deletion src/base/bittorrent/peerinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -33,6 +33,7 @@
#include "base/bittorrent/ltqbitarray.h"
#include "base/net/geoipmanager.h"
#include "base/unicodestrings.h"
#include "base/utils/bytearray.h"
#include "peeraddress.h"

using namespace BitTorrent;
Expand Down Expand Up @@ -168,13 +169,31 @@ bool PeerInfo::isPlaintextEncrypted() const

PeerAddress PeerInfo::address() const
{
if (useI2PSocket())
return {};

// fast path for platforms which boost.asio internal struct maps to `sockaddr`
return {QHostAddress(m_nativeInfo.ip.data()), m_nativeInfo.ip.port()};
// slow path for the others
//return {QHostAddress(QString::fromStdString(m_nativeInfo.ip.address().to_string()))
// , m_nativeInfo.ip.port()};
}

QString PeerInfo::I2PAddress() const
{
if (!useI2PSocket())
return {};

if (m_I2PAddress.isEmpty())
{
const lt::sha256_hash destHash = m_nativeInfo.i2p_destination();
const QByteArray base32Dest = Utils::ByteArray::toBase32({destHash.data(), destHash.size()}).replace('=', "").toLower();
m_I2PAddress = QString::fromLatin1(base32Dest) + u".b32.i2p";
}

return m_I2PAddress;
}

QString PeerInfo::client() const
{
return QString::fromStdString(m_nativeInfo.client);
Expand Down
4 changes: 3 additions & 1 deletion src/base/bittorrent/peerinfo.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015-2022 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -76,6 +76,7 @@ namespace BitTorrent
bool isPlaintextEncrypted() const;

PeerAddress address() const;
QString I2PAddress() const;
QString client() const;
QString peerIdClient() const;
qreal progress() const;
Expand All @@ -101,5 +102,6 @@ namespace BitTorrent
QString m_flagsDescription;

mutable QString m_country;
mutable QString m_I2PAddress;
};
}
7 changes: 2 additions & 5 deletions src/gui/properties/peerlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
// List Model
m_listModel = new QStandardItemModel(0, PeerListColumns::COL_COUNT, this);
m_listModel->setHeaderData(PeerListColumns::COUNTRY, Qt::Horizontal, tr("Country/Region")); // Country flag column
m_listModel->setHeaderData(PeerListColumns::IP, Qt::Horizontal, tr("IP"));
m_listModel->setHeaderData(PeerListColumns::IP, Qt::Horizontal, tr("IP/Address"));
m_listModel->setHeaderData(PeerListColumns::PORT, Qt::Horizontal, tr("Port"));
m_listModel->setHeaderData(PeerListColumns::FLAGS, Qt::Horizontal, tr("Flags"));
m_listModel->setHeaderData(PeerListColumns::CONNECTION, Qt::Horizontal, tr("Connection"));
Expand Down Expand Up @@ -434,9 +434,6 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
const bool hideZeroValues = Preferences::instance()->getHideZeroValues();
for (const BitTorrent::PeerInfo &peer : peers)
{
if (peer.address().ip.isNull())
continue;

const PeerEndpoint peerEndpoint {peer.address(), peer.connectionType()};

auto itemIter = m_peerItems.find(peerEndpoint);
Expand All @@ -448,7 +445,7 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)

const bool useI2PSocket = peer.useI2PSocket();

const QString peerIPString = useI2PSocket ? tr("N/A") : peerEndpoint.address.ip.toString();
const QString peerIPString = useI2PSocket ? peer.I2PAddress() : peerEndpoint.address.ip.toString();
setModelData(m_listModel, row, PeerListColumns::IP, peerIPString, peerIPString, {}, peerIPString);

const QString peerIPHiddenString = useI2PSocket ? QString() : peerEndpoint.address.ip.toString();
Expand Down

0 comments on commit 242f8e5

Please sign in to comment.