mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-19 06:43:42 +00:00
简单实现peer wire protocol协议
This commit is contained in:
1 parent
ae1c605143
commit
fb45066228
13 files changed
+859
-404
No files matched your search
@@ -30,7 +30,7 @@ type MetaInfo struct {
|
||||
type Info struct {
|
||||
Name string `json:"name"`
|
||||
PieceLength uint64 `json:"piece length"`
|
||||
Pieces []string
|
||||
Pieces [][20]byte
|
||||
Length uint64 `json:"length"`
|
||||
Files []File `json:"files"`
|
||||
}
|
||||
@@ -71,11 +71,12 @@ func ParseFromFile(path string) (*MetaInfo, error) {
|
||||
// Split pieces hash
|
||||
pieces := info["pieces"].(string)
|
||||
if pieces != "" {
|
||||
metaInfo.Info.Pieces = make([]string, len(pieces)/20)
|
||||
metaInfo.Info.Pieces = make([][20]byte, len(pieces)/20)
|
||||
// pieces parse
|
||||
for i := range metaInfo.Info.Pieces {
|
||||
begin := i * 20
|
||||
metaInfo.Info.Pieces[i] = pieces[begin : begin+20]
|
||||
metaInfo.Info.Pieces[i] = [20]byte{}
|
||||
copy(metaInfo.Info.Pieces[i][:], pieces[begin:begin+20])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ func TestParseFromFile(t *testing.T) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%+v\n", metaInfo)
|
||||
fmt.Printf("%+v\n", metaInfo.AnnounceList)
|
||||
fmt.Printf("%+v\n", metaInfo.Info.Files)
|
||||
}
|
||||
Reference in new issue
Block a user