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
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=%q]", s, err)
+ t.logger.Levelf(level, "used torrent source %q [err=%v]", s, err)
}()
}
}
return
}
defer resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ err = fmt.Errorf("unexpected response status code: %v", resp.StatusCode)
+ return
+ }
err = bencode.NewDecoder(resp.Body).Decode(&mi)
return
}