Alo Sarv
lead developer

Donate via
MoneyBookers

Latest Builds

version 0.3
tar.gz tar.bz2
Boost 1.33.1 Headers
MLDonkey Downloads Import Module Development
Payment completed
Development in progress.
Developer's Diary
irc.hydranode.com/#hydranode

Sunday, August 28, 2005

[BitTorrent] Implementing Client management

I hate client management. Seriously. In ed2k module, it took literally months to get it working in a stable manner. Let's hope this won't be the case in Bittorrent module.

To get us started in that area, I drafted another short design doc, which among other things, addresses the client / torrent management issues. Read it here.

There are also some interesting new files in svn, for example:
hncore/bt/client.h
hncore/bt/client.cpp
hncore/bt/manager.h
hncore/bt/manager.cpp
Yeye, I know, documentation is missing - I'll do that once the code stabilizes a bit.

Basically, I implemented all of the protocol Client <-> Client packets, along with client management and messages passing. Next up, we need to start adding protocol flow logic - and that's tricky at best. Bittorrent protocol, while being very small itself (as you can see in client.cpp - that's all of the protocol, implemented in under 300 lines of code), the packet flow logic on the other hand is very complex. We'll be testing, tuning and improving that one for weeks to come.

However, the most current issue is that I can't get my handshake packet right. In all protocol specs (official, unofficial), it says "1 byte of value "19", string "BitTorrent Protocol", 8 reserved bytes, 20 bytes info_hash and 20 bytes peer-id". I event went to look inside libtorrent code, and it's same in there. I'm sending this:
00000000  13 42 69 74 54 6f 72 72  65 6e 74 20 70 72 6f 74  |.BitTorrent.prot|
00000010 6f 63 6f 6c 00 00 00 00 00 00 00 00 00 00 e8 17 |ocol............|
00000020 b8 80 24 a2 58 b9 77 7f c1 98 fc 0e 75 a1 49 60 |..$.X.w.....u.I`|
00000030 0d c2 48 4e 30 31 32 30 39 38 33 34 33 38 30 37 |..HN012098343807|
00000040 30 32 35 31 39 37 |025197|
And all clients just drop the connection. Got some extra info from Azureus - it basically seems to recognize the handshake, and even sends response, but then bails out and cuts the connection with error "unexpected end of stream". Am I supposed to send something else right after handshake? *duh*.

Madcat, ZzZz



Comments:
Maybe I am getting something wrong here, but you say 1 byte of value "19" while you send "13"??
 
19 == 0x13 (hexademical 13)
 
hexadecimal...
 
so maybe you must send hex 19, not dec 19...
 
you are sending 10 reserved bytes instead of 8...
 
*doh*, now that's stupid :) I re-counted by bytes by hand multiple times, and got 8 total each time. Even in code, I wrote:

Utils::putVal<uint64_t>(tmp, 0); // 8 zero bytes
Utils::putVal<uint16_t>(tmp, 0); // 2 more zero bytes

*doh* ... thanks :)

Madcat.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?