Tidy up webseed peer naming and unused types
This commit is contained in:
parent
62e7f29a0c
commit
12ace95493
|
@ -2033,7 +2033,7 @@ func (t *Torrent) addWebSeed(url string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const maxRequests = 10
|
const maxRequests = 10
|
||||||
ws := webSeed{
|
ws := webseedPeer{
|
||||||
peer: peer{
|
peer: peer{
|
||||||
t: t,
|
t: t,
|
||||||
connString: url,
|
connString: url,
|
||||||
|
|
|
@ -2,7 +2,6 @@ package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/common"
|
"github.com/anacrolix/torrent/common"
|
||||||
"github.com/anacrolix/torrent/metainfo"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
|
@ -11,76 +10,61 @@ import (
|
||||||
"github.com/anacrolix/torrent/webseed"
|
"github.com/anacrolix/torrent/webseed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type httpRequestResult struct {
|
type webseedPeer struct {
|
||||||
resp *http.Response
|
|
||||||
err error
|
|
||||||
}
|
|
||||||
|
|
||||||
type requestPart struct {
|
|
||||||
req *http.Request
|
|
||||||
e segments.Extent
|
|
||||||
result chan httpRequestResult
|
|
||||||
}
|
|
||||||
|
|
||||||
type webseedRequest struct {
|
|
||||||
cancel func()
|
|
||||||
}
|
|
||||||
|
|
||||||
type webSeed struct {
|
|
||||||
client webseed.Client
|
client webseed.Client
|
||||||
requests map[request]webseed.Request
|
requests map[request]webseed.Request
|
||||||
peer peer
|
peer peer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ peerImpl = (*webSeed)(nil)
|
var _ peerImpl = (*webseedPeer)(nil)
|
||||||
|
|
||||||
func (ws *webSeed) String() string {
|
func (ws *webseedPeer) String() string {
|
||||||
return fmt.Sprintf("webseed peer for %q", ws.client.Url)
|
return fmt.Sprintf("webseed peer for %q", ws.client.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) onGotInfo(info *metainfo.Info) {
|
func (ws *webseedPeer) onGotInfo(info *metainfo.Info) {
|
||||||
ws.client.FileIndex = segments.NewIndex(common.LengthIterFromUpvertedFiles(info.UpvertedFiles()))
|
ws.client.FileIndex = segments.NewIndex(common.LengthIterFromUpvertedFiles(info.UpvertedFiles()))
|
||||||
ws.client.Info = info
|
ws.client.Info = info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) _postCancel(r request) {
|
func (ws *webseedPeer) _postCancel(r request) {
|
||||||
ws.cancel(r)
|
ws.cancel(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) writeInterested(interested bool) bool {
|
func (ws *webseedPeer) writeInterested(interested bool) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) cancel(r request) bool {
|
func (ws *webseedPeer) cancel(r request) bool {
|
||||||
ws.requests[r].Cancel()
|
ws.requests[r].Cancel()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) intoSpec(r request) webseed.RequestSpec {
|
func (ws *webseedPeer) intoSpec(r request) webseed.RequestSpec {
|
||||||
return webseed.RequestSpec{ws.peer.t.requestOffset(r), int64(r.Length)}
|
return webseed.RequestSpec{ws.peer.t.requestOffset(r), int64(r.Length)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) request(r request) bool {
|
func (ws *webseedPeer) request(r request) bool {
|
||||||
webseedRequest := ws.client.NewRequest(ws.intoSpec(r))
|
webseedRequest := ws.client.NewRequest(ws.intoSpec(r))
|
||||||
ws.requests[r] = webseedRequest
|
ws.requests[r] = webseedRequest
|
||||||
go ws.requestResultHandler(r, webseedRequest)
|
go ws.requestResultHandler(r, webseedRequest)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) connectionFlags() string {
|
func (ws *webseedPeer) connectionFlags() string {
|
||||||
return "WS"
|
return "WS"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) drop() {
|
// TODO: This is called when banning peers. Perhaps we want to be able to ban webseeds too.
|
||||||
}
|
func (ws *webseedPeer) drop() {}
|
||||||
|
|
||||||
func (ws *webSeed) updateRequests() {
|
func (ws *webseedPeer) updateRequests() {
|
||||||
ws.peer.doRequestState()
|
ws.peer.doRequestState()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *webSeed) _close() {}
|
func (ws *webseedPeer) _close() {}
|
||||||
|
|
||||||
func (ws *webSeed) requestResultHandler(r request, webseedRequest webseed.Request) {
|
func (ws *webseedPeer) requestResultHandler(r request, webseedRequest webseed.Request) {
|
||||||
result := <-webseedRequest.Result
|
result := <-webseedRequest.Result
|
||||||
ws.peer.t.cl.lock()
|
ws.peer.t.cl.lock()
|
||||||
defer ws.peer.t.cl.unlock()
|
defer ws.peer.t.cl.unlock()
|
Loading…
Reference in New Issue