]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Move sendChunk onto connection
authorMatt Joiner <anacrolix@gmail.com>
Fri, 2 Feb 2018 02:26:04 +0000 (13:26 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 2 Feb 2018 02:26:04 +0000 (13:26 +1100)
client.go
connection.go

index ac133047edf5e802190b3d9340ecb3a187b26a42..54a8b6ef7c9e009df2f54824faa5e40b169093ea 100644 (file)
--- a/client.go
+++ b/client.go
@@ -968,31 +968,6 @@ func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connect
        }
 }
 
-func (cl *Client) sendChunk(t *Torrent, c *connection, r request, msg func(pp.Message) bool) (more bool, err error) {
-       // Count the chunk being sent, even if it isn't.
-       b := make([]byte, r.Length)
-       p := t.info.Piece(int(r.Index))
-       n, err := t.readAt(b, p.Offset()+int64(r.Begin))
-       if n != len(b) {
-               if err == nil {
-                       panic("expected error")
-               }
-               return
-       } else if err == io.EOF {
-               err = nil
-       }
-       more = msg(pp.Message{
-               Type:  pp.Piece,
-               Index: r.Index,
-               Begin: r.Begin,
-               Piece: b,
-       })
-       c.chunksSent++
-       uploadChunksPosted.Add(1)
-       c.lastChunkSent = time.Now()
-       return
-}
-
 func (cl *Client) openNewConns(t *Torrent) {
        defer t.updateWantPeersEvent()
        for len(t.peers) != 0 {
index 4147cd769a6878a42849d8743b775448198a47c3..426e202ff245dfda93b20ebb361022022fc5c465 100644 (file)
@@ -1247,3 +1247,28 @@ func (c *connection) postCancel(r request) bool {
        c.Post(makeCancelMessage(r))
        return true
 }
+
+func (c *connection) sendChunk(r request, msg func(pp.Message) bool) (more bool, err error) {
+       // Count the chunk being sent, even if it isn't.
+       b := make([]byte, r.Length)
+       p := c.t.info.Piece(int(r.Index))
+       n, err := c.t.readAt(b, p.Offset()+int64(r.Begin))
+       if n != len(b) {
+               if err == nil {
+                       panic("expected error")
+               }
+               return
+       } else if err == io.EOF {
+               err = nil
+       }
+       more = msg(pp.Message{
+               Type:  pp.Piece,
+               Index: r.Index,
+               Begin: r.Begin,
+               Piece: b,
+       })
+       c.chunksSent++
+       uploadChunksPosted.Add(1)
+       c.lastChunkSent = time.Now()
+       return
+}