diff --git a/client.go b/client.go index 8dce3d40..2ca1661d 100644 --- a/client.go +++ b/client.go @@ -1164,6 +1164,13 @@ func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (t *Torrent, new bool, err e return } +type stringAddr string + +var _ net.Addr = stringAddr("") + +func (stringAddr) Network() string { return "" } +func (me stringAddr) String() string { return string(me) } + // The trackers will be merged with the existing ones. If the Info isn't yet known, it will be set. // spec.DisallowDataDownload/Upload will be read and applied // The display name is replaced if the new spec provides one. Note that any `Storage` is ignored. @@ -1185,6 +1192,13 @@ func (t *Torrent) MergeSpec(spec *TorrentSpec) error { for _, url := range spec.Webseeds { t.addWebSeed(url) } + for _, peerAddr := range spec.PeerAddrs { + t.addPeer(PeerInfo{ + Addr: stringAddr(peerAddr), + Source: PeerSourceDirect, + Trusted: true, + }) + } if spec.ChunkSize != 0 { t.setChunkSize(pp.Integer(spec.ChunkSize)) } diff --git a/peerconn.go b/peerconn.go index 48acbc11..50c86ad6 100644 --- a/peerconn.go +++ b/peerconn.go @@ -34,6 +34,8 @@ const ( PeerSourceDhtGetPeers = "Hg" // Peers we found by searching a DHT. PeerSourceDhtAnnouncePeer = "Ha" // Peers that were announced to us by a DHT. PeerSourcePex = "X" + // The peer was given directly, such as through a magnet link. + PeerSourceDirect = "M" ) type peer struct { diff --git a/spec.go b/spec.go index 0818a99c..7de7aa61 100644 --- a/spec.go +++ b/spec.go @@ -16,6 +16,7 @@ type TorrentSpec struct { DisplayName string Webseeds []string DhtNodes []string + PeerAddrs []string // The combination of the "xs" and "as" fields in magnet links, for now. Sources []string @@ -39,7 +40,8 @@ func TorrentSpecFromMagnetUri(uri string) (spec *TorrentSpec, err error) { InfoHash: m.InfoHash, Webseeds: m.Params["ws"], Sources: append(m.Params["xs"], m.Params["as"]...), - // TODO: What's the parameter for DHT nodes or bootstrap peers in a magnet link? + PeerAddrs: m.Params["x.pe"], // BEP 9 + // TODO: What's the parameter for DHT nodes? } return }