]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Misc minor improvements
authorMatt Joiner <anacrolix@gmail.com>
Wed, 21 May 2014 07:42:06 +0000 (17:42 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 21 May 2014 07:42:06 +0000 (17:42 +1000)
client.go
connection.go
torrent.go

index 2ae3b8321858160b9e7a460d119d5d5f4b698bb7..4902a1962457177fefef38bbd650e3dbf13344fd 100644 (file)
--- a/client.go
+++ b/client.go
@@ -161,7 +161,8 @@ func (cl *Client) TorrentReadAt(ih InfoHash, off int64, p []byte) (n int, err er
        return t.Data.ReadAt(p, off)
 }
 
-// Starts the client. Defaults are applied. The client will begin accepting connections and tracking.
+// Starts the client. Defaults are applied. The client will begin accepting
+// connections and tracking.
 func (c *Client) Start() {
        c.event.L = &c.mu
        c.torrents = make(map[InfoHash]*torrent)
@@ -406,10 +407,7 @@ func (me *Client) connectionLoop(torrent *torrent, conn *connection) error {
                        if conn.PeerRequests == nil {
                                conn.PeerRequests = make(map[request]struct{}, maxRequests)
                        }
-                       request := request{
-                               Index:     msg.Index,
-                               chunkSpec: chunkSpec{msg.Begin, msg.Length},
-                       }
+                       request := newRequest(msg.Index, msg.Begin, msg.Length)
                        conn.PeerRequests[request] = struct{}{}
                        // TODO: Requests should be satisfied from a dedicated upload routine.
                        p := make([]byte, msg.Length)
@@ -455,7 +453,7 @@ func (me *Client) connectionLoop(torrent *torrent, conn *connection) error {
                        delete(conn.Requests, request_)
                        err = me.downloadedChunk(torrent, msg)
                default:
-                       log.Printf("received unknown message type: %#v", msg.Type)
+                       err = fmt.Errorf("received unknown message type: %#v", msg.Type)
                }
                if err != nil {
                        return err
@@ -483,7 +481,7 @@ func (me *Client) dropConnection(torrent *torrent, conn *connection) {
 func (me *Client) addConnection(t *torrent, c *connection) bool {
        for _, c0 := range t.Conns {
                if c.PeerId == c0.PeerId {
-                       log.Printf("%s and %s have the same ID: %s", c.Socket.RemoteAddr(), c0.Socket.RemoteAddr(), c.PeerId)
+                       // Already connected to a client with that ID.
                        return false
                }
        }
index fada33f49448e6f98c01c76fd375df007d93f04a..5c153e19b810ff0ea9e679401480c827a151f1d9 100644 (file)
@@ -66,7 +66,7 @@ func (c *connection) Request(chunk request) bool {
        if len(c.Requests) >= maxRequests {
                return false
        }
-       if !c.PeerPieces[chunk.Index] {
+       if !c.PeerHasPiece(chunk.Index) {
                return true
        }
        c.SetInterested(true)
index 08bce0b8bda99c68e2dc28bb161db806b6e59831..4f94b89bc0bb842e78c2ba907f0eeba09cab2cf8 100644 (file)
@@ -75,7 +75,7 @@ func (t *torrent) piecesByPendingBytes() (indices []peer_protocol.Integer) {
                slice.Pending = append(slice.Pending, t.PieceNumPendingBytes(peer_protocol.Integer(i)))
                slice.Indices = append(slice.Indices, peer_protocol.Integer(i))
        }
-       sort.Sort(sort.Reverse(slice))
+       sort.Sort(slice)
        return slice.Indices
 }