Browse Source

Update listening status using native session extension

adaptive-webui-19844
Vladimir Golovnev (Glassez) 2 years ago
parent
commit
bac57de5f5
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 20
      src/base/bittorrent/nativesessionextension.cpp
  2. 16
      src/base/bittorrent/nativesessionextension.h
  3. 6
      src/base/bittorrent/sessionimpl.cpp
  4. 2
      src/base/bittorrent/sessionimpl.h

20
src/base/bittorrent/nativesessionextension.cpp

@ -62,6 +62,17 @@ namespace @@ -62,6 +62,17 @@ namespace
}
}
bool NativeSessionExtension::isSessionListening() const
{
const QReadLocker locker {&m_lock};
return m_isSesssionListening;
}
void NativeSessionExtension::added(const lt::session_handle &nativeSession)
{
m_nativeSession = nativeSession;
}
lt::feature_flags_t NativeSessionExtension::implemented_features()
{
return alert_feature;
@ -76,6 +87,9 @@ void NativeSessionExtension::on_alert(const lt::alert *alert) @@ -76,6 +87,9 @@ void NativeSessionExtension::on_alert(const lt::alert *alert)
{
switch (alert->type())
{
case lt::session_stats_alert::alert_type:
handleSessionStatsAlert(static_cast<const lt::session_stats_alert *>(alert));
break;
case lt::add_torrent_alert::alert_type:
handleAddTorrentAlert(static_cast<const lt::add_torrent_alert *>(alert));
break;
@ -86,3 +100,9 @@ void NativeSessionExtension::on_alert(const lt::alert *alert) @@ -86,3 +100,9 @@ void NativeSessionExtension::on_alert(const lt::alert *alert)
break;
}
}
void NativeSessionExtension::handleSessionStatsAlert([[maybe_unused]] const lt::session_stats_alert *alert)
{
const QWriteLocker locker {&m_lock};
m_isSesssionListening = m_nativeSession.is_listening();
}

16
src/base/bittorrent/nativesessionextension.h

@ -29,12 +29,28 @@ @@ -29,12 +29,28 @@
#pragma once
#include <libtorrent/extensions.hpp>
#include <libtorrent/fwd.hpp>
#include <libtorrent/session_handle.hpp>
#include <QReadWriteLock>
#include "extensiondata.h"
class NativeSessionExtension final : public lt::plugin
{
public:
bool isSessionListening() const;
private:
void added(const lt::session_handle &nativeSession) override;
lt::feature_flags_t implemented_features() override;
std::shared_ptr<lt::torrent_plugin> new_torrent(const lt::torrent_handle &torrentHandle, LTClientData clientData) override;
void on_alert(const lt::alert *alert) override;
void handleSessionStatsAlert(const lt::session_stats_alert *alert);
lt::session_handle m_nativeSession;
mutable QReadWriteLock m_lock;
bool m_isSesssionListening = false;
};

6
src/base/bittorrent/sessionimpl.cpp

@ -1498,7 +1498,9 @@ void SessionImpl::initializeNativeSession() @@ -1498,7 +1498,9 @@ void SessionImpl::initializeNativeSession()
if (isPeXEnabled())
m_nativeSession->add_extension(&lt::create_ut_pex_plugin);
m_nativeSession->add_extension(std::make_shared<NativeSessionExtension>());
auto nativeSessionExtension = std::make_shared<NativeSessionExtension>();
m_nativeSession->add_extension(nativeSessionExtension);
m_nativeSessionExtension = nativeSessionExtension.get();
}
void SessionImpl::processBannedIPs(lt::ip_filter &filter)
@ -4494,7 +4496,7 @@ void SessionImpl::setTrackerFilteringEnabled(const bool enabled) @@ -4494,7 +4496,7 @@ void SessionImpl::setTrackerFilteringEnabled(const bool enabled)
bool SessionImpl::isListening() const
{
return m_nativeSession->is_listening();
return m_nativeSessionExtension->isSessionListening();
}
MaxRatioAction SessionImpl::maxRatioAction() const

2
src/base/bittorrent/sessionimpl.h

@ -65,6 +65,7 @@ class QUrl; @@ -65,6 +65,7 @@ class QUrl;
class BandwidthScheduler;
class FileSearcher;
class FilterParserThread;
class NativeSessionExtension;
namespace Net
{
@ -549,6 +550,7 @@ namespace BitTorrent @@ -549,6 +550,7 @@ namespace BitTorrent
// BitTorrent
lt::session *m_nativeSession = nullptr;
NativeSessionExtension *m_nativeSessionExtension = nullptr;
bool m_deferredConfigureScheduled = false;
bool m_IPFilteringConfigured = false;

Loading…
Cancel
Save