]> Sergey Matveev's repositories - btrtrc.git/blobdiff - tracker/tracker.go
Rework HTTP announce timeouts
[btrtrc.git] / tracker / tracker.go
index 93f11ccd8d589ad14fee5e698bed3d4df938fd08..5497037f5acb07d79302b867269875c419fa1775 100644 (file)
@@ -5,6 +5,7 @@ import (
        "errors"
        "net/http"
        "net/url"
+       "time"
 
        "github.com/anacrolix/dht/v2/krpc"
 )
@@ -70,6 +71,13 @@ func (me Announce) Do() (res AnnounceResponse, err error) {
        if err != nil {
                return
        }
+       if me.Context == nil {
+               // This is just to maintain the old behaviour that should be a timeout of 15s. Users can
+               // override it by providing their own Context.
+               ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+               defer cancel()
+               me.Context = ctx
+       }
        switch _url.Scheme {
        case "http", "https":
                return announceHTTP(me, _url)