From f9916b574fffa60f19055dbaf705cd9c15598617 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Fri, 17 Nov 2006 14:50:45 +0000 Subject: [PATCH] * Added a torrent::ClientInfo object to torrent::PeerInfo. * Removed the old display::ClientInfo code. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@806 e378c898-3ddf-0310-93e7-cc216c733640 --- src/control.cc | 5 - src/control.h | 5 - src/display/Makefile.am | 2 - src/display/client_info.cc | 200 -------------------------------- src/display/client_info.h | 92 --------------- src/display/window_peer_list.cc | 6 +- src/ui/element_peer_list.cc | 14 ++- 7 files changed, 13 insertions(+), 311 deletions(-) delete mode 100644 src/display/client_info.cc delete mode 100644 src/display/client_info.h diff --git a/src/control.cc b/src/control.cc index 53f04d43..01b442b6 100644 --- a/src/control.cc +++ b/src/control.cc @@ -46,7 +46,6 @@ #include "core/scheduler.h" #include "display/canvas.h" -#include "display/client_info.h" #include "display/window.h" #include "display/manager.h" #include "input/manager.h" @@ -70,8 +69,6 @@ Control::Control() : m_commandScheduler(new CommandScheduler()), m_variables(new utils::VariableMap()), - m_clientInfo(new display::ClientInfo), - m_tick(0) { m_core = new core::Manager(); @@ -99,8 +96,6 @@ Control::~Control() { delete m_display; delete m_core; delete m_scheduler; - - delete m_clientInfo; } void diff --git a/src/control.h b/src/control.h index 8a737bd3..a97ed8ca 100644 --- a/src/control.h +++ b/src/control.h @@ -55,7 +55,6 @@ namespace core { namespace display { class Manager; - class ClientInfo; } namespace input { @@ -98,8 +97,6 @@ public: CommandScheduler* command_scheduler() { return m_commandScheduler; } utils::VariableMap* variable() { return m_variables; } - display::ClientInfo* client_info() { return m_clientInfo; } - uint64_t tick() const { return m_tick; } void inc_tick() { m_tick++; } @@ -128,8 +125,6 @@ private: CommandScheduler* m_commandScheduler; utils::VariableMap* m_variables; - display::ClientInfo* m_clientInfo; - uint64_t m_tick; mode_t m_umask; diff --git a/src/display/Makefile.am b/src/display/Makefile.am index 21728843..48aede7a 100644 --- a/src/display/Makefile.am +++ b/src/display/Makefile.am @@ -4,8 +4,6 @@ libsub_display_a_SOURCES = \ attributes.h \ canvas.cc \ canvas.h \ - client_info.cc \ - client_info.h \ frame.cc \ frame.h \ manager.cc \ diff --git a/src/display/client_info.cc b/src/display/client_info.cc deleted file mode 100644 index 1e7728fb..00000000 --- a/src/display/client_info.cc +++ /dev/null @@ -1,200 +0,0 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2006, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include -#include -#include -#include - -#include "client_info.h" -#include "utils.h" - -namespace display { - -struct client_info_equal { - client_info_equal(const char* key, ClientInfo::size_type size) : m_key(key), m_size(size) {} - - bool operator () (const ClientInfo::value_type& v) const { - for (ClientInfo::size_type i = 0; i < m_size; ++i) - if (v.first[i] != m_key[i]) - return false; - - return true; - } - - const char* m_key; - ClientInfo::size_type m_size; -}; - -ClientInfo::ClientInfo() { - m_containers[TYPE_AZUREUS].reserve(30); - - insert(TYPE_AZUREUS, "AZ", "Azureus"); - insert(TYPE_AZUREUS, "BB", "BitBuddy"); - insert(TYPE_AZUREUS, "BC", "BitComet"); - insert(TYPE_AZUREUS, "UT", "uTorrent"); - insert(TYPE_AZUREUS, "lt", "libTorrent"); - insert(TYPE_AZUREUS, "CT", "CTorrent"); - insert(TYPE_AZUREUS, "MT", "MoonlightTorrent"); - insert(TYPE_AZUREUS, "LT", "libtorrent"); - insert(TYPE_AZUREUS, "LP", "Lphant"); - insert(TYPE_AZUREUS, "KT", "KTorrent"); - insert(TYPE_AZUREUS, "BX", "Bittorrent X"); - insert(TYPE_AZUREUS, "TS", "Torrentstorm"); - insert(TYPE_AZUREUS, "TN", "TorrentDotNET"); - insert(TYPE_AZUREUS, "TR", "Transmission"); - insert(TYPE_AZUREUS, "SS", "SwarmScope"); - insert(TYPE_AZUREUS, "XT", "XanTorrent"); - insert(TYPE_AZUREUS, "BS", "BTSlave"); - insert(TYPE_AZUREUS, "ZT", "ZipTorrent"); - insert(TYPE_AZUREUS, "AR", "Arctic"); - insert(TYPE_AZUREUS, "SB", "Swiftbit"); - insert(TYPE_AZUREUS, "MP", "MooPolice"); - insert(TYPE_AZUREUS, "QT", "Qt 4 Torrent example"); - insert(TYPE_AZUREUS, "SZ", "Shareaza"); - insert(TYPE_AZUREUS, "RT", "Retriever"); - insert(TYPE_AZUREUS, "CD", "Enhanced CTorrent"); - - m_containers[TYPE_COMPACT].reserve(10); - - insert(TYPE_COMPACT, "A", "ABC"); - insert(TYPE_COMPACT, "T", "BitTornado"); - insert(TYPE_COMPACT, "S", "Shadow's client"); - insert(TYPE_COMPACT, "U", "UPnP NAT Bit Torrent"); - insert(TYPE_COMPACT, "O", "Osprey Permaseed"); - - m_containers[TYPE_MAINLINE].reserve(5); - - insert(TYPE_MAINLINE, "M", "Mainline"); -} - -void -ClientInfo::insert(Type t, const char* key, const char* name) { - if (t >= TYPE_MAXSIZE) - throw torrent::input_error("Client info type out of range."); - - size_type keySize = sizeof_key(t); - - if (keySize != std::strlen(key)) - throw torrent::input_error("Client info key size not what was expected."); - - // Check if it is already present, not entirely optimal when - // initializing but this only get run once. - iterator itr = std::find_if(m_containers[t].begin(), m_containers[t].end(), client_info_equal(key, sizeof_key(t))); - - if (itr == m_containers[t].end()) - itr = m_containers[t].insert(m_containers[t].end(), value_type()); - - std::memcpy(itr->first, key, keySize); - itr->second = name; -} - -char* -ClientInfo::print(char* first, char* last, const char* id) const { - - if (id[0] == '-' && id[7] == '-' && - std::isalpha(id[1]) && std::isalpha(id[2]) && - std::isxdigit(id[3]) && std::isxdigit(id[4]) && std::isxdigit(id[5]) && std::isxdigit(id[6])) { - // TYPE_AZUREUS. - - const_iterator itr = std::find_if(m_containers[TYPE_AZUREUS].begin(), m_containers[TYPE_AZUREUS].end(), - client_info_equal(id + 1, sizeof_key(TYPE_AZUREUS))); - - if (itr != m_containers[TYPE_AZUREUS].end()) - first = print_buffer(first, last, "%s %hhu.%hhu.%hhu.%hhu", itr->second, - rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[4]), - rak::hexchar_to_value(id[5]), rak::hexchar_to_value(id[6])); - - else - first = print_buffer(first, last, "unknown %c%c %hhu.%hhu.%hhu.%hhu", id[1], id[2], - rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[4]), - rak::hexchar_to_value(id[5]), rak::hexchar_to_value(id[6])); - - } else if (std::isalpha(id[0]) && id[4] == '-' && - std::isxdigit(id[1]) && std::isxdigit(id[2]) && std::isxdigit(id[3])) { - // TYPE_THREE_COMPACT. - - const_iterator itr = std::find_if(m_containers[TYPE_COMPACT].begin(), m_containers[TYPE_COMPACT].end(), - client_info_equal(id, sizeof_key(TYPE_COMPACT))); - - if (itr != m_containers[TYPE_COMPACT].end()) - first = print_buffer(first, last, "%s %hhu.%hhu.%hhu", itr->second, - rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[2]), rak::hexchar_to_value(id[3])); - - else - first = print_buffer(first, last, "unknown %c %hhu.%hhu.%hhu", id[0], - rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[2]), rak::hexchar_to_value(id[3])); - - } else if (std::isalpha(id[0]) && id[2] == '-' && id[4] == '-' && id[6] == '-' && - std::isxdigit(id[1]) && std::isxdigit(id[3]) && std::isxdigit(id[5])) { - // TYPE_THREE_SPARSE. - - const_iterator itr = std::find_if(m_containers[TYPE_MAINLINE].begin(), m_containers[TYPE_MAINLINE].end(), - client_info_equal(id, sizeof_key(TYPE_MAINLINE))); - - if (itr != m_containers[TYPE_MAINLINE].end()) - first = print_buffer(first, last, "%s %hhu.%hhu.%hhu", itr->second, - rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[5])); - - else - first = print_buffer(first, last, "unknown %c %hhu.%hhu.%hhu", id[0], - rak::hexchar_to_value(id[1]), rak::hexchar_to_value(id[3]), rak::hexchar_to_value(id[5])); - - - // And then the incompatible idiots that make life difficult for us - // others. (There's '3' schemes to choose from already...) - - // Well... fuck this... I don't feel like adding the rest of the - // checks as they wouldn't be possible to remove/modify. - - } else { - first = print_buffer(first, last, "unknown"); - } - - return first; -} - -std::string -ClientInfo::str(const char* id) const { - char buf[128]; - print(buf, buf + 127, id); - - return std::string(buf); -} - -} diff --git a/src/display/client_info.h b/src/display/client_info.h deleted file mode 100644 index 35977be9..00000000 --- a/src/display/client_info.h +++ /dev/null @@ -1,92 +0,0 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2006, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_DISPLAY_CLIENT_INFO_H -#define RTORRENT_DISPLAY_CLIENT_INFO_H - -#include -#include -#include -#include - -namespace display { - -class ClientInfo { -public: - // Largest key size + 1. - static const uint32_t key_size = 3; - - typedef uint32_t size_type; - typedef std::pair value_type; - typedef std::vector container_type; - typedef container_type::iterator iterator; - typedef container_type::const_iterator const_iterator; - - typedef enum { - TYPE_AZUREUS, - TYPE_COMPACT, - TYPE_MAINLINE, - TYPE_MAXSIZE - } Type; - - ClientInfo(); - - void insert(Type t, const char* key, const char* name); - - char* print(char* first, char* last, const char* id) const; - - // Fix this... - std::string str(const char* id) const; - std::string str_str(const std::string& id) const { return str(id.c_str()); } - std::string hash_str(const torrent::HashString& id) const { return str(id.c_str()); } - - size_type sizeof_key(Type t) const { - switch (t) { - case TYPE_AZUREUS: return 2; - case TYPE_COMPACT: return 1; - case TYPE_MAINLINE: return 1; - default: - case TYPE_MAXSIZE: return 0; - } - } - -private: - container_type m_containers[TYPE_MAXSIZE]; -}; - -} - -#endif diff --git a/src/display/window_peer_list.cc b/src/display/window_peer_list.cc index 4a1bd2b3..7805e379 100644 --- a/src/display/window_peer_list.cc +++ b/src/display/window_peer_list.cc @@ -47,7 +47,6 @@ #include "rak/algorithm.h" #include "canvas.h" -#include "client_info.h" #include "utils.h" #include "window_peer_list.h" @@ -140,10 +139,7 @@ WindowPeerList::redraw() { x += 7; char buf[128]; - torrent::ClientInfo clientInfo; - torrent::client_list()->retrieve_id(&clientInfo, p.id()); - - print_client_version(buf, buf + 128, clientInfo); + print_client_version(buf, buf + 128, p.info()->client_info()); m_canvas->print(x, y, "%s", buf); diff --git a/src/ui/element_peer_list.cc b/src/ui/element_peer_list.cc index 5cb0f178..6ec355e5 100644 --- a/src/ui/element_peer_list.cc +++ b/src/ui/element_peer_list.cc @@ -40,12 +40,13 @@ #include #include #include +#include -#include "display/client_info.h" #include "display/frame.h" #include "display/manager.h" #include "display/text_element_helpers.h" #include "display/text_element_lambda.h" +#include "display/utils.h" #include "display/window_peer_list.h" #include "input/manager.h" @@ -88,6 +89,14 @@ ElementPeerList::~ElementPeerList() { delete m_elementInfo; } +std::string +te_client_version(const torrent::PeerInfo* info) { + char buf[128]; + display::print_client_version(buf, buf + 128, info->client_info()); + + return buf; +} + inline ElementText* ElementPeerList::create_info() { using namespace display::helpers; @@ -107,7 +116,8 @@ ElementPeerList::create_info() { display::text_element_value_slot(rak::on(std::mem_fun(&torrent::Peer::address), std::ptr_fun(&te_port)))); element->push_column("Id:", display::text_element_string_slot(std::mem_fun(&torrent::Peer::id), string_base::flag_escape_html)); - element->push_column("Client:", display::text_element_string_slot(rak::on(std::mem_fun(&torrent::Peer::id), rak::make_mem_fun(control->client_info(), &display::ClientInfo::hash_str)))); +// element->push_column("Client:", display::text_element_string_slot(rak::on(std::mem_fun(&torrent::Peer::id), rak::make_mem_fun(control->client_info(), &display::ClientInfo::hash_str)))); + element->push_column("Client:", display::text_element_string_slot(rak::on(std::mem_fun(&torrent::Peer::info), std::ptr_fun(&te_client_version)))); element->push_column("Options:", display::text_element_string_slot(std::mem_fun(&torrent::Peer::options), string_base::flag_escape_hex | string_base::flag_fixed_width, 0, 8)); element->push_column("Connected:", display::text_element_branch(std::mem_fun(&torrent::Peer::is_incoming), te_string("incoming"), te_string("outgoing"))); element->push_column("Encrypted:", display::text_element_branch3(std::mem_fun(&torrent::Peer::is_encrypted), te_string("yes"), std::mem_fun(&torrent::Peer::is_obfuscated), te_string("handshake"), te_string("no")));