]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Tidy up webseed peer naming and unused types
authorMatt Joiner <anacrolix@gmail.com>
Thu, 4 Jun 2020 01:58:18 +0000 (11:58 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 4 Jun 2020 01:58:18 +0000 (11:58 +1000)
torrent.go
webseed-peer.go [moved from web_seed.go with 59% similarity]

index 749a5dae7d48d0238a45e7c5219958c385cb54b4..322ee230f54d5db33e141e40a412b128b8ca8246 100644 (file)
@@ -2033,7 +2033,7 @@ func (t *Torrent) addWebSeed(url string) {
                return
        }
        const maxRequests = 10
-       ws := webSeed{
+       ws := webseedPeer{
                peer: peer{
                        t:                        t,
                        connString:               url,
similarity index 59%
rename from web_seed.go
rename to webseed-peer.go
index c2bb78e1bddb1a0285d59ee8a39ed147fd4b9224..3511635ab9cdd2ed46d2d0aa03b1ecfa4b36bebf 100644 (file)
@@ -2,7 +2,6 @@ package torrent
 
 import (
        "fmt"
-       "net/http"
 
        "github.com/anacrolix/torrent/common"
        "github.com/anacrolix/torrent/metainfo"
@@ -11,76 +10,61 @@ import (
        "github.com/anacrolix/torrent/webseed"
 )
 
-type httpRequestResult 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 {
+type webseedPeer struct {
        client   webseed.Client
        requests map[request]webseed.Request
        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)
 }
 
-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.Info = info
 }
 
-func (ws *webSeed) _postCancel(r request) {
+func (ws *webseedPeer) _postCancel(r request) {
        ws.cancel(r)
 }
 
-func (ws *webSeed) writeInterested(interested bool) bool {
+func (ws *webseedPeer) writeInterested(interested bool) bool {
        return true
 }
 
-func (ws *webSeed) cancel(r request) bool {
+func (ws *webseedPeer) cancel(r request) bool {
        ws.requests[r].Cancel()
        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)}
 }
 
-func (ws *webSeed) request(r request) bool {
+func (ws *webseedPeer) request(r request) bool {
        webseedRequest := ws.client.NewRequest(ws.intoSpec(r))
        ws.requests[r] = webseedRequest
        go ws.requestResultHandler(r, webseedRequest)
        return true
 }
 
-func (ws *webSeed) connectionFlags() string {
+func (ws *webseedPeer) connectionFlags() string {
        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()
 }
 
-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
        ws.peer.t.cl.lock()
        defer ws.peer.t.cl.unlock()