BTPeerIDByteDecoder.java

Index Score
com.aelitis.azureus.core.peermanager.utils
Azureus

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
JAVA0266JAVA0266 Use of System.out
INTERFACE_COMPLEXITYInterface complexity
JAVA0076JAVA0076 Use of magic number
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0144JAVA0144 Line exceeds maximum M characters
CYCLOMATICCyclomatic complexity
COMPARISONSNumber of comparison operators
LOGICAL_LINESNumber of statements
BLOCKSNumber of blocks
LINE_COMMENTNumber of line comments
SIZESize of the file in bytes
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
JAVA0170JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0166JAVA0166 Generic exception caught
ELOCEffective lines of code
JAVA0034JAVA0034 Missing braces in if statement
LOCLines of code
EXITSProcedure exits
LINESNumber of lines in the source file
JAVA0008JAVA0008 Empty catch block
UNIQUE_OPERATORSNumber of unique operators
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0177JAVA0177 Variable declaration missing initializer
PROGRAM_VOLUMEHalstead program volume
JAVA0160JAVA0160 Method does not throw specified exception
JAVA0126JAVA0126 Method declares unchecked exception in throws
PARAMSNumber of formal parameter declarations
JAVA0145JAVA0145 Tab character used in source file
JAVA0173JAVA0173 Unused method parameter
DECL_COMMENTSComments in declarations
JAVA0068JAVA0068 Modifiers not declared in recommended order
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
NEST_DEPTHMaximum nesting depth
/* * Created on Nov 12, 2003 * Created by Alon Rohter * Copyright (C) 2003-2004 Alon Rohter, All Rights Reserved. * Copyright (C) 2003, 2004, 2005, 2006 Aelitis, All Rights Reserved. * * 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. * * AELITIS, SAS au capital de 46,603.30 euros * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France. * */ package com.aelitis.azureus.core.peermanager.utils; import org.gudy.azureus2.core3.internat.MessageText; import org.gudy.azureus2.core3.util.ByteFormatter; import org.gudy.azureus2.core3.util.Constants; import org.gudy.azureus2.core3.util.Debug; import org.gudy.azureus2.core3.util.FileUtil; import java.io.*; import java.util.HashSet; /** * Used for identifying clients by their peerID. */ public class BTPeerIDByteDecoder { final static boolean LOG_UNKNOWN; static { String prop = System.getProperty("log.unknown.peerids"); LOG_UNKNOWN = prop != null && prop.equals("1"); } private static void logUnknownClient0(byte[] peer_id_bytes, Writer log) throws IOException { String text = new String(peer_id_bytes, 0, 20, Constants.BYTE_ENCODING); text = text.replace((char)12, (char)32); text = text.replace((char)10, (char)32); log.write("[" + text + "] "); // Readable log.write(ByteFormatter.encodeString(peer_id_bytes) + " "); // Usable for assertion tests. log.write("\n"); } private static String asUTF8ByteString(String text) { try { byte[] utf_bytes = text.getBytes(Constants.DEFAULT_ENCODING); return ByteFormatter.encodeString(utf_bytes); } catch (UnsupportedEncodingException uee) {return "";} } private static HashSet logged_discrepancies = new HashSet(); public static void logClientDiscrepancy(String peer_id_name, String handshake_name, String discrepancy, String protocol, byte[] peer_id) { if (!client_logging_allowed) {return;} // Generate the string used that we will log. String line_to_log = discrepancy + " [" + protocol + "]: "; line_to_log += "\"" + peer_id_name + "\" / \"" + handshake_name + "\" "; // We'll encode the name in byte form to help us decode it. line_to_log += "[" + asUTF8ByteString(handshake_name) + "]"; // Avoid logging the same combination of things again. boolean log_to_debug_out = Constants.isCVSVersion(); if (log_to_debug_out || LOG_UNKNOWN) { // If this text has been recorded before, then avoid doing it again. if (!logged_discrepancies.add(line_to_log)) {return;} } // Add peer ID bytes. if (peer_id != null) { line_to_log += ", Peer ID: " + ByteFormatter.encodeString(peer_id); } // Enable this block for now - just until we get more feedback about // problematic clients. if (log_to_debug_out) { Debug.outNoStack("Conflicting peer identification: " + line_to_log); } if (!LOG_UNKNOWN) {return;} FileWriter log = null; File log_file = FileUtil.getUserFile("identification.log"); try { log = new FileWriter(log_file, true); log.write(line_to_log); log.write("\n"); } catch (Throwable e) { Debug.printStackTrace(e); } finally { try {if (log != null) log.close();} catch (IOException ignore) {/*ignore*/} } } static boolean client_logging_allowed = true; // I don't expect this to grow too big, and it won't grow if there's no logging going on. private static HashSet logged_ids = new HashSet(); static void logUnknownClient(byte[] peer_id_bytes) {logUnknownClient(peer_id_bytes, true);} static void logUnknownClient(byte[] peer_id_bytes, boolean to_debug_out) { if (!client_logging_allowed) {return;} // Avoid logging the same client ID multiple times. boolean log_to_debug_out = to_debug_out && Constants.isCVSVersion(); if (log_to_debug_out || LOG_UNKNOWN) { // If the ID has been recorded before, then avoid doing it again. if (!logged_ids.add(makePeerIDReadableAndUsable(peer_id_bytes))) {return;} } // Enable this block for now - just until we get more feedback about // unknown clients. if (log_to_debug_out) { Debug.outNoStack("Unable to decode peer correctly - peer ID bytes: " + makePeerIDReadableAndUsable(peer_id_bytes)); } if (!LOG_UNKNOWN) {return;} FileWriter log = null; File log_file = FileUtil.getUserFile("identification.log"); try { log = new FileWriter(log_file, true); logUnknownClient0(peer_id_bytes, log); } catch (Throwable e) { Debug.printStackTrace(e); } finally { try {if (log != null) log.close();} catch (IOException ignore) {/*ignore*/} } } static void logUnknownClient(String peer_id) { try {logUnknownClient(peer_id.getBytes(Constants.BYTE_ENCODING));} catch (UnsupportedEncodingException uee) {} } public static String decode0(byte[] peer_id_bytes) { final String UNKNOWN = MessageText.getString("PeerSocket.unknown"); final String FAKE = MessageText.getString("PeerSocket.fake_client"); final String BAD_PEER_ID = MessageText.getString("PeerSocket.bad_peer_id"); String peer_id = null; try {peer_id = new String(peer_id_bytes, Constants.BYTE_ENCODING);} catch (UnsupportedEncodingException uee) {return "";} // We store the result here. String client = null; /** * If the client reuses parts of the peer ID of other peers, then try to determine this * first (before we misidentify the client). */ if (BTPeerIDByteDecoderUtils.isPossibleSpoofClient(peer_id)) { client = decodeBitSpiritClient(peer_id, peer_id_bytes); if (client != null) {return client;} client = decodeBitCometClient(peer_id, peer_id_bytes); if (client != null) {return client;} return "BitSpirit? (" + BAD_PEER_ID + ")"; } /** * See if the client uses Az style identification. */ if (BTPeerIDByteDecoderUtils.isAzStyle(peer_id)) { client = BTPeerIDByteDecoderDefinitions.getAzStyleClientName(peer_id); if (client != null) { String client_with_version = BTPeerIDByteDecoderDefinitions.getAzStyleClientVersion(client, peer_id); /** * Hack for fake ZipTorrent clients - there seems to be some clients * which use the same identifier, but they aren't valid ZipTorrent clients. */ if (client.startsWith("ZipTorrent") && peer_id.startsWith("bLAde", 8)) { String client_name = (client_with_version == null) ? client : client_with_version; return UNKNOWN + " [" + FAKE + ": " + client_name + "]"; } /** * BitTorrent 6.0 Beta currently misidentifies itself. */ if ("\u00B5Torrent 6.0.0 Beta".equals(client_with_version)) { return "Mainline 6.0 Beta"; } /** * If it's the rakshasa libtorrent, then it's probably rTorrent. */ if (client.startsWith("libTorrent (Rakshasa)")) { String client_name = (client_with_version == null) ? client : client_with_version; return client_name + " / rTorrent*"; } if (client_with_version != null) {return client_with_version;} return client; } } /** * See if the client uses Shadow style identification. */ if (BTPeerIDByteDecoderUtils.isShadowStyle(peer_id)) { client = BTPeerIDByteDecoderDefinitions.getShadowStyleClientName(peer_id); if (client != null) { String client_ver = BTPeerIDByteDecoderUtils.getShadowStyleVersionNumber(peer_id); if (client_ver != null) {return client + " " + client_ver;} return client; } } /** * See if the client uses Mainline style identification. */ client = BTPeerIDByteDecoderDefinitions.getMainlineStyleClientName(peer_id); if (client != null) { /** * We haven't got a good way of detecting whether this is a Mainline style * version of peer ID until we start decoding peer ID information. So for * that reason, we wait until we get client version information here - if * we don't manage to determine a version number, then we assume that it * has been misidentified and carry on with it. */ String client_ver = BTPeerIDByteDecoderUtils.getMainlineStyleVersionNumber(peer_id); if (client_ver != null) { String result = client + " " + client_ver; return result; } } /** * Check for BitSpirit / BitComet (non possible spoof client mode). */ client = decodeBitSpiritClient(peer_id, peer_id_bytes); if (client != null) {return client;} client = decodeBitCometClient(peer_id, peer_id_bytes); if (client != null) {return client;} /** * See if the client identifies itself using a particular substring. */ BTPeerIDByteDecoderDefinitions.ClientData client_data = BTPeerIDByteDecoderDefinitions.getSubstringStyleClient(peer_id); if (client_data != null) { client = client_data.client_name; String client_with_version = BTPeerIDByteDecoderDefinitions.getSubstringStyleClientVersion(client_data, peer_id, peer_id_bytes); if (client_with_version != null) {return client_with_version;} return client; } client = identifyAwkwardClient(peer_id_bytes); if (client != null) {return client;} return null; } /** * Decodes the given peerID, returning an identification string. */ public static String decode(byte[] peer_id) { if ( peer_id.length > 0 ){ try { String client = decode0(peer_id); if (client != null ){ return client; } }catch (Throwable e) { Debug.out( "Failed to decode peer id " + ByteFormatter.encodeString(peer_id) + ": " + Debug.getNestedExceptionMessageAndStack( e )); } try { String peer_id_as_string = new String(peer_id, Constants.BYTE_ENCODING); boolean is_az_style = BTPeerIDByteDecoderUtils.isAzStyle(peer_id_as_string); boolean is_shadow_style = BTPeerIDByteDecoderUtils.isShadowStyle(peer_id_as_string); logUnknownClient(peer_id, !(is_az_style || is_shadow_style)); if (is_az_style) { return BTPeerIDByteDecoderDefinitions.formatUnknownAzStyleClient(peer_id_as_string); } else if (is_shadow_style) { return BTPeerIDByteDecoderDefinitions.formatUnknownShadowStyleClient(peer_id_as_string); } }catch( Throwable e ){ Debug.out( "Failed to decode peer id " + ByteFormatter.encodeString(peer_id) + ": " + Debug.getNestedExceptionMessageAndStack( e )); } } String sPeerID = getPrintablePeerID(peer_id); return MessageText.getString("PeerSocket.unknown") + " [" + sPeerID + "]"; } public static String identifyAwkwardClient(byte[] peer_id) { int iFirstNonZeroPos = 0; iFirstNonZeroPos = 20; for( int i=0; i < 20; i++ ) { if( peer_id[i] != (byte)0 ) { iFirstNonZeroPos = i; break; } } //Shareaza check if( iFirstNonZeroPos == 0 ) { boolean bShareaza = true; for( int i=0; i < 16; i++ ) { if( peer_id[i] == (byte)0 ) { bShareaza = false; break; } } if( bShareaza ) { for( int i=16; i < 20; i++ ) { if( peer_id[i] != ( peer_id[i % 16] ^ peer_id[15 - (i % 16)] ) ) { bShareaza = false; break; } } if( bShareaza ) return "Shareaza"; } } byte three = (byte)3; if ((iFirstNonZeroPos == 9) && (peer_id[9] == three) && (peer_id[10] == three) && (peer_id[11] == three)) { return "Snark"; } if ((iFirstNonZeroPos == 12) && (peer_id[12] == (byte)97) && (peer_id[13] == (byte)97)) { return "Experimental 3.2.1b2"; } if ((iFirstNonZeroPos == 12) && (peer_id[12] == (byte)0) && (peer_id[13] == (byte)0)) { return "Experimental 3.1"; } if (iFirstNonZeroPos == 12) return "Mainline"; return null; } private static String decodeBitSpiritClient(String peer_id, byte[] peer_id_bytes) { if (!peer_id.substring(2, 4).equals("BS")) {return null;} String version = BTPeerIDByteDecoderUtils.decodeNumericValueOfByte(peer_id_bytes[1]); if ("0".equals(version)) {version = "1";} return "BitSpirit v" + version; } private static String decodeBitCometClient(String peer_id, byte[] peer_id_bytes) { String mod_name = null; if (peer_id.startsWith("exbc")) {mod_name = "";} else if (peer_id.startsWith("FUTB")) {mod_name = "(Solidox Mod) ";} else if (peer_id.startsWith("xUTB")) {mod_name = "(Mod 2) ";} else {return null;} boolean is_bitlord = (peer_id.substring(6, 10).equals("LORD")); /** * Older versions of BitLord are of the form x.yy, whereas new versions (1 and onwards), * are of the form x.y. BitComet is of the form x.yy. */ String client_name = (is_bitlord) ? "BitLord " : "BitComet "; String maj_version = BTPeerIDByteDecoderUtils.decodeNumericValueOfByte(peer_id_bytes[4]); int min_version_length = (is_bitlord && !maj_version.equals("0")) ? 1 : 2; return client_name + mod_name + maj_version + "." + BTPeerIDByteDecoderUtils.decodeNumericValueOfByte(peer_id_bytes[5], min_version_length); } protected static String getPrintablePeerID(byte[] peer_id) { return getPrintablePeerID(peer_id, '-'); } protected static String getPrintablePeerID(byte[] peer_id, char fallback_char) { String sPeerID = ""; byte[] peerID = new byte[ peer_id.length ]; System.arraycopy( peer_id, 0, peerID, 0, peer_id.length ); try { for (int i = 0; i < peerID.length; i++) { int b = (0xFF & peerID[i]); if (b < 32 || b > 127) peerID[i] = (byte)fallback_char; } sPeerID = new String(peerID, Constants.BYTE_ENCODING); } catch (UnsupportedEncodingException ignore) {} catch (Throwable e) {} return( sPeerID ); } private static String makePeerIDReadableAndUsable(byte[] peer_id) { boolean as_ascii = true; for (int i=0; i<peer_id.length; i++) { int b = 0xFF & peer_id[i]; if (b < 32 || b > 127 || b == 10 || b == 9 || b==13) { as_ascii = false; break; } } if (as_ascii) { try {return new String(peer_id, Constants.BYTE_ENCODING);} catch (UnsupportedEncodingException uee) {return "";} } else {return ByteFormatter.encodeString(peer_id);} } static byte[] peerIDStringToBytes(String peer_id) throws Exception { if (peer_id.length() > 40) { peer_id = peer_id.replaceAll("[ ]", ""); } byte[] byte_peer_id = null; if (peer_id.length() == 40) { byte_peer_id = ByteFormatter.decodeString(peer_id); String readable_peer_id = makePeerIDReadableAndUsable(byte_peer_id); if (!peer_id.equals(readable_peer_id)) { throw new RuntimeException("Use alternative format for peer ID - from " + peer_id + " to " + readable_peer_id); } } else if (peer_id.length() == 20) { byte_peer_id = peer_id.getBytes(Constants.BYTE_ENCODING); } else { throw new IllegalArgumentException(peer_id); } return byte_peer_id; } private static void assertDecode(String client_result, String peer_id) throws Exception { assertDecode(client_result, peerIDStringToBytes(peer_id)); } private static void assertDecode(String client_result, byte[] peer_id) throws Exception { String peer_id_as_string = getPrintablePeerID(peer_id, '*'); System.out.println(" Peer ID: " + peer_id_as_string + " Client: " + client_result); // Do not log any clients. String decoded_result = decode(peer_id); if (client_result.equals(decoded_result)) {return;} throw new RuntimeException("assertion failure - expected \"" + client_result + "\", got \"" + decoded_result + "\": " + peer_id_as_string); } public static void main(String[] args) throws Exception { client_logging_allowed = false; final String FAKE = MessageText.getString("PeerSocket.fake_client"); final String UNKNOWN = MessageText.getString("PeerSocket.unknown"); final String BAD_PEER_ID = MessageText.getString("PeerSocket.bad_peer_id"); System.out.println("Testing AZ style clients..."); assertDecode("Ares 2.0.5.3", "-AG2053-Em6o1EmvwLtD"); assertDecode("Ares 1.6.7.0", "-AR1670-3Ql6wM3hgtCc"); assertDecode("Artemis 2.5.2.0", "-AT2520-vEEt0wO6v0cr"); assertDecode("Azureus 2.2.0.0", "-AZ2200-6wfG2wk6wWLc"); assertDecode("BT Next Evolution 1.0.9", "-NE1090002IKyMn4g7Ko"); assertDecode("BitRocket 0.3(32)", "-BR0332-!XVceSn(*KIl"); assertDecode("Mainline 6.0 Beta", "2D555436 3030422D A78DC290 C3F7BDE0 15EC3CC7"); assertDecode("FlashGet 1.80", "2D464730 31383075 F8005782 1359D64B B3DFD265"); assertDecode("GetRight 6.3", "-GR6300-13s3iFKmbArc"); assertDecode("Halite 0.2.9", "-HL0290-xUO*9ugvENUE"); assertDecode("KTorrent 1.1 RC1", "-KT11R1-693649213030"); assertDecode("KTorrent 3.0", "2D4B543330302D006A7139727958377731756A4B"); assertDecode("libTorrent (Rakshasa) 0.11.2 / rTorrent*", "2D6C74304232302D0D739B93E6BE21FEBB557B20"); assertDecode("libtorrent (Rasterbar) 0.13.0", "-LT0D00-eZ0PwaDDr-~v"); // The latest version at time of writing is v0.12, but I'll assume this is valid. assertDecode("linkage 0.1.4", "-LK0140-ATIV~nbEQAMr"); assertDecode("LimeWire", "2D4C57303030312D31E0B3A0B46F7D4E954F4103"); assertDecode("Lphant 3.02", "2D4C5030 3330322D 00383336 35363935 37373030"); assertDecode("Shareaza 2.1.3.2", "2D535A323133322D000000000000000000000000"); assertDecode("SymTorrent 1.17", "-ST0117-01234567890!"); assertDecode("Transmission 0.6", "-TR0006-01234567890!"); assertDecode("Transmission 0.72 (Dev)", "-TR072Z-zihst5yvg22f"); assertDecode("Transmission 0.72", "-TR0072-8vd6hrmp04an"); assertDecode("TuoTu 2.1.0", "-TT210w-dq!nWf~Qcext"); assertDecode("\u00B5Torrent 1.7.0 Beta", "2D555431 3730422D 92844644 1DB0A094 A01C01E5"); assertDecode("\u54c7\u560E (Vagaa) 2.6.4.4", "2D5647323634342D4FD62CDA69E235717E3BB94B"); assertDecode("Wyzo 0.3.0.0", "-WY0300-6huHF5Pr7Vde"); System.out.println(); // Shadow style clients. System.out.println("Testing Shadow style clients..."); assertDecode("ABC", "A--------YMyoBPXYy2L"); // Seen this quite a bit - not sure that it is ABC, but I guess we should default to that... assertDecode("ABC 2.6.9", "413236392D2D2D2D345077199FAEC4A673BECA01"); assertDecode("ABC 3.1", "A310--001v5Gysr4NxNK"); assertDecode("BitTornado 0.3.12", "T03C-----6tYolxhVUFS"); assertDecode("BitTornado 0.3.18", "T03I--008gY6iB6Aq27C"); assertDecode("BitTornado 0.3.9", "T0390----5uL5NvjBe2z"); assertDecode("Tribler 1", "R100--003hR6s07XWcov"); // Seen recently - is this really Tribler? assertDecode("Tribler 3.7", "R37---003uApHy851-Pq"); System.out.println(); // Simple substring style clients. System.out.println("Testing simple substring clients..."); assertDecode("Azureus 1", "417A7572 65757300 00000000 000000A0 76F0AEF7"); assertDecode("Azureus 2.0.3.2", "2D2D2D2D2D417A757265757354694E7A2A6454A7"); assertDecode("G3 Torrent", "2D473341 6E6F6E79 6D6F7573 70E8D9CB 30250AD4"); assertDecode("Hurricane Electric", "6172636C696768742E68652EA5860C157A5ADC35"); assertDecode("Pando", "Pando-6B511B691CAC2E"); // Seen recently, have they changed peer ID format? assertDecode("\u00B5Torrent 1.7.0 RC", "2D55543137302D00AF8BC5ACCC4631481EB3EB60"); System.out.println(); // Version substring style clients. System.out.println("Testing versioned substring clients..."); assertDecode("Bitlet 0.1", "4269744C657430319AEA4E02A09E318D70CCF47D"); assertDecode("BitsOnWheels", "-BOWP05-EPICNZOGQPHP"); // Seen in the wild - no idea what version that's meant to be - a pre-release? assertDecode("Burst! 1.1.3", "Mbrst1-1-32e3c394b43"); assertDecode("Opera (Build 7685)", "OP7685f2c1495b1680bf"); assertDecode("Opera (Build 10063)", "O100634008270e29150a"); assertDecode("Rufus 0.6.9", "00455253 416E6F6E 796D6F75 7382BE42 75024AE3"); assertDecode("BitTorrent DNA 1.0", "444E413031303030DD01C9B2DA689E6E02803E91"); assertDecode("BTuga Revolution 2.1", "BTM21abcdefghijklmno"); assertDecode("AllPeers 0.70rc30", "4150302E3730726333302D3E3EB87B31F241DBFE"); // AP0.70rc30->>-{1-A--]" assertDecode("External Webseed", "45787420EC7CC30033D7801FEEB713FBB0557AC4"); assertDecode("QVOD (Build 0054)", "QVOD00541234567890AB"); // Based on description on wiki.theory.org. System.out.println(); // BitComet/Lord/Spirit System.out.println("Testing BitComet/Lord/Spirit clients..."); assertDecode("BitComet 0.56", "6578626300387A4463102D6E9AD6723B339F35A9"); assertDecode("BitLord 0.56", "6578626300384C4F52443200048ECED57BD71028"); assertDecode("BitSpirit? (" + BAD_PEER_ID + ")", "4D342D302D322D2D6898D9D0CAF25E4555445030"); assertDecode("BitSpirit v2", "000242539B7ED3E058A8384AA748485454504254"); assertDecode("BitSpirit v3", "00034253 07248896 44C59530 8A5FF2CA 55445030"); System.out.println(); // Mainline style clients. System.out.println("Testing new mainline style clients..."); assertDecode("Mainline 5.0.7", "M5-0-7--9aa757efd5be"); assertDecode("Amazon AWS S3", "S3-1-0-0--0123456789"); // Not currently decoded as mainline style... System.out.println(); // Various specialised clients. System.out.println("Testing various specialised clients..."); assertDecode("Mainline", "0000000000000000000000004C53441933104277"); assertDecode(UNKNOWN + " [" + FAKE + ": ZipTorrent 1.6.0.0]", "-ZT1600-bLAdeY9rdjbe"); System.out.println(); // Unknown clients - may be random bytes. System.out.println("Testing unknown (random byte?) clients..."); assertDecode(UNKNOWN + " [--------1}-/---A---<]", "0000000000000000317DA32F831FF041A515FE3C"); assertDecode(UNKNOWN + " [------- -- ------@(]", "000000DF05020020100020200008000000004028"); assertDecode(UNKNOWN + " [-----------D-y-I--aO]", "0000000000000000F106CE44F179A2498FAC614F"); assertDecode(UNKNOWN + " [--c--_-5-\\----t-#---]", "E7F163BB0E5FCD35005C09A11BC274C42385A1A0"); System.out.println(); // Unknown AZ style clients. System.out.println("Testing unknown AZ style clients..."); String unknown_az; unknown_az = MessageText.getString("PeerSocket.unknown_az_style", new String[]{"BD", "0.3.0.0"}); assertDecode(unknown_az, "-BD0300-1SGiRZ8uWpWH"); unknown_az = MessageText.getString("PeerSocket.unknown_az_style", new String[]{"wF", "2.2.0.0"}); assertDecode(unknown_az, "2D7746323230302D9DFF296B56AFC2DF751C609C"); unknown_az = MessageText.getString("PeerSocket.unknown_az_style", new String[]{"X1", "0.0.6.4"}); assertDecode(unknown_az, "2D5831303036342D12FB8A5B954153A114267F1F"); unknown_az = MessageText.getString("PeerSocket.unknown_az_style", new String[]{"bF", "2q00"}); // I made this one up. assertDecode(unknown_az, "2D6246327130302D9DFF296B56AFC2DF751C609C"); System.out.println(); // Unknown Shadow style clients. System.out.println("Testing unknown Shadow style clients..."); String unknown_shadow; unknown_shadow = MessageText.getString("PeerSocket.unknown_shadow_style", new String[]{"B", "1.2"}); assertDecode(unknown_shadow, "B12------xgTofhetSVQ"); System.out.println(); // TODO //assertDecode("KTorrent 2.2", "-KT22B1-695754334315"); // We could use the B1 information... //assertDecode("KTorrent 2.1.4", "-KT2140-584815613993"); // Currently shows as 2.1. //assertDecode("", "C8F2D9CD3A90455354426578626300362D2D2D92"); // Looks like a BitLord client - ESTBexbc? //assertDecode("", "303030302D2D0000005433585859684B59584C72"); // Seen in the wild, appears to be a modified version of Azureus 2.5.0.0 (that's what was in the AZMP handshake)? //assertDecode("", "B5546F7272656E742F3330323520202020202020"); System.out.println("Done."); } }

The table below shows all metrics for BTPeerIDByteDecoder.java.

MetricValueDescription
BLOCKS106.00Number of blocks
BLOCK_COMMENT22.00Number of block comment lines
COMMENTS98.00Comment lines
COMMENT_DENSITY 0.28Comment density
COMPARISONS80.00Number of comparison operators
CYCLOMATIC113.00Cyclomatic complexity
DECL_COMMENTS 4.00Comments in declarations
DOC_COMMENT46.00Number of javadoc comment lines
ELOC347.00Effective lines of code
EXEC_COMMENTS33.00Comments in executable code
EXITS55.00Procedure exits
FUNCTIONS18.00Number of function declarations
HALSTEAD_DIFFICULTY73.62Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY161.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 3.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 1.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 5.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 1.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA007637.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 1.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 1.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 6.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 0.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 1.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 9.00JAVA0144 Line exceeds maximum M characters
JAVA01451249.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 1.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 5.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 5.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 1.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 2.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA026622.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES608.00Number of lines in the source file
LINE_COMMENT30.00Number of line comments
LOC417.00Lines of code
LOGICAL_LINES275.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS1167.00Number of operands
OPERATORS2136.00Number of operators
PARAMS29.00Number of formal parameter declarations
PROGRAM_LENGTH3303.00Halstead program length
PROGRAM_VOCAB482.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS132.00Number of return points from functions
SIZE23819.00Size of the file in bytes
UNIQUE_OPERANDS428.00Number of unique operands
UNIQUE_OPERATORS54.00Number of unique operators
WHITESPACE93.00Number of whitespace lines