diff --git a/server/go.mod b/server/go.mod index f3f1d3f..c8ecdb1 100644 --- a/server/go.mod +++ b/server/go.mod @@ -2,9 +2,7 @@ module server go 1.17 -replace ( - github.com/anacrolix/dms v1.2.2 => github.com/yourok/dms v0.0.0-20210826085116-42eca44e0aef -) +replace github.com/anacrolix/dms v1.2.2 => github.com/yourok/dms v0.0.0-20210826085116-42eca44e0aef exclude github.com/willf/bitset v1.2.0 @@ -29,7 +27,9 @@ require ( github.com/anacrolix/chansync v0.1.0 // indirect github.com/anacrolix/confluence v1.8.0 // indirect github.com/anacrolix/dht/v2 v2.10.3 // indirect + github.com/anacrolix/envpprof v1.1.1 // indirect github.com/anacrolix/ffprobe v1.0.0 // indirect + github.com/anacrolix/go-libutp v1.0.4 // indirect github.com/anacrolix/log v0.9.0 // indirect github.com/anacrolix/missinggo/perf v1.0.0 // indirect github.com/anacrolix/missinggo/v2 v2.5.2 // indirect diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 773b609..4021475 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -6,7 +6,6 @@ import ( "os" "path/filepath" "sort" - "sync" "time" "github.com/anacrolix/torrent" @@ -17,8 +16,7 @@ import ( ) var ( - bts *BTServer - lockApi sync.Mutex + bts *BTServer ) func InitApiHelper(bt *BTServer) { @@ -26,8 +24,6 @@ func InitApiHelper(bt *BTServer) { } func LoadTorrent(tor *Torrent) *Torrent { - lockApi.Lock() - defer lockApi.Unlock() if tor.TorrentSpec == nil { return nil } @@ -45,8 +41,6 @@ func LoadTorrent(tor *Torrent) *Torrent { } func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string) (*Torrent, error) { - lockApi.Lock() - defer lockApi.Unlock() torr, err := NewTorrent(spec, bts) if err != nil { log.TLogln("error add torrent:", err) @@ -86,8 +80,6 @@ func SaveTorrentToDB(torr *Torrent) { } func GetTorrent(hashHex string) *Torrent { - lockApi.Lock() - defer lockApi.Unlock() hash := metainfo.NewHashFromHex(hashHex) tor := bts.GetTorrent(hash) if tor != nil { @@ -99,8 +91,6 @@ func GetTorrent(hashHex string) *Torrent { if tr != nil { tor = tr go func() { - lockApi.Lock() - defer lockApi.Unlock() log.TLogln("New torrent", tor.Hash()) tr, _ := NewTorrent(tor.TorrentSpec, bts) if tr != nil { @@ -117,9 +107,6 @@ func GetTorrent(hashHex string) *Torrent { } func SetTorrent(hashHex, title, poster, data string) *Torrent { - lockApi.Lock() - defer lockApi.Unlock() - hash := metainfo.NewHashFromHex(hashHex) torr := bts.GetTorrent(hash) torrDb := GetTorrentDB(hash) @@ -155,8 +142,6 @@ func SetTorrent(hashHex, title, poster, data string) *Torrent { } func RemTorrent(hashHex string) { - lockApi.Lock() - defer lockApi.Unlock() hash := metainfo.NewHashFromHex(hashHex) if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" { name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex) @@ -174,8 +159,6 @@ func RemTorrent(hashHex string) { } func ListTorrent() []*Torrent { - lockApi.Lock() - defer lockApi.Unlock() btlist := bts.ListTorrents() dblist := ListTorrentsDB() @@ -202,8 +185,6 @@ func ListTorrent() []*Torrent { } func DropTorrent(hashHex string) { - lockApi.Lock() - defer lockApi.Unlock() hash := metainfo.NewHashFromHex(hashHex) bts.RemoveTorrent(hash) } @@ -212,12 +193,6 @@ func SetSettings(set *sets.BTSets) { if sets.ReadOnly { return } - lockApi.Lock() - defer lockApi.Unlock() - log.TLogln("drop all torrents") - dropAllTorrent() - time.Sleep(time.Second * 2) - log.TLogln("disconect") bts.Disconnect() sets.SetBTSets(set) log.TLogln("connect") @@ -230,12 +205,6 @@ func SetDefSettings() { if sets.ReadOnly { return } - lockApi.Lock() - defer lockApi.Unlock() - log.TLogln("drop all torrents") - dropAllTorrent() - time.Sleep(time.Second * 2) - log.TLogln("disconect") bts.Disconnect() sets.SetDefault() log.TLogln("connect") @@ -252,8 +221,6 @@ func dropAllTorrent() { } func Shutdown() { - lockApi.Lock() - defer lockApi.Unlock() bts.Disconnect() sets.CloseDB() log.TLogln("Received shutdown. Quit") @@ -265,8 +232,6 @@ func WriteStatus(w io.Writer) { } func Preload(torr *Torrent, index int) { - lockApi.Lock() - lockApi.Unlock() cache := float32(sets.BTsets.CacheSize) preload := float32(sets.BTsets.PreloadCache) size := int64((cache / 100.0) * preload)