Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Mar 4, 2024
1 parent 3a0c124 commit 600da36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import (
"github.com/anacrolix/chansync/events"
"github.com/anacrolix/dht/v2"
"github.com/anacrolix/dht/v2/krpc"
. "github.com/anacrolix/generics"
g "github.com/anacrolix/generics"
"github.com/anacrolix/log"
"github.com/anacrolix/missinggo/perf"
"github.com/anacrolix/missinggo/v2"
"github.com/anacrolix/missinggo/v2/bitmap"
"github.com/anacrolix/missinggo/v2/pproffd"
"github.com/anacrolix/sync"
Expand All @@ -35,6 +33,7 @@ import (
"github.com/dustin/go-humanize"
gbtree "github.com/google/btree"
"github.com/pion/datachannel"
"golang.org/x/sync/semaphore"

"github.com/anacrolix/torrent/bencode"
"github.com/anacrolix/torrent/internal/check"
Expand Down Expand Up @@ -91,6 +90,7 @@ type Client struct {
clientHolepunchAddrSets

defaultLocalLtepProtocolMap LocalLtepProtocolMap
hashersLimit *semaphore.Weighted
}

type ipStr string
Expand Down Expand Up @@ -198,6 +198,7 @@ func (cl *Client) announceKey() int32 {
// Initializes a bare minimum Client. *Client and *ClientConfig must not be nil.
func (cl *Client) init(cfg *ClientConfig) {
cl.config = cfg
cl.hashersLimit = semaphore.NewWeighted(9000)
g.MakeMap(&cl.dopplegangerAddrs)
cl.torrents = make(map[metainfo.Hash]*Torrent)
cl.activeAnnounceLimiter.SlotsPerKey = 2
Expand Down
5 changes: 5 additions & 0 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,11 @@ func (t *Torrent) dropBannedPeers() {
}

func (t *Torrent) pieceHasher(index pieceIndex) {
if err := t.cl.hashersLimit.Acquire(context.Background(), 1); err != nil {
return
}
defer t.cl.hashersLimit.Release(1)

p := t.piece(index)
sum, failedPeers, copyErr := t.hashPiece(index)
correct := sum == *p.hash
Expand Down

0 comments on commit 600da36

Please sign in to comment.