1
/***************************************************************************
2
* Copyright (C) 2005 by Joris Guisson *
3
* joris.guisson@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19
***************************************************************************/
25
#include "btversion.h"
29
char RandomLetterOrNumber()
35
return 'A' + (i - 26);
37
return '0' + (i - 52);
44
memcpy(id,bt::PeerIDPrefix().toAscii(),8);
45
for (int i = 8;i < 20;i++)
46
id[i] = RandomLetterOrNumber();
47
client_name = identifyClient();
50
PeerID::PeerID(const char* pid)
56
client_name = identifyClient();
59
PeerID::PeerID(const PeerID & pid)
62
client_name = pid.client_name;
70
PeerID & PeerID::operator = (const PeerID & pid)
73
client_name = pid.client_name;
77
bool operator == (const PeerID & a,const PeerID & b)
79
for (int i = 0;i < 20;i++)
80
if (a.id[i] != b.id[i])
86
bool operator != (const PeerID & a,const PeerID & b)
88
return ! operator == (a,b);
91
bool operator < (const PeerID & a,const PeerID & b)
93
for (int i = 0;i < 20;i++)
94
if (a.id[i] < b.id[i])
100
QString PeerID::toString() const
103
for (int i = 0;i < 20;i++)
104
r += id[i] == 0 ? ' ' : id[i];
108
QString PeerID::identifyClient() const
110
if (!client_name.isNull())
113
QString peer_id = toString();
114
// we only need to create this map once
116
static QMap<QString, QString> Map;
117
static bool first = true;
121
// Keep things a bit alphabetic to make it easier add new ones
125
Map["AV"] = "Avicora";
126
Map["AX"] = "BitPump";
127
Map["AR"] = "Arctic";
128
Map["AZ"] = "Azureus";
129
Map["BB"] = "BitBuddy";
130
Map["BC"] = "BitComet";
131
Map["BF"] = "Bitflu";
132
Map["BG"] = "BTGetit";
133
Map["BM"] = "BitMagnet";
134
Map["BO"] = "BitsOnWheels";
135
Map["BR"] = "BitRocket";
136
Map["BS"] = "BTSlave";
137
Map["BX"] = "BitTorrent X";
138
Map["CD"] = "Enhanced CTorrent";
139
Map["CT"] = "CTorrent";
140
Map["DE"] = "DelugeTorrent";
141
Map["DP"] = "Propagate Data Client";
143
Map["ES"] = "electric sheep";
144
Map["FT"] = "FoxTorrent";
145
Map["GS"] = "GSTorrent";
146
Map["G3"] = "G3 Torrent";
147
Map["HL"] = "Halite";
148
Map["HN"] = "Hydranode";
150
Map["KT"] = "KTorrent"; // lets not forget our own client
151
Map["LH"] = "LH-ABC";
152
Map["lt"] = "libTorrent";
153
Map["LT"] = "libtorrent";
154
Map["LP"] = "Lphant";
155
Map["LW"] = "LimeWire";
156
Map["ML"] = "MLDonkey";
157
Map["MO"] = "MonoTorrent";
158
Map["MP"] = "MooPolice";
159
Map["MT"] = "MoonLight";
161
Map["qB"] = "qBittorrent";
162
Map["QD"] = "QQDownload";
163
Map["QT"] = "Qt 4 Torrent example";
165
Map["RT"] = "Retriever";
166
Map["S~"] = "Shareaza alpha/beta";
167
Map["SB"] = "Swiftbit";
168
Map["SS"] = "SwarmScope";
169
Map["ST"] = "SymTorrent";
170
Map["st"] = "sharktorrent";
171
Map["SZ"] = "Shareaza";
172
Map["TN"] = "Torrent .NET";
173
Map["TR"] = "Transmission";
174
Map["TS"] = "Torrent Storm";
176
Map["UL"] = "uLeecher!";
177
Map["UT"] = QString("%1Torrent").arg(QChar(0x00B5)); // µTorrent, 0x00B5 is unicode for µ
178
Map["WT"] = "BitLet";
179
Map["WY"] = "FireTorrent";
180
Map["XL"] = "Xunlei";
181
Map["XT"] = "Xan Torrent";
182
Map["XX"] = "Xtorrent";
183
Map["ZT"] = "Zip Torrent";
187
Map["O"] = "Osprey Permaseed";
188
Map["Q"] = "BTQueue";
189
Map["R"] = "Tribler";
190
Map["S"] = "Shadow's";
191
Map["T"] = "BitTornado";
192
Map["U"] = "UPnP NAT BitTorrent";
194
Map["Plus"] = "Plus! II";
196
Map["BOW"] = "Bits on Wheels";
197
Map["M"] = "BitTorrent";
198
Map["exbc"] = "BitComet";
199
Map["Mbrst"] = "Burst!";
203
QString name = i18n("Unknown client");
204
if (peer_id.at(0) == '-' &&
205
peer_id.at(1).isLetter() &&
206
peer_id.at(2).isLetter() ) //AZ style
208
QString ID(peer_id.mid(1,2));
209
if (Map.contains(ID))
210
name = Map[ID] + ' ' + peer_id.at(3) + '.' + peer_id.at(4) + '.'
211
+ peer_id.at(5) + '.' + peer_id.at(6);
213
else if (peer_id.at(0).isLetter() &&
214
peer_id.at(1).isDigit() &&
215
peer_id.at(2).isDigit() ) //Shadow's style
217
QString ID = QString(peer_id.at(0));
218
if (Map.contains(ID))
219
name = Map[ID] + ' ' + peer_id.at(1) + '.' +
220
peer_id.at(2) + '.' + peer_id.at(3);
222
else if (peer_id.at(0) == 'M' && peer_id.at(2) == '-' && (peer_id.at(4) == '-' || peer_id.at(5) == '-'))
224
name = Map["M"] + ' ' + peer_id.at(1) + '.' + peer_id.at(3);
225
if(peer_id.at(4) == '-')
226
name += QString(".%1").arg(peer_id.at(5));
228
name += QString("%1.%2").arg(peer_id.at(4)).arg(peer_id.at(6));
230
else if (peer_id.startsWith("OP"))
234
else if ( peer_id.startsWith("exbc") )
238
else if ( peer_id.mid(1,3) == "BOW")
242
else if ( peer_id.startsWith("Plus"))
246
else if ( peer_id.startsWith("Mbrst"))
248
name = Map["Mbrst"] + ' ' + peer_id.at(5) + '.' + peer_id.at(7);