torrent.go | 1 + url-net-addr.go | 26 ++++++++++++++++++++++++++ diff --git a/torrent.go b/torrent.go index c7cc02554afdde5e707ac00d6a9e73d337d0679b..0cfe31f0777deb3e5ac9587c5fe6aada7ddc563f 100644 --- a/torrent.go +++ b/torrent.go @@ -2114,6 +2114,7 @@ network: "http", reconciledHandshakeStats: true, peerSentHaveAll: true, PeerMaxRequests: maxRequests, + RemoteAddr: remoteAddrFromUrl(url), }, client: webseed.Client{ HttpClient: http.DefaultClient, diff --git a/url-net-addr.go b/url-net-addr.go new file mode 100644 index 0000000000000000000000000000000000000000..6558e89e0c08731c4a11bcda1aa4e3387f8cb09a --- /dev/null +++ b/url-net-addr.go @@ -0,0 +1,26 @@ +package torrent + +import ( + "net" + "net/url" +) + +type urlNetAddr struct { + u *url.URL +} + +func (me urlNetAddr) Network() string { + return me.u.Scheme +} + +func (me urlNetAddr) String() string { + return me.u.Host +} + +func remoteAddrFromUrl(urlStr string) net.Addr { + u, err := url.Parse(urlStr) + if err != nil { + return nil + } + return urlNetAddr{u} +}