From 78ed2c74d062adf5e9e5f8c4bb087d04e4f31a08 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 25 Aug 2014 06:00:29 +1000 Subject: [PATCH] Make NoUpload a client configuration option and use it for torrentfs --- client.go | 8 ++++++++ cmd/torrentfs/main.go | 1 + config.go | 1 + 3 files changed, 10 insertions(+) diff --git a/client.go b/client.go index dc862969..e4e9cecb 100644 --- a/client.go +++ b/client.go @@ -92,6 +92,7 @@ type dataSpec struct { } type Client struct { + noUpload bool dataDir string halfOpenLimit int peerID [20]byte @@ -201,6 +202,7 @@ func NewClient(cfg *Config) (cl *Client, err error) { } cl = &Client{ + noUpload: cfg.NoUpload, disableTrackers: cfg.DisableTrackers, downloadStrategy: cfg.DownloadStrategy, halfOpenLimit: 100, @@ -704,6 +706,9 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error { 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 @@ func (me *Client) connectionLoop(t *torrent, c *connection) error { 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 d542c717..4a5b7599 100644 --- a/cmd/torrentfs/main.go +++ b/cmd/torrentfs/main.go @@ -111,6 +111,7 @@ func main() { 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 40e1fd0d..6f954bc5 100644 --- a/config.go +++ b/config.go @@ -6,4 +6,5 @@ type Config struct { DisableTrackers bool DownloadStrategy DownloadStrategy NoDHT bool + NoUpload bool } -- 2.48.1