Merge pull request #13 from milosgajdos83/metainfo-trackerless
Added support for trackerless metainfo files
This commit is contained in:
commit
e71ba5210e
1
metainfo/_testdata/trackerless.torrent
Normal file
1
metainfo/_testdata/trackerless.torrent
Normal file
@ -0,0 +1 @@
|
|||||||
|
d7:comment19:This is just a test10:created by12:Johnny Bravo13:creation datei1430648794e8:encoding5:UTF-84:infod6:lengthi1128e4:name12:testfile.bin12:piece lengthi32768e6:pieces20:Õˆë =‘UŒäiÎ^æ °Eâ?ÇÒe5:nodesll35:udp://tracker.openbittorrent.com:8035:udp://tracker.openbittorrent.com:80eee
|
@ -67,6 +67,11 @@ func (b *Builder) AddAnnounceGroup(group []string) {
|
|||||||
b.announce_list = append(b.announce_list, group)
|
b.announce_list = append(b.announce_list, group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add DHT nodes URLs for trackerless mode
|
||||||
|
func (b *Builder) AddDhtNodes(group []string) {
|
||||||
|
b.node_list = append(b.node_list, group)
|
||||||
|
}
|
||||||
|
|
||||||
// Sets creation date. The default is time.Now() when the .Build method was
|
// Sets creation date. The default is time.Now() when the .Build method was
|
||||||
// called.
|
// called.
|
||||||
func (b *Builder) SetCreationDate(date time.Time) {
|
func (b *Builder) SetCreationDate(date time.Time) {
|
||||||
@ -203,20 +208,18 @@ func (b *Builder) check_parameters() error {
|
|||||||
return errors.New("no files were queued")
|
return errors.New("no files were queued")
|
||||||
}
|
}
|
||||||
|
|
||||||
// let's clean up the announce_list
|
// let's clean up the announce_list and node_list
|
||||||
newal := make([][]string, 0, len(b.announce_list))
|
b.announce_list = cleanUpLists(b.announce_list)
|
||||||
for _, ag := range b.announce_list {
|
b.node_list = cleanUpLists(b.node_list)
|
||||||
ag = remove_empty_strings(ag)
|
|
||||||
|
|
||||||
// discard empty announce groups
|
if len(b.announce_list) == 0 && len(b.node_list) == 0 {
|
||||||
if len(ag) == 0 {
|
return errors.New("no announce group or DHT nodes specified")
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
newal = append(newal, ag)
|
|
||||||
}
|
// Either the node_list or announce_list can be present
|
||||||
b.announce_list = newal
|
// Never the both!
|
||||||
if len(b.announce_list) == 0 {
|
if len(b.announce_list) > 0 && len(b.node_list) > 0 {
|
||||||
return errors.New("no announce groups were specified")
|
return errors.New("announce group and nodes are mutually exclusive")
|
||||||
}
|
}
|
||||||
|
|
||||||
// and clean up the urls
|
// and clean up the urls
|
||||||
@ -225,6 +228,20 @@ func (b *Builder) check_parameters() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanUpLists(list [][]string) [][]string {
|
||||||
|
newList := make([][]string, 0, len(list))
|
||||||
|
for _, l := range list {
|
||||||
|
l = remove_empty_strings(l)
|
||||||
|
|
||||||
|
// discard empty announce groups
|
||||||
|
if len(l) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newList = append(newList, l)
|
||||||
|
}
|
||||||
|
return newList
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
// Batch
|
// Batch
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -346,10 +363,19 @@ func (b *Batch) Start(w io.Writer, nworkers int) (<-chan error, <-chan int64) {
|
|||||||
|
|
||||||
func (b *Batch) write_torrent(w io.Writer) error {
|
func (b *Batch) write_torrent(w io.Writer) error {
|
||||||
var td MetaInfo
|
var td MetaInfo
|
||||||
|
|
||||||
|
// Either announce or node lists are allowed - not both
|
||||||
|
if len(b.announce_list) != 0 {
|
||||||
td.Announce = b.announce_list[0][0]
|
td.Announce = b.announce_list[0][0]
|
||||||
if len(b.announce_list) != 1 || len(b.announce_list[0]) != 1 {
|
if len(b.announce_list) != 1 || len(b.announce_list[0]) != 1 {
|
||||||
td.AnnounceList = b.announce_list
|
td.AnnounceList = b.announce_list
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(b.node_list) != 0 {
|
||||||
|
td.Nodes = b.node_list
|
||||||
|
}
|
||||||
|
|
||||||
td.CreationDate = b.creation_date.Unix()
|
td.CreationDate = b.creation_date.Unix()
|
||||||
td.Comment = b.comment
|
td.Comment = b.comment
|
||||||
td.CreatedBy = b.created_by
|
td.CreatedBy = b.created_by
|
||||||
@ -420,6 +446,7 @@ type batch_state struct {
|
|||||||
pieces []byte
|
pieces []byte
|
||||||
private bool
|
private bool
|
||||||
announce_list [][]string
|
announce_list [][]string
|
||||||
|
node_list [][]string
|
||||||
creation_date time.Time
|
creation_date time.Time
|
||||||
comment string
|
comment string
|
||||||
created_by string
|
created_by string
|
||||||
|
@ -144,8 +144,9 @@ func (this InfoEx) MarshalBencode() ([]byte, error) {
|
|||||||
|
|
||||||
type MetaInfo struct {
|
type MetaInfo struct {
|
||||||
Info InfoEx `bencode:"info"`
|
Info InfoEx `bencode:"info"`
|
||||||
Announce string `bencode:"announce"`
|
Announce string `bencode:"announce,omitempty"`
|
||||||
AnnounceList [][]string `bencode:"announce-list,omitempty"`
|
AnnounceList [][]string `bencode:"announce-list,omitempty"`
|
||||||
|
Nodes [][]string `bencode:"nodes,omitempty"`
|
||||||
CreationDate int64 `bencode:"creation date,omitempty"`
|
CreationDate int64 `bencode:"creation date,omitempty"`
|
||||||
Comment string `bencode:"comment,omitempty"`
|
Comment string `bencode:"comment,omitempty"`
|
||||||
CreatedBy string `bencode:"created by,omitempty"`
|
CreatedBy string `bencode:"created by,omitempty"`
|
||||||
|
@ -43,4 +43,5 @@ func TestFile(t *testing.T) {
|
|||||||
test_file(t, "_testdata/archlinux-2011.08.19-netinstall-i686.iso.torrent")
|
test_file(t, "_testdata/archlinux-2011.08.19-netinstall-i686.iso.torrent")
|
||||||
test_file(t, "_testdata/continuum.torrent")
|
test_file(t, "_testdata/continuum.torrent")
|
||||||
test_file(t, "_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent")
|
test_file(t, "_testdata/23516C72685E8DB0C8F15553382A927F185C4F01.torrent")
|
||||||
|
test_file(t, "_testdata/trackerless.torrent")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user