client.go | 2 +- cmd/torrent/main.go | 5 +---- dht/dht.go | 6 +++++- download_strategies.go | 12 ++++++------ fs/torrentfs.go | 2 +- torrent.go | 6 ------ diff --git a/client.go b/client.go index b02d9a50f486fb126a98d192e5afa4f146dadacb..a519e0c3cda4cb6b063f7adc9c56046cf6f19a6f 100644 --- a/client.go +++ b/client.go @@ -1271,7 +1271,7 @@ // Write the chunk out. err := t.WriteChunk(int(msg.Index), int64(msg.Begin), msg.Piece) if err != nil { - return err + return fmt.Errorf("error writing chunk: %s", err) } // Record that we have the chunk. diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 294923360d9a3749b02ce0cfac326225bdeb81c1..142b1d339d5e7b6b30b8a23a288374c02dfce0dc 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -26,12 +26,9 @@ disableTrackers = flag.Bool("disableTrackers", false, "disable trackers") seed = flag.Bool("seed", false, "seed after downloading") ) -func init() { +func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) flag.Parse() -} - -func main() { if *httpAddr != "" { util.LoggedHTTPServe(*httpAddr) } diff --git a/dht/dht.go b/dht/dht.go index b77324b05af87d8193c815be60c9d0e321b4b740..bf3b3f5a7c45699cacf733a85a6da6242c0af5e7 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -141,7 +141,11 @@ close(t.done) if t.onResponse != nil { t.onResponse(m) } - t.Response <- m + select { + case t.Response <- m: + default: + panic("blocked handling response") + } close(t.Response) } diff --git a/download_strategies.go b/download_strategies.go index 1de19a5b5682fbe43a13c11b5b60126ee5717a10..6b2886118d504d73e7d1393b0c1ec9da790972ed 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -8,12 +8,12 @@ pp "bitbucket.org/anacrolix/go.torrent/peer_protocol" ) type DownloadStrategy interface { - FillRequests(t *torrent, c *connection) - TorrentStarted(t *torrent) - TorrentStopped(t *torrent) - DeleteRequest(t *torrent, r request) + FillRequests(*torrent, *connection) + TorrentStarted(*torrent) + TorrentStopped(*torrent) + DeleteRequest(*torrent, request) TorrentPrioritize(t *torrent, off, _len int64) - TorrentGotChunk(t *torrent, r request) + TorrentGotChunk(*torrent, request) TorrentGotPiece(t *torrent, piece int) WriteStatus(w io.Writer) AssertNotRequested(*torrent, request) @@ -130,7 +130,7 @@ fmt.Fprintf(w, "Priorities:\n") for t, pp := range me.priorities { fmt.Fprintf(w, "\t%s:", t.Name()) for r := range pp { - fmt.Fprintf(w, "%v ", r) + fmt.Fprintf(w, " %v", r) } fmt.Fprintln(w) } diff --git a/fs/torrentfs.go b/fs/torrentfs.go index e0816befdecbba84f0b2efa397b86bb43b1fdbcf..31891effbf021cd7ba678aa50061a53b0e404f8d 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -55,7 +55,7 @@ } func (fn fileNode) Read(req *fuse.ReadRequest, resp *fuse.ReadResponse, intr fusefs.Intr) fuse.Error { if req.Dir { - panic("hodor") + panic("read on directory") } log.Printf("read request for %s: offset=%d size=%d", fn.fsPath(), req.Offset, req.Size) size := req.Size diff --git a/torrent.go b/torrent.go index 82256f1e4284dbaa8c197de3bb38cdc5db343ff2..4c2a476ebe1ec7f7452653f50a17b4d6ac813fe7 100644 --- a/torrent.go +++ b/torrent.go @@ -258,12 +258,6 @@ for index := range t.Pieces { fmt.Fprintf(w, "%c", t.pieceStatusChar(index)) } fmt.Fprintln(w) - // fmt.Fprintln(w, "Priorities: ") - // if t.Priorities != nil { - // for e := t.Priorities.Front(); e != nil; e = e.Next() { - // fmt.Fprintf(w, "\t%v\n", e.Value) - // } - // } fmt.Fprintf(w, "Pending peers: %d\n", len(t.Peers)) fmt.Fprintf(w, "Active peers: %d\n", len(t.Conns)) for _, c := range t.Conns {