From: Matt Joiner Date: Sat, 22 Feb 2020 08:38:56 +0000 (+1100) Subject: Misc cleanup X-Git-Tag: v1.15.0~16 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ddc61845acb725707781d1acd756a3a60c60c8d0;p=btrtrc.git Misc cleanup --- diff --git a/client.go b/client.go index 2ce57d0f..0e83374e 100644 --- a/client.go +++ b/client.go @@ -821,7 +821,7 @@ func (cl *Client) runReceivedConn(c *PeerConn) { t, err := cl.receiveHandshakes(c) if err != nil { log.Fmsg( - "error receiving handshakes: %s", err, + "error receiving handshakes on %v: %s", c, err, ).AddValue( debugLogValue, ).Add( diff --git a/peerconn.go b/peerconn.go index 3141348e..9ff1a693 100644 --- a/peerconn.go +++ b/peerconn.go @@ -522,8 +522,7 @@ func (cn *PeerConn) fillWriteBuffer(msg func(pp.Message) bool) { } } } - } - if len(cn.requests) <= cn.requestsLowWater { + } else if len(cn.requests) <= cn.requestsLowWater { filledBuffer := false cn.iterPendingPieces(func(pieceIndex pieceIndex) bool { cn.iterPendingRequests(pieceIndex, func(r request) bool { @@ -1236,12 +1235,11 @@ func (c *PeerConn) receiveChunk(msg *pp.Message) error { defer cl.lock() concurrentChunkWrites.Add(1) defer concurrentChunkWrites.Add(-1) - // Write the chunk out. Note that the upper bound on chunk writing - // concurrency will be the number of connections. We write inline with - // receiving the chunk (with this lock dance), because we want to - // handle errors synchronously and I haven't thought of a nice way to - // defer any concurrency to the storage and have that notify the - // client of errors. TODO: Do that instead. + // Write the chunk out. Note that the upper bound on chunk writing concurrency will be the + // number of connections. We write inline with receiving the chunk (with this lock dance), + // because we want to handle errors synchronously and I haven't thought of a nice way to + // defer any concurrency to the storage and have that notify the client of errors. TODO: Do + // that instead. return t.writeChunk(int(msg.Index), int64(msg.Begin), msg.Piece) }() diff --git a/test/transfer_test.go b/test/transfer_test.go index 7d7e51bb..32b9ed15 100644 --- a/test/transfer_test.go +++ b/test/transfer_test.go @@ -38,7 +38,7 @@ func assertReadAllGreeting(t *testing.T, r io.ReadSeeker) { assert.EqualValues(t, 0, pos) _greeting, err := ioutil.ReadAll(r) assert.NoError(t, err) - assert.EqualValues(t, testutil.GreetingFileContents, _greeting) + assert.EqualValues(t, testutil.GreetingFileContents, string(_greeting)) } // Creates a seeder and a leecher, and ensures the data transfers when a read diff --git a/torrent.go b/torrent.go index 2c18b73d..74688c0b 100644 --- a/torrent.go +++ b/torrent.go @@ -726,7 +726,7 @@ func (t *Torrent) writeChunk(piece int, begin int64, data []byte) (err error) { if err == nil && n != len(data) { err = io.ErrShortWrite } - return + return err } func (t *Torrent) bitfield() (bf []bool) {