Merge branch 'master' into crawshaw

This commit is contained in:
Matt Joiner 2022-03-11 14:23:13 +11:00
commit 361300cc93
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
9 changed files with 45 additions and 6 deletions

View File

@ -1446,6 +1446,15 @@ func (cl *Client) banPeerIP(ip net.IP) {
cl.badPeerIPs = make(map[string]struct{})
}
cl.badPeerIPs[ip.String()] = struct{}{}
for _, t := range cl.torrents {
t.iterPeers(func(p *Peer) {
if p.remoteIp().Equal(ip) {
t.logger.Levelf(log.Warning, "dropping peer %v with banned ip %v", p, ip)
// Should this be a close?
p.drop()
}
})
}
}
func (cl *Client) newConnection(nc net.Conn, outgoing bool, remoteAddr PeerRemoteAddr, network, connString string) (c *PeerConn) {

View File

@ -23,6 +23,8 @@ func main() {
EmptyAnnounceList bool `name:"n" help:"exclude default announce-list entries"`
Comment string `name:"t" help:"comment"`
CreatedBy string `name:"c" help:"created by"`
InfoName *string `name:"i" help:"override info name (defaults to ROOT)"`
Url []string `name:"u" help:"add webseed url"`
tagflag.StartPos
Root string
}
@ -43,6 +45,7 @@ func main() {
if len(args.CreatedBy) > 0 {
mi.CreatedBy = args.CreatedBy
}
mi.UrlList = args.Url
info := metainfo.Info{
PieceLength: 256 * 1024,
}
@ -50,6 +53,9 @@ func main() {
if err != nil {
log.Fatal(err)
}
if args.InfoName != nil {
info.Name = *args.InfoName
}
mi.InfoBytes, err = bencode.Marshal(info)
if err != nil {
log.Fatal(err)

2
go.mod
View File

@ -12,7 +12,7 @@ require (
github.com/anacrolix/envpprof v1.1.1
github.com/anacrolix/fuse v0.2.0
github.com/anacrolix/go-libutp v1.2.0
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8
github.com/anacrolix/log v0.13.1
github.com/anacrolix/missinggo v1.3.0
github.com/anacrolix/missinggo/perf v1.0.0
github.com/anacrolix/missinggo/v2 v2.5.2

3
go.sum
View File

@ -136,8 +136,9 @@ github.com/anacrolix/log v0.7.1-0.20200604014615-c244de44fd2d/go.mod h1:s5yBP/j0
github.com/anacrolix/log v0.8.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.9.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.10.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8 h1:o1KNFCLJ6f5SRMVb70SUFiPnNiazVd0gpMxYfYCsvK4=
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8/go.mod h1:GmnE2c0nvz8pOIPUSC9Rawgefy1sDXqposC2wgtBZE4=
github.com/anacrolix/log v0.13.1 h1:BmVwTdxHd5VcNrLylgKwph4P4wf+5VvPgOK4yi91fTY=
github.com/anacrolix/log v0.13.1/go.mod h1:D4+CvN8SnruK6zIFS/xPoRJmtvtnxs+CSfDQ+BFxZ68=
github.com/anacrolix/lsan v0.0.0-20211126052245-807000409a62 h1:P04VG6Td13FHMgS5ZBcJX23NPC/fiC4cp9bXwYujdYM=
github.com/anacrolix/lsan v0.0.0-20211126052245-807000409a62/go.mod h1:66cFKPCO7Sl4vbFnAaSq7e4OXtdMhRSBagJGWgmpJbM=
github.com/anacrolix/missinggo v0.0.0-20180522035225-b4a5853e62ff/go.mod h1:b0p+7cn+rWMIphK1gDH2hrDuwGOcbB6V4VXeSsEfHVk=

View File

@ -20,7 +20,10 @@ type peerImpl interface {
connectionFlags() string
onClose()
onGotInfo(*metainfo.Info)
// Drop connection. This may be a no-op if there is no connection.
drop()
// Rebuke the peer
ban()
String() string
connStatusString() string

View File

@ -1590,6 +1590,10 @@ func (cn *PeerConn) drop() {
cn.t.dropConnection(cn)
}
func (cn *PeerConn) ban() {
cn.t.cl.banPeerIP(cn.remoteIp())
}
func (cn *Peer) netGoodPiecesDirtied() int64 {
return cn._stats.PiecesDirtiedGood.Int64() - cn._stats.PiecesDirtiedBad.Int64()
}

View File

@ -2024,8 +2024,7 @@ func (t *Torrent) pieceHashed(piece pieceIndex, passed bool, hashIoErr error) {
if len(bannableTouchers) >= 1 {
c := bannableTouchers[0]
t.cl.banPeerIP(c.remoteIp())
c.drop()
c.ban()
}
}
t.onIncompletePiece(piece)
@ -2284,6 +2283,14 @@ func (t *Torrent) callbacks() *Callbacks {
return &t.cl.config.Callbacks
}
func (t *Torrent) AddWebSeeds(urls []string) {
t.cl.lock()
defer t.cl.unlock()
for _, u := range urls {
t.addWebSeed(u)
}
}
func (t *Torrent) addWebSeed(url string) {
if t.cl.config.DisableWebseeds {
return

View File

@ -114,10 +114,13 @@ func (ws *webseedPeer) connectionFlags() string {
return "WS"
}
// TODO: This is called when banning peers. Perhaps we want to be able to ban webseeds too. We could
// return bool if this is even possible, and if it isn't, skip to the next drop candidate.
// Maybe this should drop all existing connections, or something like that.
func (ws *webseedPeer) drop() {}
func (cn *webseedPeer) ban() {
cn.peer.close()
}
func (ws *webseedPeer) handleUpdateRequests() {
// Because this is synchronous, webseed peers seem to get first dibs on newly prioritized
// pieces.

View File

@ -21,3 +21,9 @@ func TestTrailingPath(t *testing.T) {
"a_1-b_c2/d 3. (e, f).g",
)
}
func TestTrailingPathForEmptyInfoName(t *testing.T) {
qt.Check(t, trailingPath("", []string{`ノ┬─┬ノ ︵ ( \o°o)\`}), qt.Equals, "%E3%83%8E%E2%94%AC%E2%94%80%E2%94%AC%E3%83%8E+%EF%B8%B5+%28+%5Co%C2%B0o%29%5C")
qt.Check(t, trailingPath("", []string{"hello", "world"}), qt.Equals, "hello/world")
qt.Check(t, trailingPath("war", []string{"and", "peace"}), qt.Equals, "war/and/peace")
}