metainfo/builder.go | 15 ++++++++++++--- metainfo/metainfo.go | 2 +- metainfo/nodes_test.go | 20 ++++++++++++++++++++ metainfo/testdata/trackerless.torrent | 2 +- diff --git a/metainfo/builder.go b/metainfo/builder.go index 72683bb564fd7d246906b2978d752c102b2d93bf..b600f18880c85cfcd84c40153fe2ba2dcfc94c8c 100644 --- a/metainfo/builder.go +++ b/metainfo/builder.go @@ -69,7 +69,7 @@ } // Add DHT nodes URLs for trackerless mode func (b *Builder) AddDhtNodes(group []string) { - b.node_list = append(b.node_list, group) + b.node_list = append(b.node_list, group...) } // Sets creation date. The default is time.Now() when the .Build method was @@ -202,6 +202,15 @@ b.encoding = "UTF-8" } } +func emptyStringsFiltered(ss []string) (ret []string) { + for _, s := range ss { + if s != "" { + ret = append(ret, s) + } + } + return +} + func (b *Builder) check_parameters() error { // should be at least one file if len(b.filesmap) == 0 { @@ -210,7 +219,7 @@ } // let's clean up the announce_list and node_list b.announce_list = cleanUpLists(b.announce_list) - b.node_list = cleanUpLists(b.node_list) + b.node_list = emptyStringsFiltered(b.node_list) if len(b.announce_list) == 0 && len(b.node_list) == 0 { return errors.New("no announce group or DHT nodes specified") @@ -446,7 +455,7 @@ piece_length int64 pieces []byte private bool announce_list [][]string - node_list [][]string + node_list []string creation_date time.Time comment string created_by string diff --git a/metainfo/metainfo.go b/metainfo/metainfo.go index ad674887572efdf5f1f578a0408f0e6f16ff63e1..dd8fc6d8db965e358cb2c77022bc70c610f307e9 100644 --- a/metainfo/metainfo.go +++ b/metainfo/metainfo.go @@ -233,7 +233,7 @@ type MetaInfo struct { Info InfoEx `bencode:"info"` Announce string `bencode:"announce,omitempty"` AnnounceList [][]string `bencode:"announce-list,omitempty"` - Nodes [][]string `bencode:"nodes,omitempty"` + Nodes []string `bencode:"nodes,omitempty"` CreationDate int64 `bencode:"creation date,omitempty"` Comment string `bencode:"comment,omitempty"` CreatedBy string `bencode:"created by,omitempty"` diff --git a/metainfo/nodes_test.go b/metainfo/nodes_test.go new file mode 100644 index 0000000000000000000000000000000000000000..c9438b7e88570e393fe8587fadc39b68dae6b5c1 --- /dev/null +++ b/metainfo/nodes_test.go @@ -0,0 +1,20 @@ +package metainfo + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestNodesListStrings(t *testing.T) { + mi, err := LoadFromFile("testdata/trackerless.torrent") + require.NoError(t, err) + assert.EqualValues(t, []string{ + "udp://tracker.openbittorrent.com:80", + "udp://tracker.openbittorrent.com:80", + }, mi.Nodes) +} + +func TestNodesListPairsBEP5(t *testing.T) { +} diff --git a/metainfo/testdata/trackerless.torrent b/metainfo/testdata/trackerless.torrent index b90f253ea701ad30ce8d179372e40fe60f0fc5ba..65372766f53640de6bd92c554107aee2958a65e0 100644 --- a/metainfo/testdata/trackerless.torrent +++ b/metainfo/testdata/trackerless.torrent @@ -1 +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 \ No newline at end of file +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:nodesl35:udp://tracker.openbittorrent.com:8035:udp://tracker.openbittorrent.com:80ee