cleverbum Posted June 6, 2009 Share Posted June 6, 2009 I'm practicing some stuff on networking, and have found that bittorrent one of the more documented protocols out there, and it's pretty easy to get hold of some people to practice connecting to!! While I understand it might be against the rules of the board, I'm a little bit stuck, and was hoping that someone could help out. The protocol calls for a handshake that meets the following rules: The handshake is a required message and must be the first message transmitted by the client. It is (49+len(pstr)) bytes long. handshake: <pstrlen><pstr><reserved><info_hash><peer_id> * pstrlen: string length of <pstr>, as a single raw byte * pstr: string identifier of the protocol * reserved: eight ( reserved bytes. All current implementations use all zeroes. * info_hash: 20-byte SHA1 hash of the info key in the metainfo file. This is the same info_hash that is transmitted in tracker requests. * peer_id: 20-byte string used as a unique ID for the client. This is usually the same peer_id that is transmitted in tracker requests (but not always e.g. an anonymity option in Azureus). In version 1.0 of the BitTorrent protocol, pstrlen = 19, and pstr = "BitTorrent protocol". I'm using the following code to try to create this message, but it never seems to work. $buffer="000".decbin(19); $buffer.="BitTorrent protocol"; $buffer.="00000000";//pack("x8"); // the info hash is read in, and the userID apparently usually starts with -AZ2060- $buffer.=$info_hash."-AZ2060-".substr(sha1("its martinklefas-stennett!!!"),0,20-strlen("-AZ2060-")); I think I've fundamentally misunderstood how to make a custom binary string, so any help would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
XaeroDegreaz Posted June 7, 2009 Share Posted June 7, 2009 I'm not sure, but in most PHP socket connections, the string must be terminated by a zero byte character, chr(0). Try appending that to your string? I'd be happy to help you out further if you need. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.