client.go | 25 ------------------------- connection.go | 25 +++++++++++++++++++++++++ diff --git a/client.go b/client.go index ac133047edf5e802190b3d9340ecb3a187b26a42..54a8b6ef7c9e009df2f54824faa5e40b169093ea 100644 --- a/client.go +++ b/client.go @@ -968,31 +968,6 @@ return errors.New("unknown msg_type value") } } -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 { diff --git a/connection.go b/connection.go index 4147cd769a6878a42849d8743b775448198a47c3..426e202ff245dfda93b20ebb361022022fc5c465 100644 --- a/connection.go +++ b/connection.go @@ -1247,3 +1247,28 @@ } 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 +}