Import generics as g

This commit is contained in:
Matt Joiner 2023-04-04 19:12:26 +10:00
parent 069b92a98c
commit 42d29d95a6
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
5 changed files with 11 additions and 11 deletions

View File

@ -23,7 +23,7 @@ import (
"github.com/anacrolix/chansync/events" "github.com/anacrolix/chansync/events"
"github.com/anacrolix/dht/v2" "github.com/anacrolix/dht/v2"
"github.com/anacrolix/dht/v2/krpc" "github.com/anacrolix/dht/v2/krpc"
"github.com/anacrolix/generics" g "github.com/anacrolix/generics"
. "github.com/anacrolix/generics" . "github.com/anacrolix/generics"
"github.com/anacrolix/log" "github.com/anacrolix/log"
"github.com/anacrolix/missinggo/perf" "github.com/anacrolix/missinggo/perf"
@ -195,7 +195,7 @@ func (cl *Client) announceKey() int32 {
// Initializes a bare minimum Client. *Client and *ClientConfig must not be nil. // Initializes a bare minimum Client. *Client and *ClientConfig must not be nil.
func (cl *Client) init(cfg *ClientConfig) { func (cl *Client) init(cfg *ClientConfig) {
cl.config = cfg cl.config = cfg
generics.MakeMap(&cl.dopplegangerAddrs) g.MakeMap(&cl.dopplegangerAddrs)
cl.torrents = make(map[metainfo.Hash]*Torrent) cl.torrents = make(map[metainfo.Hash]*Torrent)
cl.dialRateLimiter = rate.NewLimiter(10, 10) cl.dialRateLimiter = rate.NewLimiter(10, 10)
cl.activeAnnounceLimiter.SlotsPerKey = 2 cl.activeAnnounceLimiter.SlotsPerKey = 2
@ -1461,7 +1461,7 @@ func (cl *Client) banPeerIP(ip net.IP) {
if !ok { if !ok {
panic(ip) panic(ip)
} }
generics.MakeMapIfNilAndSet(&cl.badPeerIPs, ipAddr, struct{}{}) g.MakeMapIfNilAndSet(&cl.badPeerIPs, ipAddr, struct{}{})
for _, t := range cl.torrents { for _, t := range cl.torrents {
t.iterPeers(func(p *Peer) { t.iterPeers(func(p *Peer) {
if p.remoteIp().Equal(ip) { if p.remoteIp().Equal(ip) {

View File

@ -1,7 +1,7 @@
package torrent package torrent
import ( import (
"github.com/anacrolix/generics" g "github.com/anacrolix/generics"
list "github.com/bahlo/generic-list-go" list "github.com/bahlo/generic-list-go"
"github.com/anacrolix/torrent/typed-roaring" "github.com/anacrolix/torrent/typed-roaring"
@ -33,7 +33,7 @@ func (o *orderedBitmap[T]) Contains(index T) bool {
func (o *orderedBitmap[T]) Add(index T) { func (o *orderedBitmap[T]) Add(index T) {
o.bitmap.Add(index) o.bitmap.Add(index)
if _, ok := o.elements[index]; !ok { if _, ok := o.elements[index]; !ok {
generics.MakeMapIfNilAndSet(&o.elements, index, o.order.PushBack(index)) g.MakeMapIfNilAndSet(&o.elements, index, o.order.PushBack(index))
} }
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"expvar" "expvar"
"github.com/anacrolix/generics" g "github.com/anacrolix/generics"
"github.com/anacrolix/multiless" "github.com/anacrolix/multiless"
"github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/metainfo"
@ -55,7 +55,7 @@ func GetRequestablePieces(
storageLeft = &cap storageLeft = &cap
} }
var allTorrentsUnverifiedBytes int64 var allTorrentsUnverifiedBytes int64
var lastItem generics.Option[pieceRequestOrderItem] var lastItem g.Option[pieceRequestOrderItem]
pro.tree.Scan(func(_i pieceRequestOrderItem) bool { pro.tree.Scan(func(_i pieceRequestOrderItem) bool {
// Check that scan emits pieces in priority order. // Check that scan emits pieces in priority order.
if lastItem.Ok { if lastItem.Ok {

View File

@ -5,7 +5,7 @@ import (
"crypto/sha1" "crypto/sha1"
"net/netip" "net/netip"
"github.com/anacrolix/generics" g "github.com/anacrolix/generics"
"github.com/anacrolix/torrent/smartban" "github.com/anacrolix/torrent/smartban"
) )
@ -26,7 +26,7 @@ type blockCheckingWriter struct {
func (me *blockCheckingWriter) checkBlock() { func (me *blockCheckingWriter) checkBlock() {
b := me.blockBuffer.Next(me.chunkSize) b := me.blockBuffer.Next(me.chunkSize)
for _, peer := range me.cache.CheckBlock(me.requestIndex, b) { for _, peer := range me.cache.CheckBlock(me.requestIndex, b) {
generics.MakeMapIfNilAndSet(&me.badPeers, peer, struct{}{}) g.MakeMapIfNilAndSet(&me.badPeers, peer, struct{}{})
} }
me.requestIndex++ me.requestIndex++
} }

View File

@ -9,7 +9,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/anacrolix/generics" g "github.com/anacrolix/generics"
"github.com/anacrolix/log" "github.com/anacrolix/log"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/pion/datachannel" "github.com/pion/datachannel"
@ -286,7 +286,7 @@ func (tc *TrackerClient) announce(event tracker.AnnounceEvent, infoHash [20]byte
return fmt.Errorf("write AnnounceRequest: %w", err) return fmt.Errorf("write AnnounceRequest: %w", err)
} }
for _, offer := range offers { for _, offer := range offers {
generics.MakeMapIfNilAndSet(&tc.outboundOffers, offer.offerId, offer.outboundOfferValue) g.MakeMapIfNilAndSet(&tc.outboundOffers, offer.offerId, offer.outboundOfferValue)
} }
return nil return nil
} }