Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: go 1.22 #990

Closed
wants to merge 526 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
526 commits
Select commit Hold shift + click to select a range
3e8f7cf
buf pool printers
mh0lt Jun 27, 2024
1360803
buf pool printers + test
mh0lt Jun 27, 2024
6b7167f
buf pool printers
mh0lt Jun 27, 2024
1ebae2b
fix alloc size
mh0lt Jun 27, 2024
26127df
remove alloc printers
mh0lt Jun 27, 2024
76d629f
round pool alloc to bytes.MinRead
mh0lt Jun 27, 2024
3059bba
make pool 5GB
mh0lt Jun 27, 2024
3b51e74
Merge pull request #13 from erigontech/increase_webseed_parallelization
mh0lt Jun 28, 2024
b65e41d
group trigger events on download
mh0lt Jun 28, 2024
25df4d5
fix lock
mh0lt Jun 28, 2024
975668d
add smartban buf pool
mh0lt Jun 28, 2024
2f78e07
remove unuses semaphore
mh0lt Jun 28, 2024
550d67e
consolidated buffer pools
mh0lt Jun 28, 2024
3ed0807
fix close check
mh0lt Jun 28, 2024
de13c76
clear dirtier hashes
mh0lt Jun 29, 2024
a27aa6c
Merge pull request #14 from erigontech/increase_webseed_parallelization
mh0lt Jun 29, 2024
aeeda28
completion printer
mh0lt Jun 29, 2024
20d0c9f
completion printer
mh0lt Jun 29, 2024
7d2ab15
completion printer
mh0lt Jun 29, 2024
fb45ebd
comment completion printer
mh0lt Jun 29, 2024
192e243
finish comment
mh0lt Jun 29, 2024
232bff0
add nil support
mh0lt Jun 29, 2024
e07d091
make cancel & _cancel atomic
mh0lt Jun 29, 2024
b79c600
piece printer
mh0lt Jun 29, 2024
d3145ed
print hash printer
mh0lt Jun 29, 2024
6617b64
print hash
mh0lt Jun 29, 2024
1167f89
print hash
mh0lt Jun 29, 2024
9788073
print hash
mh0lt Jun 29, 2024
9f49b65
remove printers
mh0lt Jun 29, 2024
96a3f11
close on 5x bans
mh0lt Jun 29, 2024
b1c7ad9
ignore banned peers
mh0lt Jun 29, 2024
3e3510d
don't close on ban
mh0lt Jun 29, 2024
2a85b2b
don't close on ban
mh0lt Jun 29, 2024
be406f6
piece printer
mh0lt Jun 29, 2024
35a7b5e
activate flush
mh0lt Jun 30, 2024
78025bc
print mark complete
mh0lt Jun 30, 2024
a2e6d44
dirty printer
mh0lt Jun 30, 2024
d05ecb8
pass dirty index to map writer
mh0lt Jun 30, 2024
ca3aec3
remove printers
mh0lt Jun 30, 2024
646bba5
write printer
mh0lt Jun 30, 2024
74106fc
mk printer
mh0lt Jun 30, 2024
8237e74
remove printers
mh0lt Jun 30, 2024
252ba57
remove printers
mh0lt Jun 30, 2024
3bf6a66
remove printers
mh0lt Jun 30, 2024
39a73dc
make delete request and remoteRejectedRequest handling consistent
mh0lt Jul 1, 2024
f33d9ea
mu fot torrent
mh0lt Jul 1, 2024
0ecd197
mu peer
mh0lt Jul 1, 2024
f417570
hold torrent lock (not r)
mh0lt Jul 1, 2024
bb2e4de
independent lock
mh0lt Jul 1, 2024
23dc0e7
independent lock
mh0lt Jul 1, 2024
d48f057
no mu peer & torrent
mh0lt Jul 1, 2024
4912dfb
move comment
mh0lt Jul 1, 2024
2c6c007
Merge pull request #15 from erigontech/increase_webseed_parallelization
mh0lt Jul 1, 2024
67deab1
make flush time longer
mh0lt Jul 1, 2024
0812b77
remove deadlock checker
mh0lt Jul 1, 2024
6c860df
Merge pull request #16 from erigontech/increase_webseed_parallelization
mh0lt Jul 1, 2024
d891cd7
make maybeUpdateActualRequestState atomic
mh0lt Jul 2, 2024
5ed267c
restore mu
mh0lt Jul 2, 2024
a72cdff
update mods
mh0lt Jul 2, 2024
c2e7a4d
remove lock timeout
mh0lt Jul 2, 2024
2d039bd
update locks
mh0lt Jul 2, 2024
fd6a4e9
don't lock peer
mh0lt Jul 2, 2024
a7b5d9b
maybeUpdateActualRequestState needs lock control
mh0lt Jul 2, 2024
79ac9e5
give updateRequests peer lock control
mh0lt Jul 2, 2024
08021a8
remove recursive lock
mh0lt Jul 2, 2024
f3a099b
add lockto
mh0lt Jul 2, 2024
4b15ef4
added con with all printer
mh0lt Jul 3, 2024
f2ec7ac
fixed races
mh0lt Jul 3, 2024
e4fb54c
cons printer
mh0lt Jul 3, 2024
48fa1c9
conn printers
mh0lt Jul 3, 2024
87ca31f
conn printers
mh0lt Jul 3, 2024
454a6b3
conn printers
mh0lt Jul 3, 2024
1f0671a
conn printers
mh0lt Jul 3, 2024
fa12964
move close to deleteConn
mh0lt Jul 3, 2024
a69ba06
conn printers
mh0lt Jul 3, 2024
c3f9bb9
remove cons printers
mh0lt Jul 3, 2024
3164f6f
removed deadlock checks
mh0lt Jul 3, 2024
8d3754e
Merge pull request #17 from erigontech/increase_webseed_parallelization
mh0lt Jul 3, 2024
20763ad
make onPiecePendingTriggers use write lock
mh0lt Jul 4, 2024
785635d
close printer
mh0lt Jul 4, 2024
5d07d5a
don't lock torrent for peers
mh0lt Jul 4, 2024
70d98e1
don't lock torrent for peers
mh0lt Jul 4, 2024
6ba5ca9
don't lock torrent for peers
mh0lt Jul 4, 2024
44ffeb8
re-adjust cancel to work for close
mh0lt Jul 4, 2024
58e379f
re-adjust cancel to work for close
mh0lt Jul 4, 2024
0c898ab
re-adjust cancel to work for close
mh0lt Jul 4, 2024
ad33c1b
re-adjust cancel to work for close
mh0lt Jul 4, 2024
5bc4a90
fix peer refs
mh0lt Jul 4, 2024
76e9891
remoce printers
mh0lt Jul 4, 2024
d04dc67
close hash results
mh0lt Jul 4, 2024
5f75929
torent close printer
mh0lt Jul 4, 2024
5c4102d
client close printer
mh0lt Jul 4, 2024
ce297a6
client close printer
mh0lt Jul 4, 2024
61397ac
no wait if closed
mh0lt Jul 4, 2024
9439c88
storafe deadlock check
mh0lt Jul 4, 2024
b88e8fd
wait for torrent close before storage close
mh0lt Jul 4, 2024
c14b547
storage close printer
mh0lt Jul 4, 2024
a49ec92
storage close printer
mh0lt Jul 4, 2024
1cd605e
storage close printer
mh0lt Jul 4, 2024
ff3116a
storage close printer
mh0lt Jul 4, 2024
70b89f7
storage close printer
mh0lt Jul 4, 2024
481467d
flush lock
mh0lt Jul 4, 2024
3730d86
remove close printers
mh0lt Jul 4, 2024
b2c914e
remove deadlock check
mh0lt Jul 5, 2024
c71b72d
Merge pull request #18 from erigontech/increase_webseed_parallelization
mh0lt Jul 5, 2024
6d79ffb
fix wantPeersEvent race
mh0lt Jul 5, 2024
02524cf
don't use client lock for config
mh0lt Jul 6, 2024
39247e7
Merge pull request #19 from erigontech/increase_webseed_parallelization
mh0lt Jul 6, 2024
0bd7f5b
add piece buf printers
mh0lt Jul 8, 2024
fd900d4
add piece buf printers
mh0lt Jul 8, 2024
b61c24c
add piece buf printers
mh0lt Jul 8, 2024
7215ba7
restore close on ban
mh0lt Jul 8, 2024
d89315d
add printer status
mh0lt Jul 8, 2024
a5bd063
check closed
mh0lt Jul 8, 2024
6096c4a
add printer status
mh0lt Jul 8, 2024
a37cc0f
add lock detection
mh0lt Jul 9, 2024
b654ccb
fix torrent deadlock
mh0lt Jul 9, 2024
34abe35
add lock to request state data
mh0lt Jul 9, 2024
41dd070
add printer status
mh0lt Jul 9, 2024
d596a63
add peer deadlock checker
mh0lt Jul 10, 2024
2a7f20d
remove lock detector
mh0lt Jul 10, 2024
ad9219c
re-introduce client lock
mh0lt Jul 10, 2024
99d65bf
export status strings
mh0lt Jul 10, 2024
1453b96
track peer lock not client
mh0lt Jul 10, 2024
10f1ce2
fix flags
mh0lt Jul 10, 2024
866f4dc
fix fastenabled lock param
mh0lt Jul 10, 2024
6b88478
remove printer
mh0lt Jul 10, 2024
1b56deb
remove printer
mh0lt Jul 10, 2024
4b6e144
increase ban count to 16
mh0lt Jul 11, 2024
7de8739
remove deadlock tests
mh0lt Jul 11, 2024
9e5f962
Merge pull request #20 from erigontech/increase_webseed_parallelization
mh0lt Jul 11, 2024
74f6e52
fix useful rlock
mh0lt Jul 12, 2024
a6ac7dc
don't add conns when torrent is complete
mh0lt Jul 14, 2024
854a6de
fix races
mh0lt Jul 14, 2024
5dd79fd
fix races
mh0lt Jul 15, 2024
5eae18f
fix races
mh0lt Jul 15, 2024
ee2c60a
fix races
mh0lt Jul 15, 2024
2775322
Merge pull request #21 from erigontech/increase_webseed_parallelization
mh0lt Jul 15, 2024
030accb
add missing defer
mh0lt Jul 15, 2024
c323168
Merge pull request #22 from erigontech/increase_webseed_parallelization
mh0lt Jul 15, 2024
79dd030
fix missing defer
mh0lt Jul 16, 2024
32523f6
Merge pull request #23 from erigontech/increase_webseed_parallelization
mh0lt Jul 16, 2024
636e8d6
print piece
mh0lt Jul 17, 2024
fd84feb
add isnew + await flush
mh0lt Jul 17, 2024
289169d
dl printer
mh0lt Jul 18, 2024
9131d8b
localize counter
mh0lt Jul 18, 2024
5066724
print completions
mh0lt Jul 18, 2024
8b2813f
manage downloading status in download all
mh0lt Jul 18, 2024
e43b93e
remove ok printer
mh0lt Jul 18, 2024
e4ac702
print completions
mh0lt Jul 18, 2024
92c0e1e
add hashers to download all
mh0lt Jul 18, 2024
9c12e6b
remove printers
mh0lt Jul 18, 2024
6b5c3aa
remove unwanted var
mh0lt Jul 18, 2024
7c10138
print hash rate
mh0lt Jul 18, 2024
8d57784
print hash rate
mh0lt Jul 18, 2024
3185ae2
print hash rate
mh0lt Jul 18, 2024
e3be32d
print hash rate
mh0lt Jul 18, 2024
b2351e5
print hash rate
mh0lt Jul 18, 2024
0186542
print hash rate
mh0lt Jul 18, 2024
643041e
print hash rate
mh0lt Jul 18, 2024
74f2dc8
print hash rate
mh0lt Jul 18, 2024
d08bcd0
print hash rate
mh0lt Jul 18, 2024
d2569e7
print hash rate
mh0lt Jul 18, 2024
2e470b5
remove print hash rate
mh0lt Jul 18, 2024
1079022
Merge pull request #25 from erigontech/increase_webseed_parallelization
mh0lt Jul 18, 2024
89e3cd7
added hash/complete counts
mh0lt Jul 20, 2024
7607773
added hash/complete counts
mh0lt Jul 20, 2024
b9cfe10
ds printer
mh0lt Jul 21, 2024
116eca1
ds printer
mh0lt Jul 21, 2024
77cfed7
ds printer
mh0lt Jul 21, 2024
aa4502c
ds printer
mh0lt Jul 21, 2024
4838a83
remove ds printer
mh0lt Jul 21, 2024
db0b955
added bytes flushed
mh0lt Jul 21, 2024
e00524b
update const per host
mh0lt Jul 22, 2024
9f65af9
don't request for completed torrent
mh0lt Jul 22, 2024
9f8d405
zero desired requests on close
mh0lt Jul 22, 2024
c802be4
update cons per host
mh0lt Jul 22, 2024
e5388dd
ban after 5 drops
mh0lt Jul 22, 2024
6eb9a83
remove max conns
mh0lt Jul 22, 2024
5a41be4
remove max conns
mh0lt Jul 22, 2024
5278e37
remove max conns
mh0lt Jul 22, 2024
fcadd3a
remove max conns
mh0lt Jul 23, 2024
31175cf
remove max conns
mh0lt Jul 23, 2024
ee8ee63
Merge pull request #26 from erigontech/increase_webseed_parallelization
mh0lt Jul 24, 2024
57210f4
use local var to avoid race on close
mh0lt Aug 3, 2024
08b20c6
use local var to avoid race on close
mh0lt Aug 3, 2024
523b853
locally cache ip lookup
mh0lt Aug 3, 2024
ba9b2b3
locally cache ip lookup
mh0lt Aug 3, 2024
b09452a
make ip lookup cache global
mh0lt Aug 3, 2024
10f8862
use local var to avoid race on close
mh0lt Aug 3, 2024
092574b
use local var to avoid race on close
mh0lt Aug 3, 2024
6164078
dns lookup cache error handling
mh0lt Aug 4, 2024
243ff4c
use local var to avoid race on close
mh0lt Aug 4, 2024
04af86a
locally cache ip lookup
mh0lt Aug 4, 2024
e44eb85
close printers
mh0lt Aug 4, 2024
76cde54
close printers
mh0lt Aug 4, 2024
eeefd76
parallel torrent close
mh0lt Aug 4, 2024
0cd7405
process close done
mh0lt Aug 4, 2024
06a718a
call flushcb on close
mh0lt Aug 5, 2024
c2735ad
don't initatiate time if closed
mh0lt Aug 5, 2024
43e17e4
move oncluse until after shutdown
mh0lt Aug 6, 2024
40a6dda
close storage after other components
mh0lt Aug 7, 2024
c108cf5
add close printer
mh0lt Aug 7, 2024
f2f5321
add close printer
mh0lt Aug 7, 2024
3a56aa7
add close printer
mh0lt Aug 7, 2024
a984272
adjust close wait group usage
mh0lt Aug 7, 2024
9d02d53
remove printers
mh0lt Aug 8, 2024
f458456
add client lock for deletePieceRequestOrder
mh0lt Aug 8, 2024
a1b13ba
Merge pull request #27 from erigontech/increase_webseed_parallelization
mh0lt Aug 8, 2024
aa3478a
fixed completed bytes count
dvovk Aug 22, 2024
9848cb5
Merge pull request #28 from erigontech/piececomplete
dvovk Aug 22, 2024
1933e04
check info nil
mh0lt Aug 27, 2024
e7832e6
Merge pull request #29 from erigontech/fix-info-nil
mh0lt Aug 27, 2024
97fd664
moved event cond from client to torrent
mh0lt Sep 4, 2024
f2da1b2
Merge pull request #30 from erigontech/fix-verify-deadlock
dvovk Sep 4, 2024
80799f9
fixed diacover for new peers connection
dvovk Oct 5, 2024
3ccd90c
Merge pull request #31 from erigontech/fixpeerconn
dvovk Oct 6, 2024
b104e3b
Revert "fixed discover for new peers connection"
dvovk Oct 12, 2024
3672b16
Merge pull request #32 from erigontech/revert-31-fixpeerconn
dvovk Oct 12, 2024
697e0d0
enable peers
dvovk Oct 12, 2024
cafc8fc
fix
dvovk Oct 13, 2024
757f4d7
concurent write fix
dvovk Oct 15, 2024
073d807
lock
dvovk Oct 15, 2024
37d2d5c
fix
dvovk Oct 16, 2024
6e40a01
fix
dvovk Oct 16, 2024
ff0e9b2
Merge pull request #33 from erigontech/peers_enable
dvovk Oct 16, 2024
1ef31a0
Revert "Peers enable"
dvovk Oct 16, 2024
3b27feb
Merge pull request #34 from erigontech/revert-33-peers_enable
dvovk Oct 16, 2024
a25f93f
fix
dvovk Oct 17, 2024
687a710
Merge pull request #35 from erigontech/tps
dvovk Oct 17, 2024
bad3277
added peer bytes uploaded and rate
mh0lt Oct 22, 2024
14518bc
Merge pull request #36 from erigontech/upload_stats
mh0lt Oct 22, 2024
97e8ac6
fixed function naming
mh0lt Oct 22, 2024
688e150
Merge branch 'release/v1.54' of https://github.com/erigontech/torrent…
mh0lt Oct 22, 2024
7c43720
save
dvovk Nov 30, 2024
d1c0a59
save
dvovk Dec 3, 2024
54a75e7
move delete active request before cancel flag remove
mh0lt Dec 3, 2024
e4e6b46
defer delete for non errors
mh0lt Dec 3, 2024
be15f28
don't reprocess requests
mh0lt Dec 3, 2024
07b0075
add cancel handling for already processed request
mh0lt Dec 3, 2024
a4d8f94
add func
mh0lt Dec 3, 2024
3bee769
save progress
dvovk Dec 5, 2024
0466376
save
dvovk Dec 5, 2024
87998b5
save
dvovk Dec 5, 2024
87d4028
save
dvovk Dec 5, 2024
fd58b86
save
dvovk Dec 5, 2024
de18ee1
Merge pull request #38 from erigontech/mtr_ws
mh0lt Dec 5, 2024
2c43b24
Revert "Enabled peers connection"
dvovk Dec 5, 2024
105924a
Merge pull request #39 from erigontech/revert-35-tps
dvovk Dec 5, 2024
e3a7bd4
save
AskAlexSharov Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make cancel & _cancel atomic
mh0lt committed Jun 29, 2024
commit e07d091d67d32bd28a6920ebbdaaf2fc8462fc99
146 changes: 146 additions & 0 deletions common/multireadcloser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package common

import (
"errors"
"fmt"
"io"
)

// errs is a list of errors.
type Errs []error

// Combine combines multiple non-empty errors into a single error.
func CombineErrs(errs ...error) error {
var group Errs
group.Add(errs...)
return group.Err()
}

// Add adds non-empty errors to the Group.
func (group *Errs) Add(errs ...error) {
for _, err := range errs {
if err != nil {
*group = append(*group, err)
}
}
}

// Err returns an error containing all of the non-nil errors.
// If there was only one error, it will return it.
// If there were none, it returns nil.
func (group Errs) Err() error {
sanitized := group.sanitize()
if len(sanitized) == 0 {
return nil
}
if len(sanitized) == 1 {
return sanitized[0]
}
return combinedError(sanitized)
}

// sanitize returns group that doesn't contain nil-s
func (group Errs) sanitize() Errs {
// sanity check for non-nil errors
for i, err := range group {
if err == nil {
sanitized := make(Errs, 0, len(group)-1)
sanitized = append(sanitized, group[:i]...)
sanitized.Add(group[i+1:]...)
return sanitized
}
}

return group
}

// combinedError is a list of non-empty errors
type combinedError []error

// Unwrap returns the first error.
func (group combinedError) Unwrap() []error { return group }

// Error returns error string delimited by semicolons.
func (group combinedError) Error() string { return fmt.Sprintf("%v", group) }

// Format handles the formatting of the error. Using a "+" on the format
// string specifier will cause the errors to be formatted with "+" and
// delimited by newlines. They are delimited by semicolons otherwise.
func (group combinedError) Format(f fmt.State, c rune) {
delim := "; "
if f.Flag(int('+')) {
io.WriteString(f, "errs:\n--- ")
delim = "\n--- "
}

for i, err := range group {
if i != 0 {
io.WriteString(f, delim)
}
if formatter, ok := err.(fmt.Formatter); ok {
formatter.Format(f, c)
} else {
fmt.Fprintf(f, "%v", err)
}
}
}

type eofReadCloser struct{}

func (eofReadCloser) Read([]byte) (int, error) {
return 0, io.EOF
}

func (eofReadCloser) Close() error {
return nil
}

type multiReadCloser struct {
readers []io.ReadCloser
}

// MultiReadCloser is a MultiReader extension that returns a ReaderCloser
// that's the logical concatenation of the provided input readers.
// They're read sequentially. Once all inputs have returned EOF,
// Read will return EOF. If any of the readers return a non-nil,
// non-EOF error, Read will return that error.
func MultiReadCloser(readers ...io.ReadCloser) io.ReadCloser {
r := make([]io.ReadCloser, len(readers))
copy(r, readers)
return &multiReadCloser{r}
}

func (mr *multiReadCloser) Read(p []byte) (n int, err error) {
for len(mr.readers) > 0 {
// Optimization to flatten nested multiReaders.
if len(mr.readers) == 1 {
if r, ok := mr.readers[0].(*multiReadCloser); ok {
mr.readers = r.readers
continue
}
}
n, err = mr.readers[0].Read(p)
if errors.Is(err, io.EOF) {
err = mr.readers[0].Close()
// Use eofReader instead of nil to avoid nil panic
mr.readers[0] = eofReadCloser{}
mr.readers = mr.readers[1:]
}
if n > 0 || !errors.Is(err, io.EOF) {
if errors.Is(err, io.EOF) && len(mr.readers) > 0 {
// Don't return EOF yet. More readers remain.
err = nil
}
return
}
}
return 0, io.EOF
}

func (mr *multiReadCloser) Close() error {
errlist := make([]error, len(mr.readers))
for i, r := range mr.readers {
errlist[i] = r.Close()
}
return CombineErrs(errlist...)
}
34 changes: 25 additions & 9 deletions peer.go
Original file line number Diff line number Diff line change
@@ -556,16 +556,32 @@ func (cn *Peer) request(r RequestIndex, maxRequests int, lock bool, lockTorrent
}

func (me *Peer) cancel(r RequestIndex, updateRequests bool, lock bool, lockTorrent bool) {
if !me.deleteRequest(r, lock, lockTorrent) {
panic("request not existing should have been guarded")
}
if me._cancel(r, lock, lockTorrent) {
// Record that we expect to get a cancel ack.
if !me.requestState.Cancelled.CheckedAdd(r) {
panic(fmt.Sprintf("request %d: already cancelled for hash: %s", r, me.t.InfoHash()))
func() {
// keep the torrent and peer locked across the whole
// cancel operation to avoid part processing holes

if lockTorrent {
me.t.mu.Lock()
defer me.t.mu.Unlock()
}
}
me.decPeakRequests(lock)

if lock {
me.mu.Lock()
defer me.mu.Unlock()
}

if !me.deleteRequest(r, false, false) {
panic("request not existing should have been guarded")
}
if me._cancel(r, false, false) {
// Record that we expect to get a cancel ack.
if !me.requestState.Cancelled.CheckedAdd(r) {
panic(fmt.Sprintf("request %d: already cancelled for hash: %s", r, me.t.InfoHash()))
}
}
me.decPeakRequests(false)
}()

if updateRequests && me.isLowOnRequests(lock, lockTorrent) {
me.updateRequests("Peer.cancel", lock, lockTorrent)
}
21 changes: 8 additions & 13 deletions webseed-peer.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import (
"github.com/anacrolix/log"
"golang.org/x/time/rate"

"github.com/anacrolix/torrent/common"
"github.com/anacrolix/torrent/metainfo"
pp "github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/storage"
@@ -538,18 +539,8 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
}
}

if len(piece) == 0 {
var readers []io.Reader

// TODO this will cause an additional buffer to
// get created - which is not ideal - but would
// require receive chunck etc to be io interface
// rather than buffer based
for _, reader := range result.Readers {
readers = append(readers, reader)
}

piece, _ = io.ReadAll(io.MultiReader(readers...))
if piece == nil && len(result.Readers) > 0 {
piece, _ = io.ReadAll(common.MultiReadCloser(result.Readers...))
}

// We do this here rather than inside receiveChunk, since we want to count errors too. I'm not
@@ -592,7 +583,7 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
index := ws.peer.t.requestIndexFromRequest(r, true)

if !ws.peer.remoteRejectedRequest(index) {
panic(fmt.Sprintf("invalid reject %s for: %d", err, index))
panic(fmt.Sprintf(`invalid reject "%s" for: %d`, err, index))
}

return err
@@ -605,6 +596,10 @@ func (ws *webseedPeer) requestResultHandler(r Request, webseedRequest webseed.Re
return result.Ctx.Err()
}

if len(piece) == 0 {
fmt.Println("Received empty piece:", r.Index, " from:", ws.peer.String())
}

err = ws.peer.receiveChunk(&pp.Message{
Type: pp.Piece,
Index: r.Index,
6 changes: 5 additions & 1 deletion webseed/client.go
Original file line number Diff line number Diff line change
@@ -216,8 +216,12 @@ func readRequestPartResponses(ctx context.Context, parts []requestPart, receivin
if err = func() error {
receivingCounter.Add(1)
defer receivingCounter.Add(-1)
if err := recvPartResult(ctx, readWriter, part, result); err != nil {
readWriter.Close()
return err
}
readers = append(readers, readWriter)
return recvPartResult(ctx, readWriter, part, result)
return nil
}(); err != nil {
return readers, fmt.Errorf("reading %q at %q: %w", part.req.URL, part.req.Header.Get("Range"), err)
}