Fix peer_protocol.Message.RequestSpec for Type Piece

This commit is contained in:
Matt Joiner 2018-07-13 21:33:21 +10:00
parent c001e6e008
commit cc6441a791
2 changed files with 18 additions and 2 deletions

View File

@ -26,8 +26,18 @@ func MakeCancelMessage(piece, offset, length Integer) Message {
}
}
func (msg Message) RequestSpec() RequestSpec {
return RequestSpec{msg.Index, msg.Begin, msg.Length}
func (msg Message) RequestSpec() (ret RequestSpec) {
return RequestSpec{
msg.Index,
msg.Begin,
func() Integer {
if msg.Type == Piece {
return Integer(len(msg.Piece))
} else {
return msg.Length
}
}(),
}
}
func (msg Message) MustMarshalBinary() []byte {

View File

@ -1,5 +1,11 @@
package peer_protocol
import "fmt"
type RequestSpec struct {
Index, Begin, Length Integer
}
func (me RequestSpec) String() string {
return fmt.Sprintf("{%d %d %d}", me.Index, me.Begin, me.Length)
}