Switch to external anacrolix/generics
This commit is contained in:
parent
9e5dac9514
commit
1cff4fe95e
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/anacrolix/chansync/events"
|
||||
"github.com/anacrolix/dht/v2"
|
||||
"github.com/anacrolix/dht/v2/krpc"
|
||||
"github.com/anacrolix/generics"
|
||||
"github.com/anacrolix/log"
|
||||
"github.com/anacrolix/missinggo/perf"
|
||||
"github.com/anacrolix/missinggo/pubsub"
|
||||
|
@ -29,8 +30,6 @@ import (
|
|||
"github.com/anacrolix/missinggo/v2/bitmap"
|
||||
"github.com/anacrolix/missinggo/v2/pproffd"
|
||||
"github.com/anacrolix/sync"
|
||||
"github.com/anacrolix/torrent/generics"
|
||||
"github.com/anacrolix/torrent/option"
|
||||
request_strategy "github.com/anacrolix/torrent/request-strategy"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/dustin/go-humanize"
|
||||
|
@ -39,6 +38,7 @@ import (
|
|||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/anacrolix/chansync"
|
||||
. "github.com/anacrolix/generics"
|
||||
|
||||
"github.com/anacrolix/torrent/bencode"
|
||||
"github.com/anacrolix/torrent/internal/limiter"
|
||||
|
@ -1518,7 +1518,7 @@ func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr PeerRemot
|
|||
if remoteAddr != nil {
|
||||
netipAddrPort, err := netip.ParseAddrPort(remoteAddr.String())
|
||||
if err == nil {
|
||||
c.bannableAddr = option.Some(netipAddrPort.Addr())
|
||||
c.bannableAddr = Some(netipAddrPort.Addr())
|
||||
}
|
||||
}
|
||||
c.peerImpl = c
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package generics
|
||||
|
||||
func MakeMapIfNilAndSet[K comparable, V any](pm *map[K]V, k K, v V) {
|
||||
m := *pm
|
||||
if m == nil {
|
||||
m = make(map[K]V)
|
||||
*pm = m
|
||||
}
|
||||
m[k] = v
|
||||
}
|
||||
|
||||
// Does this exist in the maps package?
|
||||
func MakeMap[K comparable, V any](pm *map[K]V) {
|
||||
*pm = make(map[K]V)
|
||||
}
|
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require (
|
|||
github.com/anacrolix/dht/v2 v2.14.1-0.20211220010335-4062f7927abf
|
||||
github.com/anacrolix/envpprof v1.1.1
|
||||
github.com/anacrolix/fuse v0.2.0
|
||||
github.com/anacrolix/generics v0.0.0-20220121083126-c81e77b56d6d
|
||||
github.com/anacrolix/go-libutp v1.1.0
|
||||
github.com/anacrolix/log v0.10.0
|
||||
github.com/anacrolix/missinggo v1.3.0
|
||||
|
|
2
go.sum
2
go.sum
|
@ -37,6 +37,8 @@ github.com/anacrolix/envpprof v1.1.1 h1:sHQCyj7HtiSfaZAzL2rJrQdyS7odLqlwO6nhk/tG
|
|||
github.com/anacrolix/envpprof v1.1.1/go.mod h1:My7T5oSqVfEn4MD4Meczkw/f5lSIndGAKu/0SM/rkf4=
|
||||
github.com/anacrolix/fuse v0.2.0 h1:pc+To78kI2d/WUjIyrsdqeJQAesuwpGxlI3h1nAv3Do=
|
||||
github.com/anacrolix/fuse v0.2.0/go.mod h1:Kfu02xBwnySDpH3N23BmrP3MDfwAQGRLUCj6XyeOvBQ=
|
||||
github.com/anacrolix/generics v0.0.0-20220121083126-c81e77b56d6d h1:hKdj31gsNwxan3Lr4S5N1wXQI+0pMnX6/qZt75GSq7U=
|
||||
github.com/anacrolix/generics v0.0.0-20220121083126-c81e77b56d6d/go.mod h1:SommN0/3j+jrAnjopAZfqkREMGw59ELwloDcx6Y0KLA=
|
||||
github.com/anacrolix/go-libutp v1.1.0 h1:89XK+0NBTaKgSoG/v5OfDK0yoyrt2HInfg46I1BaT2E=
|
||||
github.com/anacrolix/go-libutp v1.1.0/go.mod h1:so9zroOUhFPGnIkddyflaCCl+xdTsRSq97/AOQ2/Hjk=
|
||||
github.com/anacrolix/log v0.3.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package option
|
||||
|
||||
type T[V any] struct {
|
||||
ok bool
|
||||
value V
|
||||
}
|
||||
|
||||
func (me *T[V]) Ok() bool {
|
||||
return me.ok
|
||||
}
|
||||
|
||||
func (me *T[V]) Value() V {
|
||||
if !me.ok {
|
||||
panic("not set")
|
||||
}
|
||||
return me.value
|
||||
}
|
||||
|
||||
func Some[V any](value V) T[V] {
|
||||
return T[V]{ok: true, value: value}
|
||||
}
|
|
@ -15,13 +15,12 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/RoaringBitmap/roaring"
|
||||
"github.com/anacrolix/chansync"
|
||||
. "github.com/anacrolix/generics"
|
||||
"github.com/anacrolix/log"
|
||||
"github.com/anacrolix/missinggo/iter"
|
||||
"github.com/anacrolix/missinggo/v2/bitmap"
|
||||
"github.com/anacrolix/multiless"
|
||||
"github.com/anacrolix/torrent/option"
|
||||
|
||||
"github.com/anacrolix/chansync"
|
||||
"github.com/anacrolix/torrent/bencode"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"github.com/anacrolix/torrent/mse"
|
||||
|
@ -68,7 +67,7 @@ type Peer struct {
|
|||
outgoing bool
|
||||
Network string
|
||||
RemoteAddr PeerRemoteAddr
|
||||
bannableAddr option.T[bannableAddr]
|
||||
bannableAddr Option[bannableAddr]
|
||||
// True if the connection is operating over MSE obfuscation.
|
||||
headerEncrypted bool
|
||||
cryptoMethod mse.CryptoMethod
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"crypto/sha1"
|
||||
"net/netip"
|
||||
|
||||
"github.com/anacrolix/torrent/generics"
|
||||
"github.com/anacrolix/generics"
|
||||
"github.com/anacrolix/torrent/smartban"
|
||||
)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/anacrolix/chansync"
|
||||
"github.com/anacrolix/chansync/events"
|
||||
"github.com/anacrolix/dht/v2"
|
||||
. "github.com/anacrolix/generics"
|
||||
"github.com/anacrolix/log"
|
||||
"github.com/anacrolix/missinggo/perf"
|
||||
"github.com/anacrolix/missinggo/pubsub"
|
||||
|
@ -28,7 +29,6 @@ import (
|
|||
"github.com/anacrolix/missinggo/v2/bitmap"
|
||||
"github.com/anacrolix/multiless"
|
||||
"github.com/anacrolix/sync"
|
||||
"github.com/anacrolix/torrent/option"
|
||||
request_strategy "github.com/anacrolix/torrent/request-strategy"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/pion/datachannel"
|
||||
|
@ -2139,7 +2139,7 @@ func (t *Torrent) dropBannedPeers() {
|
|||
return
|
||||
}
|
||||
netipAddr := netip.MustParseAddr(remoteIp.String())
|
||||
if option.Some(netipAddr) != p.bannableAddr {
|
||||
if Some(netipAddr) != p.bannableAddr {
|
||||
log.Printf(
|
||||
"peer remote ip does not match its bannable addr [peer=%v, remote ip=%v, bannable addr=%v]",
|
||||
p, remoteIp, p.bannableAddr)
|
||||
|
|
Loading…
Reference in New Issue