client.go | 8 ++++++++ cmd/torrentfs/main.go | 1 + config.go | 1 + diff --git a/client.go b/client.go index dc8629699ce8b0ba9a266ba4331a189d225fe5c3..e4e9cecbd1b07f112478274bd086478422a8afcb 100644 --- a/client.go +++ b/client.go @@ -92,6 +92,7 @@ request } type Client struct { + noUpload bool dataDir string halfOpenLimit int peerID [20]byte @@ -201,6 +202,7 @@ cfg = &Config{} } cl = &Client{ + noUpload: cfg.NoUpload, disableTrackers: cfg.DisableTrackers, downloadStrategy: cfg.DownloadStrategy, halfOpenLimit: 100, @@ -704,6 +706,9 @@ me.peerUnchoked(t, c) case pp.Interested: c.PeerInterested = true // TODO: This should be done from a dedicated unchoking routine. + if me.noUpload { + break + } c.Unchoke() case pp.NotInterested: c.PeerInterested = false @@ -711,6 +716,9 @@ c.Choke() case pp.Have: me.peerGotPiece(t, c, int(msg.Index)) case pp.Request: + if me.noUpload { + break + } if c.PeerRequests == nil { c.PeerRequests = make(map[request]struct{}, maxRequests) } diff --git a/cmd/torrentfs/main.go b/cmd/torrentfs/main.go index d542c7172e81f03c94ac39404545d99db1a0a4bc..4a5b75993445f46987904a2a4fdfbacccb3ac5a5 100644 --- a/cmd/torrentfs/main.go +++ b/cmd/torrentfs/main.go @@ -111,6 +111,7 @@ DataDir: downloadDir, DisableTrackers: *disableTrackers, DownloadStrategy: torrent.NewResponsiveDownloadStrategy(*readaheadBytes), ListenAddr: *listenAddr, + NoUpload: true, // Ensure that uploads are responsive. }) http.DefaultServeMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { client.WriteStatus(w) diff --git a/config.go b/config.go index 40e1fd0dbc5bd78a0a61a2dbf0be3cca89ac9d79..6f954bc5d93591258b64f34a082b3005580f47d5 100644 --- a/config.go +++ b/config.go @@ -6,4 +6,5 @@ ListenAddr string DisableTrackers bool DownloadStrategy DownloadStrategy NoDHT bool + NoUpload bool }