单个peer的文件下载实现

This commit is contained in:
liwei committed 2019-10-08 16:56:22 +08:00
1 parent fe0138440f
commit 15a4b6ddc4
9 files changed
+179 -48

No files matched your search

+4 -3
View File
@@ -2,13 +2,13 @@ package message
// bitfield: <len=0001+X><id=5><bitfield>
type Bitfield struct {
Message
*Message
payload []byte
}
func NewBitfield(payload []byte) *Bitfield {
return &Bitfield{
Message: Message{
Message: &Message{
Length: uint32(len(payload) + 1),
ID: IdBitfield,
},
@@ -21,8 +21,9 @@ func (b *Bitfield) Encode() []byte {
}
func (b *Bitfield) Decode(buf []byte) Serialize {
b.Message = &Message{}
b.Message.Decode(buf)
copy(b.payload, buf[5:])
b.payload = buf[5:]
return b
}