metainfo: It looks like the "nodes" field of metainfo was never handled correctly, support []string instead of [][]string, fix tests
This commit is contained in:
parent
7ed81fa708
commit
b3a5591d14
|
@ -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
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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) {
|
||||
}
|
|
@ -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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue