2
0
mirror of synced 2025-02-23 14:18:13 +00:00

Misc cleanup

This commit is contained in:
Matt Joiner 2020-02-22 19:38:56 +11:00
parent b16118ee18
commit ddc61845ac
4 changed files with 9 additions and 11 deletions

View File

@ -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(

View 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)
}()

View 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

View 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) {