// 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.
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)
}
if t.onResponse != nil {
t.onResponse(m)
}
- t.Response <- m
+ select {
+ case t.Response <- m:
+ default:
+ panic("blocked handling response")
+ }
close(t.Response)
}
)
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)
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)
}
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
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 {