参照以下示例代码以生成:
outPath := "./downloaded/"
var hashmapPath = "./hashmap/hashmap.json"
name := "[Sakurato] Kono Subarashii Sekai ni Bakuen wo! [12][AVC-8bit 1080p AAC][CHS].mp4"
filePath := "./testdata/" + name
newtorrent, err := torrent.NewTorrentFile(filePath, "http://localhost:8090/announce", 12*1024)
if err != nil {
log.Fatal(err)
}
err = newtorrent.SaveTorrentFile(filePath, "./have/"+name+".json", hashmapPath)
if err != nil {
log.Fatal(err)
}
server用于为下载方返回拥有资源的peer的地址
使用以下代码运行server:
go run ./server/server.go
修改peer.go的配置后运行以下代码以启动服务
go run ./peer/peer.go
可以更改peer.go中的port以启动多个服务
修改main.go的配置以后运行以下代码以开始下载
go run ./cmd/main.go