Documentation ¶
Index ¶
- Constants
- func CopyPieceData(index int, buf []byte, msg *PeerMsg) (int, error)
- func Download(task *TorrentTask) error
- func GetIndex(msg *PeerMsg) (int, error)
- func WriteHandShake(w io.Writer, msg *HandShakeMsg) (int, error)
- type Bitfield
- type HandShakeMsg
- type MsgID
- type PeerConn
- type PeerInfo
- type PeerMsg
- type TorrentFile
- type TorrentTask
- type TrackerResp
Constants ¶
View Source
const ( BLOCKSIZE = 1024 * 16 // block = sub-piece MAXBACKLOG = 5 // 一个peer协程最多同时发送5个请求 )
View Source
const ( Reserved = 8 HsMsgLen = Reserved + SHALEN + IDLen )
View Source
const ( PeerPort = 6666 IpLen = 4 PortLen = 2 PeerLen = IpLen + PortLen IDLen = 20 )
View Source
const LenByte = 4
View Source
const SHALEN int = 20
Variables ¶
This section is empty.
Functions ¶
func CopyPieceData ¶
CopyPieceData 把通信消息中对应分片的子分片内容拷贝到内存buf中
func Download ¶
func Download(task *TorrentTask) error
func WriteHandShake ¶
func WriteHandShake(w io.Writer, msg *HandShakeMsg) (int, error)
Types ¶
type HandShakeMsg ¶
HandShakeMsg 握手消息格式:协议长度 + 协议名 + SHA-1哈希值 + peer_id
func NewHandShakeMsg ¶
func NewHandShakeMsg(infoSHA [SHALEN]byte, peerID [IDLen]byte) *HandShakeMsg
func ReadHandShake ¶
func ReadHandShake(r io.Reader) (*HandShakeMsg, error)
type PeerConn ¶
type PeerConn struct { net.Conn Choked bool Field Bitfield // contains filtered or unexported fields }
func NewPeerConn ¶
type PeerMsg ¶
func NewRequestMsg ¶
type TorrentFile ¶
type TorrentTask ¶
type TorrentTask struct { PeerID [IDLen]byte // 客户端id PeerList []PeerInfo // 获取到的peer列表 InfoSHA [SHALEN]byte // 文件哈希值 FileName string // 文件名 FileLen int // 文件长度 PieceLen int // 分片长度 PieceSHA [][SHALEN]byte // 所有分片哈希值 }
TorrentTask 下载任务的抽象
type TrackerResp ¶
Click to show internal directories.
Click to hide internal directories.