Ed2k protocol
ed2k protocol
The amule client uses the ed2k protocol to connect to the server. This page is based on the document of emule-project.net called: "The eMule/eDonkey protocol specification" by Yoram Kulbak and Danny Bickson and intents to update all messages that have changed in order that anyone can understand ed2k protocol, be able to implement it and to understand actual source codes like amule.
This page pretends to be an explanation on how to connect to the ed2k servers, perform searchs, file sharing, etc. Note: It is created by a newbie and WILL have errors, so I hope that people can help me to complete this article.
First of all. ALL MESSAGES ARE ENCODED IN LITTLE ENDIAN (the opposite of natural order).
Messages
Tag messages
Login message
In order to connect to the network, you must have an IP address and port of an emule server. For example, if you have a emule server runing at localhost, the host will be: localhost and the port that you have configured.
After connecting, you must sent the first message to the server, this message is composed by (as the howto says):
HEADER
protocol 1 byte (default value for EMULE: 0xE3) size 4 bytes (the size of the message not including this header) type 1 byte (OP_LOGINREQUEST: 0x01)
userhash 16 bytes generated randomly (it is said that positions 6th and 15th are not randomly generated, and their values are 14 and 111 respectively). clientID 4 bytes (the fist time are 0x00 because the clientID is assigned by server). TCPport 2 bytes (default: 4662: 0x36 0x12) TagCount 4 bytes (default: 4: 0x04 0x00 0x00 0x00). CAUTION: In spite of having the name TAG is NOT a tag message.
THE TAGS (Problem: I still don't understand very well how amule creates and sends):
nametag Is a String tag (not fixed length) versiontag 8 bytes porttag 8 bytes flagstag 8 bytes
How to do test
If you are runing linux and your own donkey server
tcpdump -i lo -X
can be really usefull (lo is the loopback interface). If you want to perform translations from binary to hexadecimal
hexdump -C
is usefull too.
For example, I use netcat with hexdump to "emulate" a server:
nc -l -p PORT|hexdump -C
This allows me to see byte per byte all the login message (for example).
If you want to run your own edonkey server to perform some test and not to be banned from some official servers you can download it from: