From 2d9c22ae1e8482d5464b8b32b8548e06f755bed7 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 25 Aug 2014 22:14:10 +1000 Subject: [PATCH] Misc trivial improvements --- client.go | 2 +- cmd/torrent/main.go | 5 +---- dht/dht.go | 6 +++++- download_strategies.go | 12 ++++++------ fs/torrentfs.go | 2 +- torrent.go | 6 ------ 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/client.go b/client.go index b02d9a50..a519e0c3 100644 --- a/client.go +++ b/client.go @@ -1271,7 +1271,7 @@ func (me *Client) downloadedChunk(t *torrent, c *connection, msg *pp.Message) er // 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 29492336..142b1d33 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -26,12 +26,9 @@ var ( 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 b77324b0..bf3b3f5a 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -141,7 +141,11 @@ func (t *transaction) handleResponse(m Msg) { 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 1de19a5b..6b288611 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -8,12 +8,12 @@ import ( ) 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 @@ func (me *responsiveDownloadStrategy) WriteStatus(w io.Writer) { 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 e0816bef..31891eff 100644 --- a/fs/torrentfs.go +++ b/fs/torrentfs.go @@ -55,7 +55,7 @@ func (n *node) fsPath() string { 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 82256f1e..4c2a476e 100644 --- a/torrent.go +++ b/torrent.go @@ -258,12 +258,6 @@ func (t *torrent) WriteStatus(w io.Writer) { 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 { -- 2.48.1