]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make NoUpload a client configuration option and use it for torrentfs
authorMatt Joiner <anacrolix@gmail.com>
Sun, 24 Aug 2014 20:00:29 +0000 (06:00 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 24 Aug 2014 20:00:29 +0000 (06:00 +1000)
client.go
cmd/torrentfs/main.go
config.go

index dc8629699ce8b0ba9a266ba4331a189d225fe5c3..e4e9cecbd1b07f112478274bd086478422a8afcb 100644 (file)
--- 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)
                        }
index d542c7172e81f03c94ac39404545d99db1a0a4bc..4a5b75993445f46987904a2a4fdfbacccb3ac5a5 100644 (file)
@@ -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)
index 40e1fd0dbc5bd78a0a61a2dbf0be3cca89ac9d79..6f954bc5d93591258b64f34a082b3005580f47d5 100644 (file)
--- a/config.go
+++ b/config.go
@@ -6,4 +6,5 @@ type Config struct {
        DisableTrackers  bool
        DownloadStrategy DownloadStrategy
        NoDHT            bool
+       NoUpload         bool
 }