]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Merge branch 'master' into crawshaw
authorMatt Joiner <anacrolix@gmail.com>
Fri, 11 Mar 2022 03:23:13 +0000 (14:23 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 11 Mar 2022 03:23:13 +0000 (14:23 +1100)
client.go
cmd/torrent-create/main.go
go.mod
go.sum
peer-impl.go
peerconn.go
torrent.go
webseed-peer.go
webseed/request_test.go

index 804b4c797581b84b98190cd5e6d81e82c9414eb4..a6b6b21642681f65fdda2dc46c392dff17d1a141 100644 (file)
--- a/client.go
+++ b/client.go
@@ -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) {
index 3177d6ce945b2dab7a9768d82010b205563afb6e..2f92978f0af2e206075a2a302c5767644676d295 100644 (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)
diff --git a/go.mod b/go.mod
index 9f1581e5dad5113a47eba7d8217ebd5faae2e0d8..9e6354c0c7c77eb3fd5bb3ac962b2a0f5c451edf 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -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
diff --git a/go.sum b/go.sum
index d9f3443289d92616b233799e858ee7d312b05345..3828dd0e1c9664fa10261a7b50d158eb47377f02 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -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=
index e29fb43967cb255086dc3fa73dead6b077749df4..1b9cf978205506a598fbfbad1812a31cf5cafb40 100644 (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
 
index bc16ae6c63cabad8a18680e5ac9da3cb280c4574..6615d79c5a4573bab13a3561b5be4d95463fe170 100644 (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()
 }
index f9635e31d3b1c40086655e5658617d33d8261f34..9791b9305a9baa0683ca2682cdc417b396173940 100644 (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
index 9b1cba2233ec82f05d09a94b4a5177d3d592b138..0cdf4cacd4950300d27b2c4625fc92d10229f712 100644 (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.
index b82a00576e333d02d6ccccbea682b80e4da45559..f7c18a03fdb92df6e4649d71019a581dbada6833 100644 (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")
+}