Generate a RemoteAddr for webseed Peers

This commit is contained in:
Matt Joiner 2021-01-20 14:23:25 +11:00
parent 669905e203
commit 955e337b78
2 changed files with 27 additions and 0 deletions

View File

@ -2114,6 +2114,7 @@ func (t *Torrent) addWebSeed(url string) {
reconciledHandshakeStats: true,
peerSentHaveAll: true,
PeerMaxRequests: maxRequests,
RemoteAddr: remoteAddrFromUrl(url),
},
client: webseed.Client{
HttpClient: http.DefaultClient,

26
url-net-addr.go Normal file
View File

@ -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}
}