]> Sergey Matveev's repositories - btrtrc.git/blobdiff - sources.go
Drop support for go 1.20
[btrtrc.git] / sources.go
index 4fd44673e41b2cc0c5e0ae2122dbef43db17c7e7..ed5ecbfa6c0b492884aaa60e55b222ce9d5ecf7d 100644 (file)
@@ -2,15 +2,19 @@ package torrent
 
 import (
        "context"
+       "errors"
        "fmt"
        "net/http"
 
        "github.com/anacrolix/log"
+
        "github.com/anacrolix/torrent/bencode"
        "github.com/anacrolix/torrent/metainfo"
 )
 
-func (t *Torrent) useSources(sources []string) {
+// Add HTTP endpoints that serve the metainfo. They will be used if the torrent info isn't obtained
+// yet. The Client HTTP client is used.
+func (t *Torrent) UseSources(sources []string) {
        select {
        case <-t.Closed():
                return
@@ -31,7 +35,7 @@ func (t *Torrent) useSources(sources []string) {
                                panic(s)
                        }
                        level := log.Debug
-                       if err != nil {
+                       if err != nil && !errors.Is(err, context.Canceled) {
                                level = log.Warning
                        }
                        t.logger.Levelf(level, "used torrent source %q [err=%v]", s, err)