]> Sergey Matveev's repositories - btrtrc.git/commitdiff
metainfo: It looks like the "nodes" field of metainfo was never handled correctly...
authorMatt Joiner <anacrolix@gmail.com>
Tue, 23 Feb 2016 11:04:06 +0000 (22:04 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 23 Feb 2016 11:04:06 +0000 (22:04 +1100)
metainfo/builder.go
metainfo/metainfo.go
metainfo/nodes_test.go [new file with mode: 0644]
metainfo/testdata/trackerless.torrent

index 72683bb564fd7d246906b2978d752c102b2d93bf..b600f18880c85cfcd84c40153fe2ba2dcfc94c8c 100644 (file)
@@ -69,7 +69,7 @@ func (b *Builder) AddAnnounceGroup(group []string) {
 
 // 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 @@ func (b *Builder) set_defaults() {
        }
 }
 
+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 @@ func (b *Builder) check_parameters() error {
 
        // 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 @@ type batch_state struct {
        pieces        []byte
        private       bool
        announce_list [][]string
-       node_list     [][]string
+       node_list     []string
        creation_date time.Time
        comment       string
        created_by    string
index ad674887572efdf5f1f578a0408f0e6f16ff63e1..dd8fc6d8db965e358cb2c77022bc70c610f307e9 100644 (file)
@@ -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 (file)
index 0000000..c9438b7
--- /dev/null
@@ -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) {
+}
index b90f253ea701ad30ce8d179372e40fe60f0fc5ba..65372766f53640de6bd92c554107aee2958a65e0 100644 (file)
@@ -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:Õ\88ë        =\91U\8cä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:Õ\88ë        =\91U\8cäiÎ^æ °Eâ?ÇÒe5:nodesl35:udp://tracker.openbittorrent.com:8035:udp://tracker.openbittorrent.com:80ee