From 484cb2c9172dd18966cdf676d8a90ea440b8c7a1 Mon Sep 17 00:00:00 2001 From: Oleg Baranov Date: Sat, 17 Jun 2023 21:17:02 +0400 Subject: [PATCH 1/2] Show uninitialized in cli list too --- cli/main.go | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/cli/main.go b/cli/main.go index 211f0ba..1e633a0 100644 --- a/cli/main.go +++ b/cli/main.go @@ -314,21 +314,27 @@ func list() { } for _, t := range Storage.GetAll() { - if t.Info == nil { - continue - } - mask := t.PiecesMask() - downloadedPieces := 0 - for _, b := range mask { - downloadedPieces += bits.OnesCount8(b) - } - full := t.Info.FileSize - t.Info.HeaderSize - downloaded := uint64(downloadedPieces*int(t.Info.PieceSize)) - t.Info.HeaderSize - if uint64(downloadedPieces*int(t.Info.PieceSize)) < t.Info.HeaderSize { // 0 if header not fully downloaded - downloaded = 0 - } - if downloaded > full { // cut not full last piece - downloaded = full + var strDownloaded, strFull, description = "0 Bytes", "???", "???" + completed := false + if t.Info != nil { + mask := t.PiecesMask() + downloadedPieces := 0 + for _, b := range mask { + downloadedPieces += bits.OnesCount8(b) + } + full := t.Info.FileSize - t.Info.HeaderSize + downloaded := uint64(downloadedPieces*int(t.Info.PieceSize)) - t.Info.HeaderSize + if uint64(downloadedPieces*int(t.Info.PieceSize)) < t.Info.HeaderSize { // 0 if header not fully downloaded + downloaded = 0 + } + if downloaded > full { // cut not full last piece + downloaded = full + } + completed = downloaded == full + + strDownloaded = storage.ToSz(downloaded) + strFull = storage.ToSz(full) + description = t.Info.Description.Value } var dow, upl, num uint64 @@ -338,9 +344,9 @@ func list() { num++ } - table = append(table, []string{hex.EncodeToString(t.BagID), t.Info.Description.Value, - storage.ToSz(downloaded), storage.ToSz(full), fmt.Sprint(num), - storage.ToSpeed(dow), storage.ToSpeed(upl), fmt.Sprint(downloaded == full)}) + table = append(table, []string{hex.EncodeToString(t.BagID), description, + strDownloaded, strFull, fmt.Sprint(num), + storage.ToSpeed(dow), storage.ToSpeed(upl), fmt.Sprint(completed)}) } if len(table) > 1 { From 828252d71964f4f2fc8d6b17ed05b4bcd9abca18 Mon Sep 17 00:00:00 2001 From: Oleg Baranov Date: Sat, 17 Jun 2023 21:28:33 +0400 Subject: [PATCH 2/2] Better new pieces check --- storage/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/server.go b/storage/server.go index 7a5b0c3..429142e 100644 --- a/storage/server.go +++ b/storage/server.go @@ -340,9 +340,9 @@ func (s *Server) handleRLDPQuery(peer *overlay.RLDPWrapper) func(transfer []byte } else if len(lastPieces) > 0 { mask := t.PiecesMask() var newPieces []int32 - for i := 0; i < len(lastPieces); i++ { + for i := 0; i < len(mask); i++ { for j := 0; j < 8; j++ { - if mask[i]&(1< 0 && lastPieces[i]&(1< 0 && (i >= len(lastPieces) || lastPieces[i]&(1<