FileDocCategorySizeDatePackage
BTPeerIDByteDecoderDefinitions.javaAPI DocAzureus 3.0.3.417305Tue Oct 02 04:51:22 BST 2007com.aelitis.azureus.core.peermanager.utils

BTPeerIDByteDecoderDefinitions

public class BTPeerIDByteDecoderDefinitions extends Object

Fields Summary
private static HashMap
az_style_code_map
private static HashMap
az_client_version_map
private static HashMap
shadow_style_code_map
private static HashMap
shadow_client_version_map
private static HashMap
mainline_style_code_map
private static ArrayList
custom_style_client_list
List of objects which describes clients with their own custom naming scheme.
static String
VER_AZ_THREE_DIGITS
static String
VER_AZ_THREE_DIGITS_PLUS_MNEMONIC
static String
VER_AZ_ONE_MAJ_TWO_MIN_PLUS_MNEMONIC
static String
VER_AZ_FOUR_DIGITS
static String
VER_AZ_TWO_MAJ_TWO_MIN
static String
VER_AZ_SKIP_FIRST_ONE_MAJ_TWO_MIN
static String
VER_AZ_KTORRENT_STYLE
static String
VER_AZ_TRANSMISSION_STYLE
static String
VER_AZ_LAST_THREE_DIGITS
static String
VER_AZ_THREE_ALPHANUMERIC_DIGITS
static String
VER_BLOCK
static String
VER_DOTTED_BLOCK
static String
VER_BYTE_BLOCK_DOTTED_CHAR
static String
VER_BITS_ON_WHEELS
static String
VER_TWO_BYTE_THREE_PART
static String
NO_VERSION
Constructors Summary
Methods Summary
private static voidaddAzStyle(java.lang.String id, java.lang.String client)

	
	// Used to register client information.
	       
		addAzStyle(id, client, VER_AZ_FOUR_DIGITS);
	
private static voidaddAzStyle(java.lang.String id, java.lang.String client, java.lang.String version_style)

		if (id.length() != 2) {throw new RuntimeException("not two chars long - " + id);}
		az_style_code_map.put(id, client);
		az_client_version_map.put(client, version_style);
	
private static voidaddMainlineStyle(char id, java.lang.String client)

		mainline_style_code_map.put("" + id, client);
	
private static voidaddShadowStyle(char id, java.lang.String client)

		addShadowStyle(id, client, VER_AZ_THREE_DIGITS);
	
private static voidaddShadowStyle(char id, java.lang.String client, java.lang.String version_style)

		shadow_style_code_map.put("" + id, client);
		shadow_client_version_map.put(client, version_style);
	
private static com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientDataaddSimpleClient(java.lang.String client_name, java.lang.String identifier)

		return addSimpleClient(client_name, identifier, 0);
	
private static com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientDataaddSimpleClient(java.lang.String client_name, java.lang.String identifier, int position)

		ClientData result = new ClientData(client_name, identifier, position);
		custom_style_client_list.add(result);
		return result;
	
private static voidaddVersionedClient(com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientData client, java.lang.String version_type, int length, int version_pos)

		addVersionedClient(client, version_type, length, null, version_pos);
	
private static voidaddVersionedClient(com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientData client, java.lang.String version_type, int length, java.lang.String format, int version_pos)

		client.version_data = new VersionNumberData(version_type, length, format, version_pos);
	
private static voidaddVersionedClient(com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientData client, java.lang.String version_type, int length)

		addVersionedClient(client, version_type, length, null);
	
private static voidaddVersionedClient(com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientData client, java.lang.String version_type, int length, java.lang.String format)

		addVersionedClient(client, version_type, length, format, client.simple_string.length() + client.simple_string_pos);
	
public static java.lang.StringformatUnknownAzStyleClient(java.lang.String peer_id)

		String version_string = peer_id.substring(3, 7);
		try {
		    version_string = BTPeerIDByteDecoderUtils.decodeAzStyleVersionNumber(
		    		version_string, VER_AZ_FOUR_DIGITS);
		}
		catch (Exception e) {/* Just use the unformatted string */}

		return MessageText.getString("PeerSocket.unknown_az_style", new String[] {
		    peer_id.substring(1, 3), version_string
		});
	
public static java.lang.StringformatUnknownShadowStyleClient(java.lang.String peer_id)

		String version_string = BTPeerIDByteDecoderUtils.getShadowStyleVersionNumber(peer_id);
		return MessageText.getString("PeerSocket.unknown_shadow_style", new String[] {
			peer_id.substring(0, 1), version_string
		});
	
public static java.lang.StringgetAzStyleClientName(java.lang.String peer_id)

		return (String)az_style_code_map.get(peer_id.substring(1, 3));
	
public static java.lang.StringgetAzStyleClientVersion(java.lang.String client_name, java.lang.String peer_id)

		String version_scheme = (String)az_client_version_map.get(client_name);
		if (version_scheme == NO_VERSION) {return null;}
		try {
			return client_name + " " + BTPeerIDByteDecoderUtils.decodeAzStyleVersionNumber(
				peer_id.substring(3, 7), version_scheme
			);
		}
		catch (Exception e) {
			BTPeerIDByteDecoder.logUnknownClient(peer_id);
			return null;
		}
	
public static java.lang.StringgetMainlineStyleClientName(java.lang.String peer_id)

		return (String)mainline_style_code_map.get(peer_id.substring(0, 1));
	
public static java.lang.StringgetShadowStyleClientName(java.lang.String peer_id)

		return (String)shadow_style_code_map.get(peer_id.substring(0, 1));
	
public static com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientDatagetSubstringStyleClient(java.lang.String peer_id)

		ClientData cd = null;
		for (int i=0; i<custom_style_client_list.size(); i++) {
			cd = (ClientData)custom_style_client_list.get(i);
			if (peer_id.startsWith(cd.simple_string, cd.simple_string_pos)) {
				return cd;
			}
		}
		return null;
	
public static java.lang.StringgetSubstringStyleClientVersion(com.aelitis.azureus.core.peermanager.utils.BTPeerIDByteDecoderDefinitions$ClientData client_data, java.lang.String peer_id, byte[] peer_id_bytes)

		VersionNumberData verdata = client_data.version_data;
		if (verdata == null) {return null;}
		
		String version_scheme = verdata.type;
		String version_string = null;
		try {
			if (version_scheme == VER_TWO_BYTE_THREE_PART) {
				int start_byte_index = verdata.pos;
				version_string = BTPeerIDByteDecoderUtils.getTwoByteThreePartVersion(peer_id_bytes[start_byte_index], peer_id_bytes[start_byte_index+1]);
			}
			else if (version_scheme == VER_BLOCK && verdata.length == -1) {
				version_string = BTPeerIDByteDecoderUtils.extractReadableVersionSubstringFromPeerID(peer_id.substring(verdata.pos, peer_id.length()));
			}
			else {
				version_string = BTPeerIDByteDecoderUtils.decodeCustomVersionNumber(
					peer_id.substring(verdata.pos, verdata.pos + verdata.length), version_scheme
				);
			}
			
			if (verdata.fmt == null) {return client_data.client_name + " " + version_string;}
			else {return client_data.client_name + verdata.fmt.replaceFirst("%s", version_string);}
		}
		catch (Exception e) {
			BTPeerIDByteDecoder.logUnknownClient(peer_id);
			return null;
		}