fix: do not add external tracker to a private torrent (#1011)

This commit is contained in:
Charles Huang authored and GitHub committed 2025-04-23 22:53:15 +08:00
1 parent ff43a373cd
commit 3262e5a11b
1 file changed
+21 -7
+21 -7
View File
@@ -4,13 +4,6 @@ import (
"bytes" "bytes"
"context" "context"
"fmt" "fmt"
"github.com/GopeedLab/gopeed/internal/controller"
"github.com/GopeedLab/gopeed/internal/fetcher"
"github.com/GopeedLab/gopeed/pkg/base"
"github.com/GopeedLab/gopeed/pkg/protocol/bt"
"github.com/GopeedLab/gopeed/pkg/util"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/metainfo"
"io" "io"
"net/url" "net/url"
"os" "os"
@@ -19,6 +12,14 @@ import (
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/GopeedLab/gopeed/internal/controller"
"github.com/GopeedLab/gopeed/internal/fetcher"
"github.com/GopeedLab/gopeed/pkg/base"
"github.com/GopeedLab/gopeed/pkg/protocol/bt"
"github.com/GopeedLab/gopeed/pkg/util"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/metainfo"
) )
var ( var (
@@ -359,6 +360,7 @@ func (f *Fetcher) addTorrent(req *base.Request, fromUpload bool) (err error) {
return return
} }
schema := util.ParseSchema(req.URL) schema := util.ParseSchema(req.URL)
privateTorrent := false
if schema == "MAGNET" { if schema == "MAGNET" {
f.torrent, err = client.AddMagnet(req.URL) f.torrent, err = client.AddMagnet(req.URL)
} else { } else {
@@ -388,12 +390,23 @@ func (f *Fetcher) addTorrent(req *base.Request, fromUpload bool) (err error) {
if err != nil && !strings.Contains(err.Error(), "expected EOF") { if err != nil && !strings.Contains(err.Error(), "expected EOF") {
return err return err
} }
info, er := metaInfo.UnmarshalInfo()
if er != nil {
return er
}
if info.Private != nil && *info.Private {
privateTorrent = true
}
f.torrent, err = client.AddTorrent(metaInfo) f.torrent, err = client.AddTorrent(metaInfo)
} }
if err != nil { if err != nil {
return return
} }
// Do not add external tracker to a private torrent.
if !privateTorrent {
// use map to deduplicate // use map to deduplicate
trackers := make(map[string]bool) trackers := make(map[string]bool)
if req.Extra != nil { if req.Extra != nil {
@@ -416,6 +429,7 @@ func (f *Fetcher) addTorrent(req *base.Request, fromUpload bool) (err error) {
} }
f.torrent.AddTrackers(announceList) f.torrent.AddTrackers(announceList)
} }
}
<-f.torrent.GotInfo() <-f.torrent.GotInfo()
f.torrentReady.Store(true) f.torrentReady.Store(true)