+
+// Sets the v2 piece hash, queuing initial piece checks if appropriate.
+func (p *Piece) setV2Hash(v2h [32]byte) {
+ // See Torrent.onSetInfo. We want to trigger an initial check if appropriate, if we didn't yet
+ // have a piece hash (can occur with v2 when we don't start with piece layers).
+ if !p.hashV2.Set(v2h).Ok && p.hash == nil {
+ p.t.queueInitialPieceCheck(p.index)
+ }
+}
+
+// Can't do certain things if we don't know the piece hash.
+func (p *Piece) haveHash() bool {
+ return p.hash != nil || p.hashV2.Ok
+}
+
+func pieceStateAllowsMessageWrites(p *Piece, pc *PeerConn) bool {
+ return (pc.shouldRequestHashes() && !p.haveHash()) || !p.t.ignorePieceForRequests(p.index)
+}