-
-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
1,821 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// This is an alternate to cmd/torrent which has become bloated with awful argument parsing. Since | ||
// this is my most complicated binary, I will try to build something that satisfies only what I need | ||
// here. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/anacrolix/torrent/metainfo" | ||
) | ||
|
||
type argError struct { | ||
err error | ||
} | ||
|
||
func assertOk(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func bail(str string) { | ||
panic(str) | ||
} | ||
|
||
func main() { | ||
args := os.Args[1:] | ||
map[string]func(){ | ||
"metainfo": func() { | ||
map[string]func(){ | ||
"validate-v2": func() { | ||
mi, err := metainfo.LoadFromFile(args[2]) | ||
assertOk(err) | ||
info, err := mi.UnmarshalInfo() | ||
assertOk(err) | ||
if !info.HasV2() { | ||
bail("not a v2 torrent") | ||
} | ||
err = metainfo.ValidatePieceLayers(mi.PieceLayers, &info.FileTree, info.PieceLength) | ||
assertOk(err) | ||
}, | ||
"pprint": func() { | ||
mi, err := metainfo.LoadFromFile(args[2]) | ||
assertOk(err) | ||
info, err := mi.UnmarshalInfo() | ||
assertOk(err) | ||
files := info.UpvertedFiles() | ||
pieceIndex := 0 | ||
for _, f := range files { | ||
numPieces := int((f.Length + info.PieceLength - 1) / info.PieceLength) | ||
endIndex := pieceIndex + numPieces | ||
fmt.Printf( | ||
"%x: %q: pieces (%v-%v)\n", | ||
f.PiecesRoot.Unwrap(), | ||
f.BestPath(), | ||
pieceIndex, | ||
endIndex-1, | ||
) | ||
pieceIndex = endIndex | ||
} | ||
}, | ||
}[args[1]]() | ||
}, | ||
}[args[0]]() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.