Skip to content

Commit

Permalink
Some tweaks for v1 and v2 short infohash handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Mar 6, 2024
1 parent be63f20 commit bdc91b1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit bdc91b1

Please sign in to comment.