From 114e8c0f0621cdde84fc666d9384edca3a1a6bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0irhoe=20Biazhkovi=C4=8D?= Date: Sun, 5 Sep 2021 18:16:10 +0300 Subject: [PATCH] Fix invalid time serialization --- frontend/http/writer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontend/http/writer.go b/frontend/http/writer.go index 4adbbda..e528156 100644 --- a/frontend/http/writer.go +++ b/frontend/http/writer.go @@ -3,6 +3,7 @@ package http import ( "github.com/anacrolix/torrent/bencode" "net/http" + "time" "github.com/chihaya/chihaya/bittorrent" "github.com/chihaya/chihaya/pkg/log" @@ -28,6 +29,14 @@ func WriteError(w http.ResponseWriter, err error) error { // WriteAnnounceResponse communicates the results of an Announce to a // BitTorrent client over HTTP. func WriteAnnounceResponse(w http.ResponseWriter, resp *bittorrent.AnnounceResponse) error { + if resp.Interval > 0 { + resp.Interval /= time.Second + } + + if resp.Interval > 0 { + resp.MinInterval /= time.Second + } + bdict := strMap{ "complete": resp.Complete, "incomplete": resp.Incomplete,