Add support for the x.pe magnet link parameter
This commit is contained in:
parent
71b9718347
commit
b020b8c2b6
14
client.go
14
client.go
|
@ -1164,6 +1164,13 @@ func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (t *Torrent, new bool, err e
|
||||||
return
|
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.
|
// 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
|
// 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.
|
// 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 {
|
for _, url := range spec.Webseeds {
|
||||||
t.addWebSeed(url)
|
t.addWebSeed(url)
|
||||||
}
|
}
|
||||||
|
for _, peerAddr := range spec.PeerAddrs {
|
||||||
|
t.addPeer(PeerInfo{
|
||||||
|
Addr: stringAddr(peerAddr),
|
||||||
|
Source: PeerSourceDirect,
|
||||||
|
Trusted: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
if spec.ChunkSize != 0 {
|
if spec.ChunkSize != 0 {
|
||||||
t.setChunkSize(pp.Integer(spec.ChunkSize))
|
t.setChunkSize(pp.Integer(spec.ChunkSize))
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ const (
|
||||||
PeerSourceDhtGetPeers = "Hg" // Peers we found by searching a DHT.
|
PeerSourceDhtGetPeers = "Hg" // Peers we found by searching a DHT.
|
||||||
PeerSourceDhtAnnouncePeer = "Ha" // Peers that were announced to us by a DHT.
|
PeerSourceDhtAnnouncePeer = "Ha" // Peers that were announced to us by a DHT.
|
||||||
PeerSourcePex = "X"
|
PeerSourcePex = "X"
|
||||||
|
// The peer was given directly, such as through a magnet link.
|
||||||
|
PeerSourceDirect = "M"
|
||||||
)
|
)
|
||||||
|
|
||||||
type peer struct {
|
type peer struct {
|
||||||
|
|
4
spec.go
4
spec.go
|
@ -16,6 +16,7 @@ type TorrentSpec struct {
|
||||||
DisplayName string
|
DisplayName string
|
||||||
Webseeds []string
|
Webseeds []string
|
||||||
DhtNodes []string
|
DhtNodes []string
|
||||||
|
PeerAddrs []string
|
||||||
// The combination of the "xs" and "as" fields in magnet links, for now.
|
// The combination of the "xs" and "as" fields in magnet links, for now.
|
||||||
Sources []string
|
Sources []string
|
||||||
|
|
||||||
|
@ -39,7 +40,8 @@ func TorrentSpecFromMagnetUri(uri string) (spec *TorrentSpec, err error) {
|
||||||
InfoHash: m.InfoHash,
|
InfoHash: m.InfoHash,
|
||||||
Webseeds: m.Params["ws"],
|
Webseeds: m.Params["ws"],
|
||||||
Sources: append(m.Params["xs"], m.Params["as"]...),
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue