SimpleTorrent
成员变量
PeerMsg结构体 参考

BT 消息 更多...

#include <peer.h>

成员变量

uint32_t len
 后续消息长度(不包含 len 自身的 4 个字节)
 
uint8_t id
 消息编号
 
union {
   struct {
      uint32_t   piece_index
 分片号
 
   }   have
 HAVE 消息
 
   uint8_t   bitfield [0]
 位域消息,变长
 
   struct {
      uint32_t   index
 分片号
 
      uint32_t   begin
 子分片起始偏移量
 
      uint32_t   length
 子分片长度
 
   }   request
 REQUEST 消息
 
   struct {
      uint32_t   index
 分片号
 
      uint32_t   begin
 子分片起始偏移量
 
      uint8_t   block [0]
 边长数据块
 
   }   piece
 PIECE 消息
 
   struct {
      uint32_t   index
 分片号
 
      uint32_t   begin
 子分片起始偏移量
 
      uint32_t   length
 子分片长度
 
   }   cancel
 CANCEL 消息
 
}; 
 

详细描述

BT 消息

构造模式

uint32_t len;
read(fd, &len, sizeof(len));
PeerMsg *msg = malloc(len);
read(fd, &msg->id, len);
msg->len = len;

len 大部分时候是不需要的,但是可边长的 bitfield 和 block 报文自身不带长度,只能靠 len 计算得出。


该结构体的文档由以下文件生成: