zoukankan      html  css  js  c++  java
  • 从bnbt tracker源码分析bt客户端与traker的通信

    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

  • 相关阅读:
    ASP.NET缓存全解析(系列)
    updateprogress用法技巧
    text与img对齐
    9款Firefox插件提高设计开发效率
    ASP.NET页面实时进行GZIP压缩优化
    如何收缩和删除SQL日志文件
    闲扯加班
    与大家分享一点游戏管理晋升的心得(完整版)
    FDS (Flex Data Services)
    和我老婆去旅游
  • 原文地址:https://www.cnblogs.com/no7dw/p/2877295.html
Copyright © 2011-2022 走看看