}()
}
+type stringAddr string
+
+func (stringAddr) Network() string { return "" }
+func (me stringAddr) String() string { return string(me) }
+
+func resolveTestPeers(addrs []string) (ret []torrent.PeerInfo) {
+ for _, ta := range flags.TestPeer {
+ ret = append(ret, torrent.PeerInfo{
+ Addr: stringAddr(ta),
+ })
+ }
+ return
+}
+
func addTorrents(client *torrent.Client) error {
+ testPeers := resolveTestPeers(flags.TestPeer)
for _, arg := range flags.Torrent {
t, err := func() (*torrent.Torrent, error) {
if strings.HasPrefix(arg, "magnet:") {
if flags.Progress {
torrentBar(t, flags.PieceStates)
}
- t.AddPeers(func() (ret []torrent.PeerInfo) {
- for _, ta := range flags.TestPeer {
- ret = append(ret, torrent.PeerInfo{
- Addr: ta,
- })
- }
- return
- }())
+ t.AddPeers(testPeers)
go func() {
<-t.GotInfo()
t.DownloadAll()
}
var flags = struct {
- Mmap bool `help:"memory-map torrent data"`
- TestPeer []*net.TCPAddr `help:"addresses of some starting peers"`
- Seed bool `help:"seed after download is complete"`
- Addr string `help:"network listen addr"`
- UploadRate tagflag.Bytes `help:"max piece bytes to send per second"`
- DownloadRate tagflag.Bytes `help:"max bytes per second down from peers"`
+ Mmap bool `help:"memory-map torrent data"`
+ TestPeer []string `help:"addresses of some starting peers"`
+ Seed bool `help:"seed after download is complete"`
+ Addr string `help:"network listen addr"`
+ UploadRate tagflag.Bytes `help:"max piece bytes to send per second"`
+ DownloadRate tagflag.Bytes `help:"max bytes per second down from peers"`
Debug bool
PackedBlocklist string
Stats *bool