feat: peer wire protocol实现

This commit is contained in:
liwei committed 2020-02-28 18:45:41 +08:00
1 parent 7bb3e38b21
commit ee4ff7dd8b
13 files changed
+212 -165

No files matched your search

+11
View File
@@ -66,6 +66,17 @@ func (ps *pieces) size() int {
return len(ps.arr)
}
func (ps *pieces) isDone() bool {
ps.rw.RLock()
defer ps.rw.RUnlock()
for _, s := range ps.arr {
if s.state != stateFinished {
return false
}
}
return true
}
// 指定piece下的某个block是否下载完成
func (ps *pieces) isBlockDownloaded(pieceIndex int, blockIndex int) bool {
return ps.arr[pieceIndex].blocks.ContainsInt(blockIndex)