从bnbt tracker源码分析bt客户端与traker的通信

本文深入解析了BNBT Tracker的工作原理,包括与BT客户端的基本交互流程及通过traker_announce.cpp进行通信的过程。详细介绍了BT客户端如何通过HTTP GET请求与Tracker交互,并解释了Tracker如何响应这些请求,记录Peer状态,以及如何在BNBT环境中识别和处理Seeder与Leecher。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

we already have some article analyse BNBT , including analyse the basic routine and the most import part around communication with bt clients.

this article also talks about the communication via traker_announce.cpp.

BT客户端据此向tracker发送GET请求,例如:
GET http://192.168.0.1:2222/announce?info_hash=w%3D%1E%FB%A2%09%8C%E5k%2A%9F%A03PQ%3E%12%2CMq&peer_id=-BC0092-%89v%5E%0A%8Cf%EB%90%B1%0D%EE%DE&port=14479&natmapped=1&localip=192.168.0.65&port_type=lan&uploaded=0&downloaded=0&left=0&numwant=200&compact=1&no_peer_id=1&key=31526&event=started HTTP/1.1

BT client send this GET method via HTTP protocol, with lots of parameters in the request.

Then, HERE IS WHAT TRACKER DO as a response:

    1. disassemble the http request  , and verify the request parmeters , return and log if not verification goes wrong.
    2. record the peers state according to the request event:(stopped, completed, started). Add unique peer if started or remove unique peer if stopped.
    3. return the peer list to the bt clients. (may cause randomize if tracker contains more than the bt client ask for numbers of peer in return )

 

Tracker did NOT tell the difference of seed and lecher in returning peers. In another word ,  the return peers might contain peers which has nothing.

BT client then communication with the return peers , to see who has the part it wants.

during handshakes protocol:

  1. am_chocking
  2. am_interested
  3. peer_chocking
  4. peer_interested

 

  • am_chocking 该值若为 1,表明客户端将远程 peer 阻塞。此时如果 peer 发送数据请求给客户端,客户端将不会理会。也就是说,一旦将 peer 阻塞,peer 就无法从客户端下载到数据;该值若为 0,则刚好相反,即表明 peer 未被阻塞,允许 peer 从客户端下载数据
  • am_interested 该值若为 1,表明客户端对远程的 peer 感兴趣。 peer 拥有某个 piece,而客户端没有,则客户端对peer 感兴趣。该值若为 0,则刚好相反,即表明客户端对 peer 不感兴趣,peer 拥有的所有 piece,客户端都拥有
  • peer_chocking 该值若为 1,表明 peer 将客户端阻塞。此时,客户端无法从 peer 处下载到数据。该值若为 0,表明客户端可以向 peer 发送数据请求,客户端将进行响应
  • peer_interested 该值若为 1,表明 peer 对客户端感兴趣。也即客户端拥有某个 piece,而 peer 没有。该值若为 0,表明 peer 对客户端不感兴趣

ps: after knowing how bnbt tracker handler the web pages message via combining string with parameters , I find it so ugly to do such kind of jobs in c , and think of how simple python can do such kind of job by template method.

EOF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值