]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix peer_protocol.Message.RequestSpec for Type Piece
authorMatt Joiner <anacrolix@gmail.com>
Fri, 13 Jul 2018 11:33:21 +0000 (21:33 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 13 Jul 2018 11:33:21 +0000 (21:33 +1000)
peer_protocol/msg.go
peer_protocol/reqspec.go

index 7d3764b714223cafe832cc73b7a8f708694cf968..d7e5f5a77482a7dffab3996da84ca7077f33f717 100644 (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 {
index f73a66df128e04c97950f990a33ad901d6d5db3a..f9989a269573ab98b986812f128c903a8f7aed49 100644 (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)
+}