From 76c24e70b51369c8bc9461a58c2f262648a0b49a Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 10 Oct 2016 14:57:34 +1100 Subject: [PATCH] Improve code comments --- client.go | 5 +++++ client_test.go | 2 ++ config.go | 6 ++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 23819096..e0aa472a 100644 --- a/client.go +++ b/client.go @@ -1066,6 +1066,7 @@ func (cl *Client) gotMetadataExtensionMsg(payload []byte, t *Torrent, c *connect } } +// Also handles choking and unchoking of the remote peer. func (cl *Client) upload(t *Torrent, c *connection) { if cl.config.NoUpload { return @@ -1075,10 +1076,14 @@ func (cl *Client) upload(t *Torrent, c *connection) { } seeding := t.seeding() if !seeding && !t.connHasWantedPieces(c) { + // There's no reason to upload to this peer. return } + // Breaking or completing this loop means we don't want to upload to the + // peer anymore, and we choke them. another: for seeding || c.chunksSent < c.UsefulChunksReceived+6 { + // We want to upload to the peer. c.Unchoke() for r := range c.PeerRequests { err := cl.sendChunk(t, c, r) diff --git a/client_test.go b/client_test.go index 835ca1b8..cc1ab594 100644 --- a/client_test.go +++ b/client_test.go @@ -296,6 +296,7 @@ func TestClientTransferSmallCache(t *testing.T) { } func TestClientTransferVarious(t *testing.T) { + // Leecher storage for _, ls := range []storageFactory{ NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{ Wrapper: fileCachePieceFileStorage, @@ -305,6 +306,7 @@ func TestClientTransferVarious(t *testing.T) { }), storage.NewBoltDB, } { + // Seeder storage for _, ss := range []func(string) storage.ClientImpl{ storage.NewFile, storage.NewMMap, diff --git a/config.go b/config.go index dbcdbd13..cb52d3cd 100644 --- a/config.go +++ b/config.go @@ -22,10 +22,12 @@ type Config struct { NoDHT bool `long:"disable-dht"` // Overrides the default DHT configuration. DHTConfig dht.ServerConfig - // Don't ever send chunks to peers. + + // Never send chunks to peers. NoUpload bool `long:"no-upload"` // Upload even after there's nothing in it for us. By default uploading is - // not altruistic. + // not altruistic, we'll upload slightly more than we download from each + // peer. Seed bool `long:"seed"` // User-provided Client peer ID. If not present, one is generated automatically. PeerID string