]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Misc tweaks
authorMatt Joiner <anacrolix@gmail.com>
Thu, 28 Aug 2014 00:05:41 +0000 (10:05 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 28 Aug 2014 00:05:41 +0000 (10:05 +1000)
client.go
cmd/torrent/main.go

index 048cc8a110f95305e4de8b4c6735da475d63689b..0ffd93019099eb4ca8f04aca5fbdd3bc66bd9e90 100644 (file)
--- 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()
index 142b1d339d5e7b6b30b8a23a288374c02dfce0dc..ed98932421d78d76ae4fa34a7e05c679ffe6c470 100644 (file)
@@ -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?!")
        }