* 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
This commit is contained in:
rakshasa
2006-11-17 14:50:45 +00:00
parent a5e7acc61b
commit f9916b574f
7 changed files with 13 additions and 311 deletions
-5
View File
@@ -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
-5
View File
@@ -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;
-2
View File
@@ -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 \
-200
View File
@@ -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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <cctype>
#include <cstring>
#include <rak/string_manip.h>
#include <torrent/exceptions.h>
#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);
}
}
-92
View File
@@ -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 <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_DISPLAY_CLIENT_INFO_H
#define RTORRENT_DISPLAY_CLIENT_INFO_H
#include <string>
#include <vector>
#include <inttypes.h>
#include <torrent/hash_string.h>
namespace display {
class ClientInfo {
public:
// Largest key size + 1.
static const uint32_t key_size = 3;
typedef uint32_t size_type;
typedef std::pair<char[key_size], const char*> value_type;
typedef std::vector<value_type> 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
+1 -5
View File
@@ -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);
+12 -2
View File
@@ -40,12 +40,13 @@
#include <torrent/exceptions.h>
#include <torrent/rate.h>
#include <torrent/hash_string.h>
#include <torrent/peer/peer_info.h>
#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")));