]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Misc cleanup
authorMatt Joiner <anacrolix@gmail.com>
Sat, 22 Feb 2020 08:38:56 +0000 (19:38 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 22 Feb 2020 08:38:56 +0000 (19:38 +1100)
client.go
peerconn.go
test/transfer_test.go
torrent.go

index 2ce57d0fb82207f2fdc5f560fa21249fd1b495ec..0e83374ecbec3b592ca79402046549cb8cfd3585 100644 (file)
--- 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(
index 3141348eb777bb04e210f7db282165b24472c3de..9ff1a693c231d4a6ecef0a6f0ebe7889b2dc420a 100644 (file)
@@ -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)
        }()
 
index 7d7e51bbcd482ed5c7c1ca40624a7f64c453bcca..32b9ed156c62388e0c7c6dc9c35940002ddd7d2f 100644 (file)
@@ -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
index 2c18b73df67e8c43c091058c76edbcdce8192ab2..74688c0b2614b947206bacc5d309e2eabcf46587 100644 (file)
@@ -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) {