Abstract out making a cancel message
This commit is contained in:
parent
9e6cdff175
commit
3ed8274384
|
@ -355,12 +355,7 @@ func (cn *connection) fillWriteBuffer(msg func(pp.Message) bool) {
|
|||
for r := range cn.requests {
|
||||
cn.deleteRequest(r)
|
||||
// log.Printf("%p: cancelling request: %v", cn, r)
|
||||
if !msg(pp.Message{
|
||||
Type: pp.Cancel,
|
||||
Index: r.Index,
|
||||
Begin: r.Begin,
|
||||
Length: r.Length,
|
||||
}) {
|
||||
if !msg(makeCancelMessage(r)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -261,3 +261,12 @@ func marshalBitfield(bf []bool) (b []byte) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func MakeCancelMessage(piece, offset, length Integer) Message {
|
||||
return Message{
|
||||
Type: Cancel,
|
||||
Index: piece,
|
||||
Begin: offset,
|
||||
Length: length,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package torrent
|
||||
|
||||
import (
|
||||
pp "github.com/anacrolix/torrent/peer_protocol"
|
||||
)
|
||||
|
||||
func makeCancelMessage(r request) pp.Message {
|
||||
return pp.MakeCancelMessage(r.Index, r.Begin, r.Length)
|
||||
}
|
Loading…
Reference in New Issue