From d5a2bc67f7d6e63fd8d298eb1ea9c447a3084e6b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 28 Aug 2014 10:05:41 +1000 Subject: [PATCH] Misc tweaks --- client.go | 14 +++++++++++--- cmd/torrent/main.go | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 048cc8a1..0ffd9301 100644 --- a/client.go +++ b/client.go @@ -123,7 +123,7 @@ func (me *Client) ListenAddr() net.Addr { } func (cl *Client) WriteStatus(w io.Writer) { - cl.mu.Lock() + cl.mu.LevelLock(1) defer cl.mu.Unlock() if cl.listener != nil { fmt.Fprintf(w, "Listening on %s\n", cl.listener.Addr()) @@ -274,6 +274,8 @@ func (me *Client) Stop() { func (cl *Client) acceptConnections() { for { + // We accept all connections immediately, because we don't what + // torrent they're for. conn, err := cl.listener.Accept() select { case <-cl.quit: @@ -287,7 +289,6 @@ func (cl *Client) acceptConnections() { log.Print(err) return } - // log.Printf("accepted connection from %s", conn.RemoteAddr()) go func() { if err := cl.runConnection(conn, nil, peerSourceIncoming); err != nil { log.Print(err) @@ -539,7 +540,14 @@ func (me *Client) runConnection(sock net.Conn, torrent *torrent, discovery peerS }, "v": "go.torrent dev 20140825", // Just the date // No upload queue is implemented yet. - "reqq": 1, + "reqq": func() int { + if me.noUpload { + // No need to look strange if it costs us nothing. + return 250 + } else { + return 1 + } + }(), } if torrent.metadataSizeKnown() { d["metadata_size"] = torrent.metadataSize() diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 142b1d33..ed989324 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -71,7 +71,7 @@ func main() { } util.CopyExact(&ih, metaInfo.Info.Hash) } - client.PrioritizeDataRegion(ih, 0, 999999999) + // client.PrioritizeDataRegion(ih, 0, 999999999) err := client.AddPeers(ih, func() []torrent.Peer { if *testPeer == "" { return nil @@ -93,7 +93,7 @@ func main() { select {} } if client.WaitAll() { - log.Print("all torrents completed!") + log.Print("downloaded ALL the torrents") } else { log.Fatal("y u no complete torrents?!") }