mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
Update listening status using native session extension
This commit is contained in:
parent
bdd56a52d3
commit
bac57de5f5
@ -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)
|
||||
{
|
||||
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)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NativeSessionExtension::handleSessionStatsAlert([[maybe_unused]] const lt::session_stats_alert *alert)
|
||||
{
|
||||
const QWriteLocker locker {&m_lock};
|
||||
m_isSesssionListening = m_nativeSession.is_listening();
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -1498,7 +1498,9 @@ void SessionImpl::initializeNativeSession()
|
||||
if (isPeXEnabled())
|
||||
m_nativeSession->add_extension(<::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)
|
||||
|
||||
bool SessionImpl::isListening() const
|
||||
{
|
||||
return m_nativeSession->is_listening();
|
||||
return m_nativeSessionExtension->isSessionListening();
|
||||
}
|
||||
|
||||
MaxRatioAction SessionImpl::maxRatioAction() const
|
||||
|
@ -65,6 +65,7 @@ class QUrl;
|
||||
class BandwidthScheduler;
|
||||
class FileSearcher;
|
||||
class FilterParserThread;
|
||||
class NativeSessionExtension;
|
||||
|
||||
namespace Net
|
||||
{
|
||||
@ -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…
x
Reference in New Issue
Block a user