Removed summary flag. Modified fileToMmap function
This commit also reverts the ugly hack in dht.go which was checking for empty bootstrap node string.
This commit is contained in:
parent
e6e0b227da
commit
41c2773bcf
@ -26,10 +26,10 @@ func init() {
|
||||
func main() {
|
||||
b := torrent.Builder{}
|
||||
for _, filename := range flag.Args() {
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := filepath.Walk(filename, func(path string, info os.FileInfo, err error) error {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
log.Print(path)
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
|
@ -18,18 +18,9 @@ import (
|
||||
var (
|
||||
torrentPath = flag.String("torrent", "/path/to/the.torrent", "path of the torrent file")
|
||||
dataPath = flag.String("path", "/torrent/data", "path of the torrent data")
|
||||
summary = flag.Bool("summary", false, "display summary at the end")
|
||||
)
|
||||
|
||||
func verifySummary(sMap map[bool][]int) {
|
||||
fmt.Println("----------------")
|
||||
fmt.Println(" TORRENT-VERIFY ")
|
||||
fmt.Println("----------------")
|
||||
fmt.Printf("Number of correct pieces: %d\n", len(sMap[true]))
|
||||
fmt.Printf("Number of wrong pieces: %d\n", len(sMap[false]))
|
||||
}
|
||||
|
||||
func fileToMmap(filename string, length int64, devZero *os.File, mMapSpan *mmap_span.MMapSpan) {
|
||||
func fileToMmap(filename string, length int64, devZero *os.File) gommap.MMap {
|
||||
osFile, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -43,12 +34,12 @@ func fileToMmap(filename string, length int64, devZero *os.File, mMapSpan *mmap_
|
||||
log.Printf("file mmap has wrong size: %#v", filename)
|
||||
}
|
||||
osFile.Close()
|
||||
mMapSpan.Append(goMMap)
|
||||
|
||||
return goMMap
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
summaryMap := make(map[bool][]int)
|
||||
metaInfo, err := metainfo.LoadFromFile(*torrentPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@ -62,15 +53,16 @@ func main() {
|
||||
if len(metaInfo.Info.Files) > 0 {
|
||||
for _, file := range metaInfo.Info.Files {
|
||||
filename := filepath.Join(append([]string{*dataPath, metaInfo.Info.Name}, file.Path...)...)
|
||||
fileToMmap(filename, file.Length, devZero, mMapSpan)
|
||||
goMMap := fileToMmap(filename, file.Length, devZero)
|
||||
mMapSpan.Append(goMMap)
|
||||
}
|
||||
log.Println(len(metaInfo.Info.Files))
|
||||
} else {
|
||||
fileToMmap(*dataPath, metaInfo.Info.Length, devZero, mMapSpan)
|
||||
goMMap := fileToMmap(*dataPath, metaInfo.Info.Length, devZero)
|
||||
mMapSpan.Append(goMMap)
|
||||
}
|
||||
log.Println(mMapSpan.Size())
|
||||
log.Println(len(metaInfo.Info.Pieces))
|
||||
var pieceValid bool
|
||||
for piece := 0; piece < (len(metaInfo.Info.Pieces)+sha1.Size-1)/sha1.Size; piece++ {
|
||||
expectedHash := metaInfo.Info.Pieces[sha1.Size*piece : sha1.Size*(piece+1)]
|
||||
if len(expectedHash) == 0 {
|
||||
@ -81,11 +73,6 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pieceValid = bytes.Equal(hash.Sum(nil), expectedHash)
|
||||
summaryMap[pieceValid] = append(summaryMap[pieceValid], piece)
|
||||
fmt.Println(piece, pieceValid)
|
||||
}
|
||||
if *summary {
|
||||
verifySummary(summaryMap)
|
||||
fmt.Println(piece, bytes.Equal(hash.Sum(nil), expectedHash))
|
||||
}
|
||||
}
|
||||
|
@ -980,14 +980,12 @@ func bootstrapAddrs(nodeAddrs []string) (addrs []*net.UDPAddr, err error) {
|
||||
}
|
||||
}
|
||||
for _, addrStr := range bootstrapNodes {
|
||||
if addrStr != "" {
|
||||
udpAddr, err := net.ResolveUDPAddr("udp4", addrStr)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
addrs = append(addrs, udpAddr)
|
||||
}
|
||||
}
|
||||
if len(addrs) == 0 {
|
||||
err = errors.New("nothing resolved")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user