client.go | 5 +++++ client_test.go | 2 ++ config.go | 6 ++++-- diff --git a/client.go b/client.go index 238190967d75b6ced78b8ebf5a2059d70fe37e61..e0aa472ae1bcebbe7c2be2dd3bef165e490a8471 100644 --- a/client.go +++ b/client.go @@ -1066,6 +1066,7 @@ return errors.New("unknown msg_type value") } } +// 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 @@ return } 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 835ca1b89f37b508786344a2654ab800c9e45333..cc1ab59436ee22b2de98ae4db44e74684c66f4a4 100644 --- a/client_test.go +++ b/client_test.go @@ -296,6 +296,7 @@ }) } func TestClientTransferVarious(t *testing.T) { + // Leecher storage for _, ls := range []storageFactory{ NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{ Wrapper: fileCachePieceFileStorage, @@ -305,6 +306,7 @@ Wrapper: fileCachePieceResourceStorage, }), storage.NewBoltDB, } { + // Seeder storage for _, ss := range []func(string) storage.ClientImpl{ storage.NewFile, storage.NewMMap, diff --git a/config.go b/config.go index dbcdbd137feb430785f6b5b5c44f6ea542a4cbdc..cb52d3cdc05f3d9c3946d2185c7912b0914cf0b1 100644 --- a/config.go +++ b/config.go @@ -22,10 +22,12 @@ // Don't create a DHT. 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