<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://test.amule.szerverem.hu/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://test.amule.szerverem.hu/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Xoneca</id>
		<title>AMule Project FAQ - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://test.amule.szerverem.hu/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Xoneca"/>
		<link rel="alternate" type="text/html" href="http://test.amule.szerverem.hu/wiki/Special:Contributions/Xoneca"/>
		<updated>2026-04-05T10:18:52Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.23.3</generator>

	<entry>
		<id>http://test.amule.szerverem.hu/wiki/EC_Protocol_HOWTO</id>
		<title>EC Protocol HOWTO</title>
		<link rel="alternate" type="text/html" href="http://test.amule.szerverem.hu/wiki/EC_Protocol_HOWTO"/>
				<updated>2009-06-29T17:55:31Z</updated>
		
		<summary type="html">&lt;p&gt;Xoneca: /* Authorization */ Response packet analised&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Work in progress, this site is under heavy construction.&lt;br /&gt;
&lt;br /&gt;
== Basic Protocol Structure ==&lt;br /&gt;
&lt;br /&gt;
EC protocol consist of two layers: a low-level ''transmission layer'', and a high level ''application layer''.&lt;br /&gt;
&lt;br /&gt;
The transmission layer consist of two int32 values.&lt;br /&gt;
&lt;br /&gt;
* A uint32 flag specify the format of the message, e.g. if the packet uses UTF-8 encoded numbers or is compressed by zlib.&lt;br /&gt;
* The next uint32 determines the size of the application layer data.&lt;br /&gt;
&lt;br /&gt;
The application layer consists of an op-code and a tag counter, followed by a tag structure.&lt;br /&gt;
&lt;br /&gt;
== Transmission layer ==&lt;br /&gt;
&lt;br /&gt;
The transmission layer is completely independent of the application layer, and holds only transport-related information.&lt;br /&gt;
&lt;br /&gt;
The transmission layer actually consists of an uint32 number, referenced below as flags, which describes flags for the current transmission session (send/receive operation).&lt;br /&gt;
&lt;br /&gt;
This four-byte value is the only one in the whole protocol that is transmitted LSB first, and zero bytes omitted (therefore an empty transmission flags value is sent as &amp;lt;tt&amp;gt;0x20&amp;lt;/tt&amp;gt;, not &amp;lt;tt&amp;gt;0x20 0x00 0x00 0x00&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Bit description ===&lt;br /&gt;
&lt;br /&gt;
* BIT 0: Compression flag. When set, zlib compression is applied to the application layer's data.&lt;br /&gt;
&lt;br /&gt;
* BIT 1: Compressed numbers. When set (presumably on small packets that don't worth compressing by zlib), all the numbers used in the protocol are encoded as a wide char converted to utf-8 to let some zero bytes not to be sent over the network.&lt;br /&gt;
&lt;br /&gt;
* BIT 2: Has ID. When this flag is set, an uint32 number follows the flags, which is the ID of this packet. The response to this packet also has to have this same ID number. The only requirement for the ID value is that they should be unique in one session (or at least do not repeat for a reasonably long time).&lt;br /&gt;
&lt;br /&gt;
* BIT 3: Reserved for later use.&lt;br /&gt;
&lt;br /&gt;
* BIT 4: Accepts value present. A client sets this flag and sends  another uint32 value (encoded as above, LSB first, zero bytes omitted), which is a fully constructed flags value, bits set meaning that the client can accept those extensions. No extensions can be used, until the other side sends an accept value for them. It is not defined when this value should be sent, best is on first transfer, but can be sent any time later, even changing the previously announced flags.&lt;br /&gt;
&lt;br /&gt;
* BIT 5: Always set to '''&amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;''', to distinguish from older (pre-rc8) clients.&lt;br /&gt;
&lt;br /&gt;
* BIT 6: Always set to '''&amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;''', to distinguish from older (pre-rc8) clients.&lt;br /&gt;
&lt;br /&gt;
* BITS 7, 15, 23: Extension flag, means that the next byte of the flags is present.&lt;br /&gt;
&lt;br /&gt;
* BITS 8-14, 16-22, 24-31: Reserved for later use.&lt;br /&gt;
&lt;br /&gt;
=== Transmission layer example ===&lt;br /&gt;
:0x30 0x23 &amp;lt;appdata&amp;gt; - Client uses no extensions on this packet, and indicates that it can accept zlib compression and compressed numbers.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
* '''Note 1:''' On the &amp;quot;&amp;lt;tt&amp;gt;accepts&amp;lt;/tt&amp;gt;&amp;quot; value, the predefined flags must be set to their predefined values, because this can be used as a sort of a sanity check.&lt;br /&gt;
&lt;br /&gt;
* '''Note 2:''' Bits marked as &amp;quot;reserved&amp;quot; should always be set to 0.&lt;br /&gt;
&lt;br /&gt;
== Application layer ==&lt;br /&gt;
&lt;br /&gt;
Data transmission is done in packets. A packet can be considered as a special tag - with no data, no &amp;lt;tt&amp;gt;tagLen&amp;lt;/tt&amp;gt; field, and with the &amp;lt;tt&amp;gt;tagCount&amp;lt;/tt&amp;gt; field always present. All numbers in the application layer are transmitted in network byte order, i.e. MSB first.&lt;br /&gt;
&lt;br /&gt;
A packet contains the following:&lt;br /&gt;
 [ec_opcode_t] OPCODE&lt;br /&gt;
 [uint16] TAGCOUNT&lt;br /&gt;
 &amp;lt;tags&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In detail: The opcode means what the data fields contain. Its type is set as &amp;lt;tt&amp;gt;ec_opcode_t&amp;lt;/tt&amp;gt;, which currently is an uint8. &amp;lt;tt&amp;gt;TagCount&amp;lt;/tt&amp;gt; is the number of first level tags this packet has. Then are the tags themselves.&lt;br /&gt;
&lt;br /&gt;
A tag consist of:&lt;br /&gt;
 [ec_tagname_t] TAGNAME&lt;br /&gt;
 [ec_tagtype_t] TAGTYPE&lt;br /&gt;
 [ec_taglen_t] TAGLEN&lt;br /&gt;
 &amp;lt;[uint16] TAGCOUNT&amp;gt;?&lt;br /&gt;
   &amp;amp;lt;sub-tags&amp;gt;&lt;br /&gt;
   &amp;lt;tag data&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ec_tagname_t&amp;lt;/tt&amp;gt; is defined as an uint16, &amp;lt;tt&amp;gt;ec_taglen_t&amp;lt;/tt&amp;gt; as an uint32 value at the moment. &amp;lt;tt&amp;gt;ec_tagtype_t&amp;lt;/tt&amp;gt; is an uint8. &amp;lt;tt&amp;gt;TagName&amp;lt;/tt&amp;gt; tells what it contains (see ECcodes.h for details). &amp;lt;tt&amp;gt;TagType&amp;lt;/tt&amp;gt; sends the type of this tag (see ECPacket.h for types) &amp;lt;tt&amp;gt;TagLen&amp;lt;/tt&amp;gt; contains the whole length of the tag, including the lengths of the possible sub-tags, but without the size of the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;tagType&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;tagLen&amp;lt;/tt&amp;gt; fields. Actually the lowest bit of the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt; doesn't belong to the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt; itself, so it has to be cleared before checking the name.&lt;br /&gt;
&lt;br /&gt;
Tags may contain sub-tags to store the information, and a &amp;lt;tt&amp;gt;tagCount&amp;lt;/tt&amp;gt; field is present only for these tags. The presence of the &amp;lt;tt&amp;gt;tagCount&amp;lt;/tt&amp;gt; field can be tested by checking the lowest bit of the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt; field, when it is set, tagCount field present.&lt;br /&gt;
&lt;br /&gt;
When a tag contains sub-tags, the sub-tags are sent before the tag's own data. So, tag data length can be calculated by substracting all sub-tags' length from the tagLen value, and the remainder is the data length, if non-zero.&lt;br /&gt;
&lt;br /&gt;
== Future Changes ==&lt;br /&gt;
&lt;br /&gt;
Future changes of the EC protocol (probably after 2.2.0) may be:&lt;br /&gt;
* No more &amp;lt;tt&amp;gt;\0&amp;lt;/tt&amp;gt; for string termination.&lt;br /&gt;
* Last bit of flag byte indicates a following flag byte, and so on.&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
You get definitions of OP- and Tag-Codes at this locations in the source:&lt;br /&gt;
* &amp;lt;tt&amp;gt;./src/lib/ec/[c#|cpp|java]/ECCodes.[cs|h|java]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;./docs/EC_Protocol.txt&amp;lt;/tt&amp;gt; (outdated, but much useful information)&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
* aMule sends EC packets in two flavours (albeit it would understand other flag options as well), depending on the packet size.&lt;br /&gt;
** zlib compressed application data that doesn't use UTF-8 compressed numbers when decompressed.&lt;br /&gt;
** UTF-8 compressed numbers in the application data&lt;br /&gt;
* The tag size doesn't take into account the size of UTF-8 compressed numbers in subtags. When parsing, you may want to drop the length completely and get it by the size of the subtags + size of the value field (determined by the value type flag).&lt;br /&gt;
&lt;br /&gt;
=== Authorization ===&lt;br /&gt;
&lt;br /&gt;
This is a packet in hex values that is sent to aMule for authorization:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 22             // flags (UTF-8 compression)&lt;br /&gt;
00 00 00 36             // packet body length (54 bytes)&lt;br /&gt;
02                      // EC_OP_AUTH_REQ&lt;br /&gt;
04                      // tag count (4 bytes)&lt;br /&gt;
&lt;br /&gt;
c8 80                   // EC_TAG_CLIENT_NAME&lt;br /&gt;
06                      // EC_TAGTYPE_STRING&lt;br /&gt;
0d                      // value length (13 bytes)&lt;br /&gt;
61 6d 75 6c 65 2d 72 65 6d 6f 74 65 00 // &amp;quot;amule-remote\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
c8 82                   // EC_TAG_CLIENT_VERSION&lt;br /&gt;
06                      // EC_TAGTYPE_STRING&lt;br /&gt;
07                      // value length (7 bytes)&lt;br /&gt;
30 78 30 30 30 31 00    // &amp;quot;0x0001\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
04                      // EC_TAG_PROTOCOL_VERSION&lt;br /&gt;
03                      // EC_TAGTYPE_UINT16&lt;br /&gt;
02                      // value length (2 bytes)&lt;br /&gt;
02 00                   // value is defined by EC_CURRENT_PROTOCOL_VERSION&lt;br /&gt;
&lt;br /&gt;
02                      // EC_TAG_PASSWD_HASH&lt;br /&gt;
09                      // EC_TAGTYPE_HASH16&lt;br /&gt;
10                      // value length (16 bytes)&lt;br /&gt;
47 bc e5 c7 4f 58 9f 48 // md5 hashed password string&lt;br /&gt;
67 db d5 7e 9c a9 f8 08 // password &amp;quot;aaa&amp;quot; was used&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c8 80&amp;lt;/tt&amp;gt; is in fact an UTF-8 encoded number. It decodes to &amp;lt;tt&amp;gt;02 00&amp;lt;/tt&amp;gt; (or 512 in decimal). As every tag code, it is shifted one bit to left to fit in a bit that indicates the presence of subtags. The lowest bit of &amp;lt;tt&amp;gt;02 00&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;; so this tag doesn't have subtags. When we shift the value to the right one bit (or divide by 2), we get &amp;lt;tt&amp;gt;01 00&amp;lt;/tt&amp;gt;. That's the value that can be found in ECCodes.h.&lt;br /&gt;
&lt;br /&gt;
And this is the '''response''' that we get from aMule if the password was good:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 20         // Flags (plain packet)&lt;br /&gt;
00 00 00 10         // Packet body length (16 bytes)&lt;br /&gt;
04                  // OpCode (EC_OP_AUTH_OK)&lt;br /&gt;
00 01               // Tag count (1)&lt;br /&gt;
&lt;br /&gt;
0a 16               // EC_TAG_SERVER_VERSION&lt;br /&gt;
06                  // EC_TAGTYPE_STRING&lt;br /&gt;
00 00 00 06         // Value length (6 bytes)&lt;br /&gt;
32 2e 32 2e 33 00   // Value: &amp;quot;2.2.3\0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;EC_OP_AUTH_OK&amp;lt;/tt&amp;gt; packet indicates that the login was successful.&lt;br /&gt;
&lt;br /&gt;
The value of the tag is the running aMule's version, in this case 2.2.3.&lt;br /&gt;
&lt;br /&gt;
If the password were wrong, aMule would terminate the connection immediately, '''without sending response'''.&lt;br /&gt;
&lt;br /&gt;
=== Search request ===&lt;br /&gt;
&lt;br /&gt;
This is a simple search request that is send without UTF-8 compressed numbers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 20             // plain format, no compression&lt;br /&gt;
00 00 00 21             // message length: 33&lt;br /&gt;
&lt;br /&gt;
26                      // EC_OP_SEARCH_START&lt;br /&gt;
00 01                   // tag count&lt;br /&gt;
    0e 03               // EC_TAG_SEARCH_TYPE&lt;br /&gt;
    02                  // EC_TAGTYPE_UINT8&lt;br /&gt;
    00 00 00 17         // tag length: 23&lt;br /&gt;
    00 02               // subtag count&lt;br /&gt;
&lt;br /&gt;
        0e 04           // EC_TAG_SEARCH_NAME&lt;br /&gt;
        06              // EC_TAGTYPE_STRING&lt;br /&gt;
        00 00 00 05     // tag length&lt;br /&gt;
        74 65 73 74 00  // &amp;quot;test\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        0e 0a           //EC_TAG_SEARCH_FILE_TYPE&lt;br /&gt;
        06              //EC_TAGTYPE_STRING&lt;br /&gt;
        00 00 00 01     // tag length&lt;br /&gt;
        00              // &amp;quot;\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    00                  // uint8 search type (local)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Xoneca</name></author>	</entry>

	<entry>
		<id>http://test.amule.szerverem.hu/wiki/User:Xoneca</id>
		<title>User:Xoneca</title>
		<link rel="alternate" type="text/html" href="http://test.amule.szerverem.hu/wiki/User:Xoneca"/>
				<updated>2009-02-01T00:15:17Z</updated>
		
		<summary type="html">&lt;p&gt;Xoneca: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi! I'm '''xOneca'''.&lt;br /&gt;
&lt;br /&gt;
I'm trying to implement ExternalConnection protocol to PHP. '''Help''' would be thanked.&lt;br /&gt;
&lt;br /&gt;
The project (called '''amule-ec-php''') is on [http://code.google.com/p/amule-ec-php/ Google Code]&lt;/div&gt;</summary>
		<author><name>Xoneca</name></author>	</entry>

	<entry>
		<id>http://test.amule.szerverem.hu/wiki/User:Xoneca</id>
		<title>User:Xoneca</title>
		<link rel="alternate" type="text/html" href="http://test.amule.szerverem.hu/wiki/User:Xoneca"/>
				<updated>2009-02-01T00:11:43Z</updated>
		
		<summary type="html">&lt;p&gt;Xoneca: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hi! I'm xOneca and I'm trying to implement ExternalConnection protocol to PHP. Help would be thanked.&lt;/div&gt;</summary>
		<author><name>Xoneca</name></author>	</entry>

	<entry>
		<id>http://test.amule.szerverem.hu/wiki/EC_Protocol_HOWTO</id>
		<title>EC Protocol HOWTO</title>
		<link rel="alternate" type="text/html" href="http://test.amule.szerverem.hu/wiki/EC_Protocol_HOWTO"/>
				<updated>2009-01-31T19:55:52Z</updated>
		
		<summary type="html">&lt;p&gt;Xoneca: Some style applied&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Work in progress, this site is under heavy construction.&lt;br /&gt;
&lt;br /&gt;
== Basic Protocol Structure ==&lt;br /&gt;
&lt;br /&gt;
EC protocol consist of two layers: a low-level ''transmission layer'', and a high level ''application layer''.&lt;br /&gt;
&lt;br /&gt;
The transmission layer consist of two int32 values.&lt;br /&gt;
&lt;br /&gt;
* A uint32 flag specify the format of the message, e.g. if the packet uses UTF-8 encoded numbers or is compressed by zlib.&lt;br /&gt;
* The next uint32 determines the size of the application layer data.&lt;br /&gt;
&lt;br /&gt;
The application layer consists of an op-code and a tag counter, followed by a tag structure.&lt;br /&gt;
&lt;br /&gt;
== Transmission layer ==&lt;br /&gt;
&lt;br /&gt;
The transmission layer is completely independent of the application layer, and holds only transport-related information.&lt;br /&gt;
&lt;br /&gt;
The transmission layer actually consists of an uint32 number, referenced below as flags, which describes flags for the current transmission session (send/receive operation).&lt;br /&gt;
&lt;br /&gt;
This four-byte value is the only one in the whole protocol that is transmitted LSB first, and zero bytes omitted (therefore an empty transmission flags value is sent as &amp;lt;tt&amp;gt;0x20&amp;lt;/tt&amp;gt;, not &amp;lt;tt&amp;gt;0x20 0x00 0x00 0x00&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Bit description ===&lt;br /&gt;
&lt;br /&gt;
* BIT 0: Compression flag. When set, zlib compression is applied to the application layer's data.&lt;br /&gt;
&lt;br /&gt;
* BIT 1: Compressed numbers. When set (presumably on small packets that don't worth compressing by zlib), all the numbers used in the protocol are encoded as a wide char converted to utf-8 to let some zero bytes not to be sent over the network.&lt;br /&gt;
&lt;br /&gt;
* BIT 2: Has ID. When this flag is set, an uint32 number follows the flags, which is the ID of this packet. The response to this packet also has to have this same ID number. The only requirement for the ID value is that they should be unique in one session (or at least do not repeat for a reasonably long time).&lt;br /&gt;
&lt;br /&gt;
* BIT 3: Reserved for later use.&lt;br /&gt;
&lt;br /&gt;
* BIT 4: Accepts value present. A client sets this flag and sends  another uint32 value (encoded as above, LSB first, zero bytes omitted), which is a fully constructed flags value, bits set meaning that the client can accept those extensions. No extensions can be used, until the other side sends an accept value for them. It is not defined when this value should be sent, best is on first transfer, but can be sent any time later, even changing the previously announced flags.&lt;br /&gt;
&lt;br /&gt;
* BIT 5: Always set to '''&amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt;''', to distinguish from older (pre-rc8) clients.&lt;br /&gt;
&lt;br /&gt;
* BIT 6: Always set to '''&amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;''', to distinguish from older (pre-rc8) clients.&lt;br /&gt;
&lt;br /&gt;
* BITS 7, 15, 23: Extension flag, means that the next byte of the flags is present.&lt;br /&gt;
&lt;br /&gt;
* BITS 8-14, 16-22, 24-31: Reserved for later use.&lt;br /&gt;
&lt;br /&gt;
=== Transmission layer example ===&lt;br /&gt;
:0x30 0x23 &amp;lt;appdata&amp;gt; - Client uses no extensions on this packet, and indicates that it can accept zlib compression and compressed numbers.&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
* '''Note 1:''' On the &amp;quot;&amp;lt;tt&amp;gt;accepts&amp;lt;/tt&amp;gt;&amp;quot; value, the predefined flags must be set to their predefined values, because this can be used as a sort of a sanity check.&lt;br /&gt;
&lt;br /&gt;
* '''Note 2:''' Bits marked as &amp;quot;reserved&amp;quot; should always be set to 0.&lt;br /&gt;
&lt;br /&gt;
== Application layer ==&lt;br /&gt;
&lt;br /&gt;
Data transmission is done in packets. A packet can be considered as a special tag - with no data, no &amp;lt;tt&amp;gt;tagLen&amp;lt;/tt&amp;gt; field, and with the &amp;lt;tt&amp;gt;tagCount&amp;lt;/tt&amp;gt; field always present. All numbers in the application layer are transmitted in network byte order, i.e. MSB first.&lt;br /&gt;
&lt;br /&gt;
A packet contains the following:&lt;br /&gt;
 [ec_opcode_t] OPCODE&lt;br /&gt;
 [uint16] TAGCOUNT&lt;br /&gt;
 &amp;lt;tags&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In detail: The opcode means what the data fields contain. Its type is set as &amp;lt;tt&amp;gt;ec_opcode_t&amp;lt;/tt&amp;gt;, which currently is an uint8. &amp;lt;tt&amp;gt;TagCount&amp;lt;/tt&amp;gt; is the number of first level tags this packet has. Then are the tags themselves.&lt;br /&gt;
&lt;br /&gt;
A tag consist of:&lt;br /&gt;
 [ec_tagname_t] TAGNAME&lt;br /&gt;
 [ec_tagtype_t] TAGTYPE&lt;br /&gt;
 [ec_taglen_t] TAGLEN&lt;br /&gt;
 &amp;lt;[uint16] TAGCOUNT&amp;gt;?&lt;br /&gt;
   &amp;amp;lt;sub-tags&amp;gt;&lt;br /&gt;
   &amp;lt;tag data&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ec_tagname_t&amp;lt;/tt&amp;gt; is defined as an uint16, &amp;lt;tt&amp;gt;ec_taglen_t&amp;lt;/tt&amp;gt; as an uint32 value at the moment. &amp;lt;tt&amp;gt;ec_tagtype_t&amp;lt;/tt&amp;gt; is an uint8. &amp;lt;tt&amp;gt;TagName&amp;lt;/tt&amp;gt; tells what it contains (see ECcodes.h for details). &amp;lt;tt&amp;gt;TagType&amp;lt;/tt&amp;gt; sends the type of this tag (see ECPacket.h for types) &amp;lt;tt&amp;gt;TagLen&amp;lt;/tt&amp;gt; contains the whole length of the tag, including the lengths of the possible sub-tags, but without the size of the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;tagType&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;tagLen&amp;lt;/tt&amp;gt; fields. Actually the lowest bit of the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt; doesn't belong to the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt; itself, so it has to be cleared before checking the name.&lt;br /&gt;
&lt;br /&gt;
Tags may contain sub-tags to store the information, and a &amp;lt;tt&amp;gt;tagCount&amp;lt;/tt&amp;gt; field is present only for these tags. The presence of the &amp;lt;tt&amp;gt;tagCount&amp;lt;/tt&amp;gt; field can be tested by checking the lowest bit of the &amp;lt;tt&amp;gt;tagName&amp;lt;/tt&amp;gt; field, when it is set, tagCount field present.&lt;br /&gt;
&lt;br /&gt;
When a tag contains sub-tags, the sub-tags are sent before the tag's own data. So, tag data length can be calculated by substracting all sub-tags' length from the tagLen value, and the remainder is the data length, if non-zero.&lt;br /&gt;
&lt;br /&gt;
== Future Changes ==&lt;br /&gt;
&lt;br /&gt;
Future changes of the EC protocol (probably after 2.2.0) may be:&lt;br /&gt;
* No more &amp;lt;tt&amp;gt;\0&amp;lt;/tt&amp;gt; for string termination.&lt;br /&gt;
* Last bit of flag byte indicates a following flag byte, and so on.&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
You get definitions of OP- and Tag-Codes at this locations in the source:&lt;br /&gt;
* &amp;lt;tt&amp;gt;./src/lib/ec/[c#|cpp|java]/ECCodes.[cs|h|java]&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;./docs/EC_Protocol.txt&amp;lt;/tt&amp;gt; (outdated, but much useful information)&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
* aMule sends EC packets in two flavours (albeit it would understand other flag options as well), depending on the packet size.&lt;br /&gt;
** zlib compressed application data that doesn't use UTF-8 compressed numbers when decompressed.&lt;br /&gt;
** UTF-8 compressed numbers in the application data&lt;br /&gt;
* The tag size doesn't take into account the size of UTF-8 compressed numbers in subtags. When parsing, you may want to drop the length completely and get it by the size of the subtags + size of the value field (determined by the value type flag).&lt;br /&gt;
&lt;br /&gt;
=== Authorization ===&lt;br /&gt;
&lt;br /&gt;
This is a packet in hex values that is sent to aMule for authorization:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 22             // flag&lt;br /&gt;
00 00 00 36             // packet body length 54&lt;br /&gt;
02                      // EC_OP_AUTH_REQ&lt;br /&gt;
04                      // tag count&lt;br /&gt;
&lt;br /&gt;
c8 80                   // EC_TAG_CLIENT_NAME&lt;br /&gt;
06                      // EC_TAGTYPE_STRING&lt;br /&gt;
0d                      // value length 13&lt;br /&gt;
61 6d 75 6c 65 2d 72 65 6d 6f 74 65 00 // &amp;quot;amule-remote\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
c8 82                   // EC_TAG_CLIENT_VERSION&lt;br /&gt;
06                      // EC_TAGTYPE_STRING&lt;br /&gt;
07                      // value length 7&lt;br /&gt;
30 78 30 30 30 31 00    // &amp;quot;0x0001\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
04                      // EC_TAG_PROTOCOL_VERSION&lt;br /&gt;
03                      // EC_TAGTYPE_UINT16&lt;br /&gt;
02                      // value length 2&lt;br /&gt;
02 00                   // value is defined by EC_CURRENT_PROTOCOL_VERSION&lt;br /&gt;
&lt;br /&gt;
02                      // EC_TAG_PASSWD_HASH&lt;br /&gt;
09                      // EC_TAGTYPE_HASH16&lt;br /&gt;
10                      // value length 16&lt;br /&gt;
47 bc e5 c7 4f 58 9f 48 // md5 hashed password string&lt;br /&gt;
67 db d5 7e 9c a9 f8 08 // password &amp;quot;aaa&amp;quot; was used&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;c8 80&amp;lt;/tt&amp;gt; is in fact an UTF-8 encoded number. It decodes to &amp;lt;tt&amp;gt;02 00&amp;lt;/tt&amp;gt; (or 512 in decimal). As every tag code, it is shifted one bit to left to fit in a bit that indicates the presence of subtags. The lowest bit of &amp;lt;tt&amp;gt;02 00&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;0&amp;lt;/tt&amp;gt;; so this tag doesn't have subtags. When we shift the value to the right one bit (or divide by 2), we get &amp;lt;tt&amp;gt;01 00&amp;lt;/tt&amp;gt;. That's the value that can be found in ECCodes.h.&lt;br /&gt;
&lt;br /&gt;
=== Search request ===&lt;br /&gt;
&lt;br /&gt;
This is a simple search request that is send without UTF-8 compressed numbers.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 20             // plain format, no compression&lt;br /&gt;
00 00 00 21             // message length: 33&lt;br /&gt;
&lt;br /&gt;
26                      // EC_OP_SEARCH_START&lt;br /&gt;
00 01                   // tag count&lt;br /&gt;
    0e 03               // EC_TAG_SEARCH_TYPE&lt;br /&gt;
    02                  // EC_TAGTYPE_UINT8&lt;br /&gt;
    00 00 00 17         // tag length: 23&lt;br /&gt;
    00 02               // subtag count&lt;br /&gt;
&lt;br /&gt;
        0e 04           // EC_TAG_SEARCH_NAME&lt;br /&gt;
        06              // EC_TAGTYPE_STRING&lt;br /&gt;
        00 00 00 05     // tag length&lt;br /&gt;
        74 65 73 74 00  // &amp;quot;test\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        0e 0a           //EC_TAG_SEARCH_FILE_TYPE&lt;br /&gt;
        06              //EC_TAGTYPE_STRING&lt;br /&gt;
        00 00 00 01     // tag length&lt;br /&gt;
        00              // &amp;quot;\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    00                  // uint8 search type (local)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Xoneca</name></author>	</entry>

	<entry>
		<id>http://test.amule.szerverem.hu/wiki/EC_Protocol_HOWTO</id>
		<title>EC Protocol HOWTO</title>
		<link rel="alternate" type="text/html" href="http://test.amule.szerverem.hu/wiki/EC_Protocol_HOWTO"/>
				<updated>2009-01-31T18:58:48Z</updated>
		
		<summary type="html">&lt;p&gt;Xoneca: /* Transmission layer */ 32 bits: from 0 to 31 (not to 32)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Work in progress, this site is under heavy construction.&lt;br /&gt;
&lt;br /&gt;
== Basic Protocol Structure ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Protocol definition'''&lt;br /&gt;
&lt;br /&gt;
Short description:&lt;br /&gt;
&lt;br /&gt;
EC protocol consist of two layers: a low-level transmission layer, and&lt;br /&gt;
a high level application layer.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The transmission layer consist of two int32 values.&amp;lt;br&amp;gt;&lt;br /&gt;
A uint32 flag specify the format of the message e.g. if the packet uses utf8 encoded numbers or is compressed by zlib.&amp;lt;br&amp;gt;&lt;br /&gt;
The next uint32 determines the size of the application layer data.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The application layer consists of an op-code and a tag counter,followed by a tag structure.&lt;br /&gt;
&lt;br /&gt;
== Transmission layer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The transmission layer is completely independent of the application layer,&amp;lt;br&amp;gt;&lt;br /&gt;
and holds only transport-related information.&lt;br /&gt;
&lt;br /&gt;
The transmission layer actually consists of an uint32 number, referenced below as flags,&amp;lt;br&amp;gt;&lt;br /&gt;
which describes flags for the current transmission session (send/receive operation).&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This four-byte value is the only one in the whole protocol, that is transmitted LSB first,&amp;lt;br&amp;gt;&lt;br /&gt;
and zero bytes omitted (therefore an empty transmission flags value is sent as 0x20, not 0x20 0x0 0x0 0x0).&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Bit description:&lt;br /&gt;
&lt;br /&gt;
:bit 0: Compression flag. When set, zlib compression is applied to the application layer's data.&lt;br /&gt;
&lt;br /&gt;
:bit 1: Compressed numbers. When set (presumably on small packets that doesn't worth compressing by zlib), all the numbers used&lt;br /&gt;
::in the protocol are encoded as a wide char converted to utf-8 to let some zero bytes not to be sent over the network&lt;br /&gt;
&lt;br /&gt;
:bit 2: Has ID. When this flag is set, an uint32 number follows the flags, which is the ID of this packet. The response to this&lt;br /&gt;
::packet also has to have this ID. The only requirement for the ID value is that they should be unique in one session (or at&lt;br /&gt;
::least do not repeat for a reasonably long time.)&lt;br /&gt;
&lt;br /&gt;
:bit 3: Reserved for later use.&lt;br /&gt;
&lt;br /&gt;
:bit 4: Accepts value present. A client sets this flag and sends  another uint32 value (encoded as above, LSB first, zero&lt;br /&gt;
::bytes omitted), which is a fully constructed flags value, bits set meaning that the client can accept those extensions.&lt;br /&gt;
::No extensions can be used, until the other side sends an accept value for them. It is not defined when this value&lt;br /&gt;
::should be send, best is on first transfer, but can be sent any time later, even changing the previously announced flags.&lt;br /&gt;
&lt;br /&gt;
:bit 5: Always set to 1, to distinguish from older (pre-rc8) clients.&lt;br /&gt;
&lt;br /&gt;
:bit 6: Always set to 0, to distinguish from older (pre-rc8) clients.&lt;br /&gt;
&lt;br /&gt;
:bits 7,15,23: Extension flag, means that the next byte of the flags is present.&lt;br /&gt;
&lt;br /&gt;
:bits 8-14,16-22,24-31: Reserved for later use.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Transmission layer example:&lt;br /&gt;
:0x30 0x23 &amp;lt;appdata&amp;gt; - Client uses no extensions on this packet, and indicates that it can accept zlib compression and compressed numbers.&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
:Note 1: On the &amp;quot;accepts&amp;quot; value, the predefined flags must be set to their predefined values, because this can be used as a sort of a sanity check.&lt;br /&gt;
&lt;br /&gt;
:Note 2: Bits marked as &amp;quot;reserved&amp;quot; should always be set to 0.&lt;br /&gt;
&lt;br /&gt;
== Application layer ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Data transmission is done in packets. A packet can be considered as&amp;lt;br&amp;gt;&lt;br /&gt;
a special tag - with no data, no tagLen field, and with the tagCount&amp;lt;br&amp;gt;&lt;br /&gt;
field always present. All numbers part of the application layer are&amp;lt;br&amp;gt;&lt;br /&gt;
transmitted in network byte order, i.e. MSB first.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:A packet contains the following:&lt;br /&gt;
::[ec_opcode_t] OPCODE&lt;br /&gt;
::[uint16] TAGCOUNT&lt;br /&gt;
::&amp;lt;tags&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In detail: The opcode means what to to or what the data fields contain.&amp;lt;br&amp;gt;&lt;br /&gt;
Its type is set as ec_opcode_t, which currently is an uint8.&amp;lt;br&amp;gt;&lt;br /&gt;
TagCount is the number of first level tags this packet has. Then are the&amp;lt;br&amp;gt;&lt;br /&gt;
tags themselves.&lt;br /&gt;
&lt;br /&gt;
:A tag consist of:&lt;br /&gt;
::[ec_tagname_t] TAGNAME&lt;br /&gt;
::[ec_tagtype_t] TAGTYPE&lt;br /&gt;
::[ec_taglen_t] TAGLEN&lt;br /&gt;
::&amp;lt;[uint16] TAGCOUNT&amp;gt;?&lt;br /&gt;
:::&amp;amp;lt;sub-tags&amp;amp;gt;&lt;br /&gt;
:::&amp;lt;tag data&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The ec_tagname_t is defined as an uint16, ec_taglen_t as an uint32 value&amp;lt;br&amp;gt;&lt;br /&gt;
at the moment. ec_tagtype_t is an uint8. &amp;lt;br&amp;gt;&lt;br /&gt;
TagName tells what it contains (see ECcodes.h for details).&amp;lt;br&amp;gt;&lt;br /&gt;
TagType sends the type of this tag (see ECPacket.h for types)&amp;lt;br&amp;gt;&lt;br /&gt;
TagLen contains the whole length of the tag, including the lengths of the&amp;lt;br&amp;gt;&lt;br /&gt;
possible sub-tags, but without the size of the tagName, tagType and &amp;lt;br&amp;gt;&lt;br /&gt;
tagLen fields. Actually the lowest bit of the tagname doesn't belong to the &amp;lt;br&amp;gt;&lt;br /&gt;
tagName itself, so it has to be cleared before checking the name.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tags may contain sub-tags to store the information, and a tagCount field&amp;lt;br&amp;gt;&lt;br /&gt;
is present only for these tags. The presence of the tagCount field can&amp;lt;br&amp;gt;&lt;br /&gt;
be tested by checking the lowest bit of the tagName field, when it is&amp;lt;br&amp;gt;&lt;br /&gt;
set, tagCount field present.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When a tag contains sub-tags, the sub-tags are sent before the tag's own&amp;lt;br&amp;gt;&lt;br /&gt;
data. So, tag data length can be calculated by substracting all sub-tags'&amp;lt;br&amp;gt;&lt;br /&gt;
length from the tagLen value, and the remainder is the data length, if&amp;lt;br&amp;gt;&lt;br /&gt;
non-zero.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Future Changes ==&lt;br /&gt;
&lt;br /&gt;
Future changes of the EC protocol (probably after 2.2.0) may be:&lt;br /&gt;
*no more \0 for string termination&lt;br /&gt;
*last bit of flag byte indicates a following flag byte, and so on&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
You get definitions of OP- and Tag-Codes at this locations in the source:&lt;br /&gt;
*./src/lib/ec/[c#|cpp|java]/ECCodes.[cs|h|java]&lt;br /&gt;
* ./docs/EC_Protocol.txt (outdated, but much useful information)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
*aMule sends EC packets in two flavours (albeit it would understand other flag options as well), depending on the packet size.&lt;br /&gt;
**zlib compressed application data that doesn't use utf8 compressed numbers when decompressed.&lt;br /&gt;
**utf8 compressed numbers in the application data&lt;br /&gt;
*The tag size doesn't take into account the size of utf8 compressed numbers in subtags. When parsing, you may want to drop the length completely and get it by the size of the subtags + size of the value field (determined by the value type flag).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a packet in hex values that is send to aMule&lt;br /&gt;
for authorization:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 22 //flag&lt;br /&gt;
00 00 00 36 //packet body length 54&lt;br /&gt;
02      //EC_OP_AUTH_REQ&lt;br /&gt;
04      //tag count&lt;br /&gt;
&lt;br /&gt;
c8 80          //EC_TAG_CLIENT_NAME&lt;br /&gt;
06             //EC_TAGTYPE_STRING&lt;br /&gt;
0d             //value length 13&lt;br /&gt;
61 6d 75 6c 65 2d 72 65 6d 6f 74 65 00 //&amp;quot;amule-remote\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
c8 82          //EC_TAG_CLIENT_VERSION&lt;br /&gt;
06             //EC_TAGTYPE_STRING&lt;br /&gt;
07             //value length 7&lt;br /&gt;
30 78 30 30 30 31 00 // &amp;quot;0x0001\0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
04             //EC_TAG_PROTOCOL_VERSION&lt;br /&gt;
03             //EC_TAGTYPE_UINT16&lt;br /&gt;
02             //value length 2&lt;br /&gt;
02 00          //value is defined by EC_CURRENT_PROTOCOL_VERSION&lt;br /&gt;
&lt;br /&gt;
02              //EC_TAG_PASSWD_HASH&lt;br /&gt;
09             //EC_TAGTYPE_HASH16&lt;br /&gt;
10             //value length 16&lt;br /&gt;
47 bc e5 c7 4f 58 9f 48 //md5 hashed password string&lt;br /&gt;
67 db d5 7e 9c a9 f8 08 //password &amp;quot;aaa&amp;quot; was used&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
c8 80 is in fact an utf8 encoded number. It decodes to 02 00 (or 512 in decimal).&amp;lt;br&amp;gt;&lt;br /&gt;
As every tag code, it is shifted one bit to left to&lt;br /&gt;
fit in a bit that indicates the presence of subtags.&amp;lt;br&amp;gt;&lt;br /&gt;
The lowest bit of 02 00 is 0; so this tag doesn't have subtags.&amp;lt;br&amp;gt;&lt;br /&gt;
When we shift the value to the right one bit (or divide by 2),&lt;br /&gt;
we get 01 00.&amp;lt;br&amp;gt;&lt;br /&gt;
That's the value that can be found in ECCodes.h.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is a simple search request that is send without utf8 compressed numbers.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
00 00 00 20 //plain format, no compression&lt;br /&gt;
00 00 00 21 //message length: 33&lt;br /&gt;
 &lt;br /&gt;
26	//EC_OP_SEARCH_START&lt;br /&gt;
00 01	//tag count&lt;br /&gt;
	0e 03	//EC_TAG_SEARCH_TYPE&lt;br /&gt;
	02	//EC_TAGTYPE_UINT8&lt;br /&gt;
	00 00 00 17	//tag length: 23&lt;br /&gt;
	00 02	//subtag count&lt;br /&gt;
&lt;br /&gt;
		0e 04		//EC_TAG_SEARCH_NAME&lt;br /&gt;
		06		//EC_TAGTYPE_STRING&lt;br /&gt;
		00 00 00 05	//tag length&lt;br /&gt;
		74 65 73 74 00 	//&amp;quot;test\0&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
		0e 0a		//EC_TAG_SEARCH_FILE_TYPE&lt;br /&gt;
		06		//EC_TAGTYPE_STRING&lt;br /&gt;
		00 00 00 01	//tag length&lt;br /&gt;
		00		//&amp;quot;\0&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
	00			//uint8 search type (local)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Xoneca</name></author>	</entry>

	</feed>