]> Sergey Matveev's repositories - btrtrc.git/blobdiff - misc.go
Drop support for go 1.20
[btrtrc.git] / misc.go
diff --git a/misc.go b/misc.go
index 139af2d405844534c2e9018dbc68ba9e0eff5f12..7d3007ecee74eb92f58eee434dfb9431a86f9098 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -4,12 +4,14 @@ import (
        "errors"
        "net"
 
+       "github.com/RoaringBitmap/roaring"
        "github.com/anacrolix/missinggo/v2"
-       "github.com/anacrolix/torrent/types"
        "golang.org/x/time/rate"
 
        "github.com/anacrolix/torrent/metainfo"
        pp "github.com/anacrolix/torrent/peer_protocol"
+       "github.com/anacrolix/torrent/types"
+       "github.com/anacrolix/torrent/types/infohash"
 )
 
 type (
@@ -113,7 +115,8 @@ func connLessTrusted(l, r *Peer) bool {
 
 func connIsIpv6(nc interface {
        LocalAddr() net.Addr
-}) bool {
+},
+) bool {
        ra := nc.LocalAddr()
        rip := addrIpOrNil(ra)
        return rip.To4() == nil && rip.To16() != nil
@@ -142,6 +145,16 @@ func max(as ...int64) int64 {
        return ret
 }
 
+func maxInt(as ...int) int {
+       ret := as[0]
+       for _, a := range as[1:] {
+               if a > ret {
+                       ret = a
+               }
+       }
+       return ret
+}
+
 func min(as ...int64) int64 {
        ret := as[0]
        for _, a := range as[1:] {
@@ -166,6 +179,16 @@ var unlimited = rate.NewLimiter(rate.Inf, 0)
 
 type (
        pieceIndex = int
-       InfoHash   = metainfo.Hash
-       IpPort     = missinggo.IpPort
+       // Deprecated: Use infohash.T directly to avoid unnecessary imports.
+       InfoHash = infohash.T
+       IpPort   = missinggo.IpPort
 )
+
+func boolSliceToBitmap(slice []bool) (rb roaring.Bitmap) {
+       for i, b := range slice {
+               if b {
+                       rb.AddInt(i)
+               }
+       }
+       return
+}