func (me *Client) AddTorrent(mi *metainfo.MetaInfo) (T Torrent, err error) {
T, _, err = me.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
+ var ss []string
+ missinggo.CastSlice(&ss, mi.Nodes)
+ me.AddDHTNodes(ss)
return
}
if err != nil {
return
}
- T, _, err = me.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
- return
+ return me.AddTorrent(mi)
}
func (me *Client) DHT() *dht.Server {
return me.dHT
}
+
+func (me *Client) AddDHTNodes(nodes []string) {
+ for _, n := range nodes {
+ hmp := missinggo.SplitHostPort(n)
+ ip := net.ParseIP(hmp.Host)
+ if ip == nil {
+ log.Printf("won't add DHT node with bad IP: %q", hmp.Host)
+ continue
+ }
+ ni := dht.NodeInfo{
+ Addr: dht.NewAddr(&net.UDPAddr{
+ IP: ip,
+ Port: hmp.Port,
+ }),
+ }
+ me.DHT().AddNode(ni)
+ }
+}
testAddTorrentPriorPieceCompletion(t, false)
}
-func TestAddIssue65Torrent(t *testing.T) {
+func TestAddMetainfoWithNodes(t *testing.T) {
cfg := TestingConfig
cfg.NoDHT = false
+ // For now, we want to just jam the nodes into the table, without
+ // verifying them first. Also the DHT code doesn't support mixing secure
+ // and insecure nodes if security is enabled (yet).
+ cfg.DHTConfig.NoSecurity = true
cl, err := NewClient(&cfg)
require.NoError(t, err)
defer cl.Close()