From: Matt Joiner Date: Wed, 6 Mar 2024 12:04:31 +0000 (+1100) Subject: Some tweaks for v1 and v2 short infohash handling X-Git-Tag: v1.56.0~57 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=bdc91b146f1fc036a591fc959fbb53fe9b00b3e5;p=btrtrc.git Some tweaks for v1 and v2 short infohash handling --- diff --git a/torrent.go b/torrent.go index 52515977..757a180c 100644 --- a/torrent.go +++ b/torrent.go @@ -576,8 +576,10 @@ func (t *Torrent) hashInfoBytes(b []byte, info *metainfo.Info) error { return errors.New("invalid v2 info") } t.infoHashV2.Set(v2Hash) + t.infoHash.SetNone() if info.HasV1() { cl.torrentsByShortHash[v1Hash] = t + t.infoHash.Set(v1Hash) } } } else if t.infoHash.Ok && t.infoHashV2.Ok { @@ -3151,11 +3153,17 @@ func (t *Torrent) canonicalShortInfohash() *infohash.T { } func (t *Torrent) eachShortInfohash(each func(short [20]byte)) { + if t.infoHash.Value == *t.infoHashV2.Value.ToShort() { + // This includes zero values, since they both should not be zero. Plus Option should not + // allow non-zero values for None. + panic("v1 and v2 info hashes should not be the same") + } if t.infoHash.Ok { each(t.infoHash.Value) } if t.infoHashV2.Ok { - each(*t.infoHashV2.Value.ToShort()) + v2Short := *t.infoHashV2.Value.ToShort() + each(v2Short) } }