Skip to content

Commit 3bce37f

Browse files
authored
include padding size in torrent stats (#225)
* include padding size in torrent stats * include padding size in RPC response
1 parent 3590a73 commit 3bce37f

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

internal/metainfo/info.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Info struct {
2929
Name string
3030
Hash [20]byte
3131
Length int64
32+
Padding int64
3233
NumPieces uint32
3334
Bytes []byte
3435
Private bool
@@ -122,6 +123,9 @@ func NewInfo(b []byte, utf8 bool, pad bool) (*Info, error) {
122123
if multiFile {
123124
for _, f := range ib.Files {
124125
i.Length += f.Length
126+
if f.isPadding() {
127+
i.Padding += f.Length
128+
}
125129
}
126130
} else {
127131
i.Length = ib.Length

internal/rpctypes/rpctypes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type Stats struct {
114114
}
115115
Bytes struct {
116116
Total int64
117+
Padding int64
117118
Allocated int64
118119
Completed int64
119120
Incomplete int64

torrent/session_rpc_handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func (h *rpcHandler) GetTorrentStats(args *rpctypes.GetTorrentStatsRequest, repl
184184
},
185185
Bytes: struct {
186186
Total int64
187+
Padding int64
187188
Allocated int64
188189
Completed int64
189190
Incomplete int64
@@ -192,6 +193,7 @@ func (h *rpcHandler) GetTorrentStats(args *rpctypes.GetTorrentStatsRequest, repl
192193
Wasted int64
193194
}{
194195
Total: s.Bytes.Total,
196+
Padding: s.Bytes.Padding,
195197
Allocated: s.Bytes.Allocated,
196198
Completed: s.Bytes.Completed,
197199
Incomplete: s.Bytes.Incomplete,

torrent/torrent_stats.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type Stats struct {
3939
Incomplete int64
4040
// The number of total bytes of files in torrent. Total = Completed + Incomplete
4141
Total int64
42+
// The number of total bytes of padding files in torrent. Disk Size = Total - Padding
43+
Padding int64
4244
// Downloaded is the number of bytes downloaded from swarm.
4345
// Because some pieces may be downloaded more than once, this number may be greater than completed bytes.
4446
Downloaded int64
@@ -151,6 +153,7 @@ func (t *torrent) stats() Stats {
151153

152154
if t.info != nil {
153155
s.Bytes.Total = t.info.Length
156+
s.Bytes.Padding = t.info.Padding
154157
s.Bytes.Completed = t.bytesComplete()
155158
s.Bytes.Incomplete = s.Bytes.Total - s.Bytes.Completed
156159

0 commit comments

Comments
 (0)