Skip to content

Commit

Permalink
turn on Responsive
Browse files Browse the repository at this point in the history
switch to default ReadaheadFunc
  • Loading branch information
vintikzzz committed Nov 10, 2024
1 parent 5689c7b commit d53c5f0
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions server/services/web_seeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import (

"github.com/anacrolix/torrent/bencode"

"github.com/anacrolix/torrent"
log "github.com/sirupsen/logrus"
)

var sha1R = regexp.MustCompile("^[0-9a-f]{5,40}$")

const (
SourceTorrentPath = "source.torrent"
MaxReadahead = 250 * 1024 * 1024
MinReadahead = 1024 * 1024
//MaxReadahead = 250 * 1024 * 1024
//MinReadahead = 1024 * 1024
)

type WebSeeder struct {
Expand Down Expand Up @@ -158,21 +157,21 @@ func (s *WebSeeder) serveFile(w http.ResponseWriter, r *http.Request, h string,
}
var reader io.ReadSeeker
torReader := f.NewReader()
// torReader.SetResponsive()
torReader.SetReadaheadFunc(func(r torrent.ReadaheadContext) int64 {
p := f.Length() / 100
if p < MinReadahead {
p = MinReadahead
}
ra := (r.CurrentPos - r.ContiguousReadStartPos) * 2
if ra < p {
return p
}
if ra > MaxReadahead {
return MaxReadahead
}
return ra
})
torReader.SetResponsive()
//torReader.SetReadaheadFunc(func(r torrent.ReadaheadContext) int64 {
// p := f.Length() / 100
// if p < MinReadahead {
// p = MinReadahead
// }
// ra := (r.CurrentPos - r.ContiguousReadStartPos) * 2
// if ra < p {
// return p
// }
// if ra > MaxReadahead {
// return MaxReadahead
// }
// return ra
//})
reader = torReader
w.Header().Set("Last-Modified", time.Unix(0, 0).Format(http.TimeFormat))
w.Header().Set("Etag", fmt.Sprintf("\"%x\"", sha1.Sum([]byte(t.InfoHash().String()+p))))
Expand Down

0 comments on commit d53c5f0

Please sign in to comment.