Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libtorrent: Add handshake bind mount #29

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libtorrent/src/manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ Manager::Manager() :
std::bind(&DownloadManager::find_main, m_downloadManager, std::placeholders::_1);
m_handshakeManager->slot_download_obfuscated() =
std::bind(&DownloadManager::find_main_obfuscated, m_downloadManager, std::placeholders::_1);
m_handshakeManager->slot_succeeded() = std::bind(&HandshakeManager::receive_succeeded, m_handshakeManager, std::placeholders::_1);
m_connectionManager->listen()->slot_accepted() =
std::bind(&HandshakeManager::add_incoming, m_handshakeManager, std::placeholders::_1, std::placeholders::_2);

Expand Down
4 changes: 2 additions & 2 deletions libtorrent/src/protocol/handshake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ Handshake::event_read() {
}

} catch (handshake_succeeded& e) {
m_manager->receive_succeeded(this);
m_manager->call_slot_succeeded(this);

} catch (handshake_error& e) {
m_manager->receive_failed(this, e.type(), e.error());
Expand Down Expand Up @@ -962,7 +962,7 @@ Handshake::event_write() {
}

} catch (handshake_succeeded& e) {
m_manager->receive_succeeded(this);
m_manager->call_slot_succeeded(this);

} catch (handshake_error& e) {
m_manager->receive_failed(this, e.type(), e.error());
Expand Down
5 changes: 5 additions & 0 deletions libtorrent/src/protocol/handshake_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ HandshakeManager::erase(Handshake* handshake) {
base_type::erase(itr);
}

void
HandshakeManager::call_slot_succeeded(Handshake* h) {
m_slot_succeeded(h);
}

struct handshake_manager_equal : std::binary_function<const rak::socket_address*, const Handshake*, bool> {
bool operator () (const rak::socket_address* sa1, const Handshake* p2) const {
return p2->peer_info() != NULL && *sa1 == *rak::socket_address::cast_from(p2->peer_info()->socket_address());
Expand Down
4 changes: 4 additions & 0 deletions libtorrent/src/protocol/handshake_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class HandshakeManager : private rak::unordered_vector<Handshake*> {
typedef uint32_t size_type;

typedef std::function<DownloadMain* (const char*)> slot_download;
typedef std::function<void (Handshake*)> slot_handshake;

// Do not connect to peers with this many or more failed chunks.
static const unsigned int max_failed = 3;
Expand All @@ -84,12 +85,14 @@ class HandshakeManager : private rak::unordered_vector<Handshake*> {

slot_download& slot_download_id() { return m_slot_download_id; }
slot_download& slot_download_obfuscated() { return m_slot_download_obfuscated; }
slot_handshake& slot_succeeded() { return m_slot_succeeded; }

// This needs to be filterable slot.
DownloadMain* download_info(const char* hash) { return m_slot_download_id(hash); }
DownloadMain* download_info_obfuscated(const char* hash) { return m_slot_download_obfuscated(hash); }

void receive_succeeded(Handshake* h);
void call_slot_succeeded(Handshake* h);
void receive_failed(Handshake* h, int message, int error);
void receive_timeout(Handshake* h);

Expand All @@ -105,6 +108,7 @@ class HandshakeManager : private rak::unordered_vector<Handshake*> {

slot_download m_slot_download_id;
slot_download m_slot_download_obfuscated;
slot_handshake m_slot_succeeded;
};

}
Expand Down
Loading