+func connLessTrusted(l, r *Peer) bool {
+ return l.trust().Less(r.trust())
+}
+
+func connIsIpv6(nc interface {
+ LocalAddr() net.Addr
+},
+) bool {
+ ra := nc.LocalAddr()
+ rip := addrIpOrNil(ra)
+ return rip.To4() == nil && rip.To16() != nil
+}
+
+func clamp(min, value, max int64) int64 {
+ if min > max {
+ panic("harumph")
+ }
+ if value < min {
+ value = min
+ }
+ if value > max {
+ value = max
+ }
+ return value
+}
+
+func max(as ...int64) int64 {
+ ret := as[0]
+ for _, a := range as[1:] {
+ if a > ret {
+ ret = a
+ }
+ }
+ 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:] {
+ if a < ret {
+ ret = a
+ }
+ }
+ return ret
+}
+
+func minInt(as ...int) int {
+ ret := as[0]
+ for _, a := range as[1:] {
+ if a < ret {
+ ret = a
+ }
+ }
+ return ret
+}
+
+var unlimited = rate.NewLimiter(rate.Inf, 0)
+
+type (
+ pieceIndex = int
+ // 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