diff --git a/go.mod b/go.mod
index 795bc38b4a..b674978b79 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
- github.com/CortexFoundation/torrentfs v1.0.55-0.20231007121016-6eb55dfda9e1
+ github.com/CortexFoundation/torrentfs v1.0.55-0.20231009075214-e36a3a83f0a7
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/arsham/figurine v1.3.0
github.com/aws/aws-sdk-go-v2 v1.21.1
diff --git a/go.sum b/go.sum
index e505dce335..4005ad73a3 100644
--- a/go.sum
+++ b/go.sum
@@ -66,8 +66,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
-github.com/CortexFoundation/torrentfs v1.0.55-0.20231007121016-6eb55dfda9e1 h1:mUMfJsKUhT7k+CBpYsGbW3moXeDCggktrR9GgXPk4So=
-github.com/CortexFoundation/torrentfs v1.0.55-0.20231007121016-6eb55dfda9e1/go.mod h1:+ZfWvq66ESoZ4fuPfmrv/qElLqMCFvMCFj8k26lRWvE=
+github.com/CortexFoundation/torrentfs v1.0.55-0.20231009075214-e36a3a83f0a7 h1:VjnoO3DGsQP2+43muYFSfCAVwSWYVkQZRXdOEbKfnoY=
+github.com/CortexFoundation/torrentfs v1.0.55-0.20231009075214-e36a3a83f0a7/go.mod h1:+ZfWvq66ESoZ4fuPfmrv/qElLqMCFvMCFj8k26lRWvE=
github.com/CortexFoundation/wormhole v0.0.2-0.20230922082251-f97b53242e48 h1:EDrk6U+GjSJ1FdbTrtRDe3LA/Ot6E3xu/HpXAio99B4=
github.com/CortexFoundation/wormhole v0.0.2-0.20230922082251-f97b53242e48/go.mod h1:a2ynt5IqAlGTWLQY0pILqkxYe4AzHLNd+bPmK/r03oE=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
diff --git a/vendor/github.com/CortexFoundation/torrentfs/backend/api.go b/vendor/github.com/CortexFoundation/torrentfs/backend/api.go
new file mode 100644
index 0000000000..8570fb7dc0
--- /dev/null
+++ b/vendor/github.com/CortexFoundation/torrentfs/backend/api.go
@@ -0,0 +1,225 @@
+// Copyright 2023 The CortexTheseus Authors
+// This file is part of the CortexTheseus library.
+//
+// The CortexTheseus library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The CortexTheseus library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the CortexTheseus library. If not, see .
+
+package backend
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strings"
+ "time"
+
+ "github.com/CortexFoundation/CortexTheseus/common"
+ "github.com/CortexFoundation/CortexTheseus/log"
+ "github.com/CortexFoundation/torrentfs/params"
+)
+
+// can only call by fs.go: 'SeedingLocal()'
+func (tm *TorrentManager) AddLocalSeedFile(ih string) bool {
+ if !common.IsHexAddress(ih) {
+ return false
+ }
+ ih = strings.TrimPrefix(strings.ToLower(ih), common.Prefix)
+
+ if _, ok := params.GoodFiles[ih]; ok {
+ return false
+ }
+
+ tm.localSeedLock.Lock()
+ tm.localSeedFiles[ih] = true
+ tm.localSeedLock.Unlock()
+
+ return true
+}
+
+// only files in map:localSeedFile can be paused!
+func (tm *TorrentManager) PauseLocalSeedFile(ih string) error {
+ if !common.IsHexAddress(ih) {
+ return errors.New("invalid infohash format")
+ }
+ ih = strings.TrimPrefix(strings.ToLower(ih), common.Prefix)
+
+ tm.localSeedLock.Lock()
+ defer tm.localSeedLock.Unlock()
+
+ if valid, ok := tm.localSeedFiles[ih]; !ok {
+ return errors.New(fmt.Sprintf("Not Local Seeding File<%s>", ih))
+ } else if _, ok := params.GoodFiles[ih]; ok {
+ return errors.New(fmt.Sprintf("Cannot Pause On-Chain GoodFile<%s>", ih))
+ } else if !valid {
+ return errors.New(fmt.Sprintf("Local Seeding File Is Not Seeding<%s>", ih))
+ }
+
+ if t := tm.getTorrent(ih); t != nil {
+ log.Debug("TorrentFS", "from seed to pause", "ok")
+ t.Pause()
+ tm.localSeedFiles[ih] = !t.Paused()
+ }
+
+ return nil
+}
+
+// only files in map:localSeedFile can be resumed!
+func (tm *TorrentManager) ResumeLocalSeedFile(ih string) error {
+ if !common.IsHexAddress(ih) {
+ return errors.New("invalid infohash format")
+ }
+ ih = strings.TrimPrefix(strings.ToLower(ih), common.Prefix)
+
+ tm.localSeedLock.Lock()
+ defer tm.localSeedLock.Unlock()
+
+ if valid, ok := tm.localSeedFiles[ih]; !ok {
+ return errors.New(fmt.Sprintf("Not Local Seeding File<%s>", ih))
+ } else if _, ok := params.GoodFiles[ih]; ok {
+ return errors.New(fmt.Sprintf("Cannot Operate On-Chain GoodFile<%s>", ih))
+ } else if valid {
+ return errors.New(fmt.Sprintf("Local Seeding File Is Already Seeding<%s>", ih))
+ }
+
+ if t := tm.getTorrent(ih); t != nil {
+ resumeFlag := t.Seed()
+ log.Debug("TorrentFS", "from pause to seed", resumeFlag)
+ tm.localSeedFiles[ih] = resumeFlag
+ }
+
+ return nil
+}
+
+// divide localSeed/on-chain Files
+// return status of torrents
+func (tm *TorrentManager) ListAllTorrents() map[string]map[string]int {
+ tm.lock.RLock()
+ tm.localSeedLock.RLock()
+ defer tm.lock.RUnlock()
+ defer tm.localSeedLock.RUnlock()
+
+ tts := make(map[string]map[string]int, tm.torrents.Len())
+ /*for ih, tt := range tm.torrents {
+ tType := torrentTypeOnChain
+ if _, ok := tm.localSeedFiles[ih]; ok {
+ tType = torrentTypeLocal
+ }
+ tts[ih] = map[string]int{
+ "status": tt.Status(),
+ "type": tType,
+ }
+ }*/
+
+ tm.torrents.Range(func(ih string, tt *Torrent) bool {
+ tType := torrentTypeOnChain
+ if _, ok := tm.localSeedFiles[ih]; ok {
+ tType = torrentTypeLocal
+ }
+ tts[ih] = map[string]int{
+ "status": tt.Status(),
+ "type": tType,
+ }
+ return true
+ })
+
+ return tts
+}
+
+func (tm *TorrentManager) Metrics() time.Duration {
+ return tm.Updates
+}
+
+func (tm *TorrentManager) LocalPort() int {
+ return tm.client.LocalPort()
+}
+
+func (tm *TorrentManager) Congress() int {
+ return int(tm.seeds.Load()) //tm.seedingTorrents.Len()
+}
+
+func (tm *TorrentManager) Candidate() int {
+ return int(tm.actives.Load())
+}
+
+func (tm *TorrentManager) Nominee() int {
+ //return tm.pendingTorrents.Len()
+ return int(tm.pends.Load())
+}
+
+func (tm *TorrentManager) IsPending(ih string) bool {
+ //return tm.pendingTorrents[ih] != nil
+ //_, ok := tm.pendingTorrents.Get(ih)
+ //return ok
+ // return tm.pendingTorrents.Has(ih)
+ if t := tm.getTorrent(ih); t != nil {
+ return t.Status() == torrentPending
+ }
+ return false
+}
+
+func (tm *TorrentManager) IsDownloading(ih string) bool {
+ //return tm.activeTorrents[ih] != nil
+ //_, ok := tm.activeTorrents.Get(ih)
+ //return ok
+ //return tm.activeTorrents.Has(ih)
+ if t := tm.getTorrent(ih); t != nil {
+ return t.Status() == torrentRunning
+ }
+ return false
+}
+
+func (tm *TorrentManager) IsSeeding(ih string) bool {
+ //return tm.seedingTorrents[ih] != nil
+ //_, ok := tm.seedingTorrents.Get(ih)
+ //return ok
+ if t := tm.getTorrent(ih); t != nil {
+ return t.Status() == torrentSeeding
+ }
+ return false //tm.seedingTorrents.Has(ih)
+}
+
+/*func (tm *TorrentManager) GlobalTrackers() [][]string {
+ tm.lock.RLock()
+ defer tm.lock.RUnlock()
+
+ return tm.globalTrackers
+}*/
+
+// Search and donwload files from torrent
+func (tm *TorrentManager) Search(ctx context.Context, hex string, request uint64) error {
+ if !common.IsHexAddress(hex) {
+ return errors.New("invalid infohash format")
+ }
+
+ hex = strings.TrimPrefix(strings.ToLower(hex), common.Prefix)
+
+ if params.IsBad(hex) {
+ return nil
+ }
+
+ if request == 0x7fffffffffffffff {
+ // TODO 0x7fffffffffffffff local downloading file
+ // GoodFiles[hex] = false
+ }
+
+ //if tm.mode == params.FULL {
+ //if request == 0 {
+ // log.Warn("Prepare mode", "ih", hex)
+ // request = uint64(block)
+ //}
+ //}
+
+ downloadMeter.Mark(1)
+
+ return tm.commit(ctx, hex, request)
+}
diff --git a/vendor/github.com/CortexFoundation/torrentfs/backend/doc.go b/vendor/github.com/CortexFoundation/torrentfs/backend/doc.go
new file mode 100644
index 0000000000..0582a90a18
--- /dev/null
+++ b/vendor/github.com/CortexFoundation/torrentfs/backend/doc.go
@@ -0,0 +1,56 @@
+// Copyright 2023 The CortexTheseus Authors
+// This file is part of the CortexTheseus library.
+//
+// The CortexTheseus library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The CortexTheseus library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the CortexTheseus library. If not, see .
+
+package backend
+
+import (
+ "github.com/CortexFoundation/CortexTheseus/metrics"
+ "github.com/CortexFoundation/torrentfs/params"
+)
+
+const (
+ bucket = params.Bucket //it is best size is 1/3 full nodes
+ group = params.Group
+ taskChanBuffer = 1 //params.SyncBatch
+ torrentChanSize = 1
+
+ block = int64(params.PER_UPLOAD_BYTES)
+ //loops = 30
+
+ torrentTypeOnChain = 0
+ torrentTypeLocal = 1
+
+ TORRENT = "torrent"
+
+ SEED_PRE = "s-"
+)
+
+var (
+ server bool = false
+ enableWorm bool = false
+ getfileMeter = metrics.NewRegisteredMeter("torrent/getfile/call", nil)
+ availableMeter = metrics.NewRegisteredMeter("torrent/available/call", nil)
+ diskReadMeter = metrics.NewRegisteredMeter("torrent/disk/read", nil)
+
+ downloadMeter = metrics.NewRegisteredMeter("torrent/download/call", nil)
+ updateMeter = metrics.NewRegisteredMeter("torrent/update/call", nil)
+
+ memcacheHitMeter = metrics.NewRegisteredMeter("torrent/memcache/hit", nil)
+ memcacheReadMeter = metrics.NewRegisteredMeter("torrent/memcache/read", nil)
+
+ memcacheMissMeter = metrics.NewRegisteredMeter("torrent/memcache/miss", nil)
+ memcacheWriteMeter = metrics.NewRegisteredMeter("torrent/memcache/write", nil)
+)
diff --git a/vendor/github.com/CortexFoundation/torrentfs/backend/handler.go b/vendor/github.com/CortexFoundation/torrentfs/backend/handler.go
index d0c187475a..1e1e6feaef 100644
--- a/vendor/github.com/CortexFoundation/torrentfs/backend/handler.go
+++ b/vendor/github.com/CortexFoundation/torrentfs/backend/handler.go
@@ -30,7 +30,6 @@ import (
"path/filepath"
"runtime"
"strconv"
- "strings"
"sync"
"sync/atomic"
"time"
@@ -38,7 +37,6 @@ import (
"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/common/mclock"
"github.com/CortexFoundation/CortexTheseus/log"
- "github.com/CortexFoundation/CortexTheseus/metrics"
"github.com/CortexFoundation/torrentfs/compress"
"github.com/CortexFoundation/torrentfs/params"
//"github.com/CortexFoundation/torrentfs/shard"
@@ -74,40 +72,6 @@ import (
"github.com/ucwong/filecache"
)
-const (
- bucket = params.Bucket //it is best size is 1/3 full nodes
- group = params.Group
- taskChanBuffer = 1 //params.SyncBatch
- torrentChanSize = 1
-
- block = int64(params.PER_UPLOAD_BYTES)
- //loops = 30
-
- torrentTypeOnChain = 0
- torrentTypeLocal = 1
-
- TORRENT = "torrent"
-
- SEED_PRE = "s-"
-)
-
-var (
- server bool = false
- enableWorm bool = false
- getfileMeter = metrics.NewRegisteredMeter("torrent/getfile/call", nil)
- availableMeter = metrics.NewRegisteredMeter("torrent/available/call", nil)
- diskReadMeter = metrics.NewRegisteredMeter("torrent/disk/read", nil)
-
- downloadMeter = metrics.NewRegisteredMeter("torrent/download/call", nil)
- updateMeter = metrics.NewRegisteredMeter("torrent/update/call", nil)
-
- memcacheHitMeter = metrics.NewRegisteredMeter("torrent/memcache/hit", nil)
- memcacheReadMeter = metrics.NewRegisteredMeter("torrent/memcache/read", nil)
-
- memcacheMissMeter = metrics.NewRegisteredMeter("torrent/memcache/miss", nil)
- memcacheWriteMeter = metrics.NewRegisteredMeter("torrent/memcache/write", nil)
-)
-
type TorrentManager struct {
client *torrent.Client
//bytes map[metainfo.Hash]int64
@@ -182,113 +146,6 @@ type TorrentManager struct {
worm *wormhole.Wormhole
}
-// can only call by fs.go: 'SeedingLocal()'
-func (tm *TorrentManager) AddLocalSeedFile(ih string) bool {
- if !common.IsHexAddress(ih) {
- return false
- }
- ih = strings.TrimPrefix(strings.ToLower(ih), common.Prefix)
-
- if _, ok := params.GoodFiles[ih]; ok {
- return false
- }
-
- tm.localSeedLock.Lock()
- tm.localSeedFiles[ih] = true
- tm.localSeedLock.Unlock()
-
- return true
-}
-
-// only files in map:localSeedFile can be paused!
-func (tm *TorrentManager) PauseLocalSeedFile(ih string) error {
- if !common.IsHexAddress(ih) {
- return errors.New("invalid infohash format")
- }
- ih = strings.TrimPrefix(strings.ToLower(ih), common.Prefix)
-
- tm.localSeedLock.Lock()
- defer tm.localSeedLock.Unlock()
-
- if valid, ok := tm.localSeedFiles[ih]; !ok {
- return errors.New(fmt.Sprintf("Not Local Seeding File<%s>", ih))
- } else if _, ok := params.GoodFiles[ih]; ok {
- return errors.New(fmt.Sprintf("Cannot Pause On-Chain GoodFile<%s>", ih))
- } else if !valid {
- return errors.New(fmt.Sprintf("Local Seeding File Is Not Seeding<%s>", ih))
- }
-
- if t := tm.getTorrent(ih); t != nil {
- log.Debug("TorrentFS", "from seed to pause", "ok")
- t.Pause()
- tm.localSeedFiles[ih] = !t.Paused()
- }
-
- return nil
-}
-
-// only files in map:localSeedFile can be resumed!
-func (tm *TorrentManager) ResumeLocalSeedFile(ih string) error {
- if !common.IsHexAddress(ih) {
- return errors.New("invalid infohash format")
- }
- ih = strings.TrimPrefix(strings.ToLower(ih), common.Prefix)
-
- tm.localSeedLock.Lock()
- defer tm.localSeedLock.Unlock()
-
- if valid, ok := tm.localSeedFiles[ih]; !ok {
- return errors.New(fmt.Sprintf("Not Local Seeding File<%s>", ih))
- } else if _, ok := params.GoodFiles[ih]; ok {
- return errors.New(fmt.Sprintf("Cannot Operate On-Chain GoodFile<%s>", ih))
- } else if valid {
- return errors.New(fmt.Sprintf("Local Seeding File Is Already Seeding<%s>", ih))
- }
-
- if t := tm.getTorrent(ih); t != nil {
- resumeFlag := t.Seed()
- log.Debug("TorrentFS", "from pause to seed", resumeFlag)
- tm.localSeedFiles[ih] = resumeFlag
- }
-
- return nil
-}
-
-// divide localSeed/on-chain Files
-// return status of torrents
-func (tm *TorrentManager) ListAllTorrents() map[string]map[string]int {
- tm.lock.RLock()
- tm.localSeedLock.RLock()
- defer tm.lock.RUnlock()
- defer tm.localSeedLock.RUnlock()
-
- tts := make(map[string]map[string]int, tm.torrents.Len())
- /*for ih, tt := range tm.torrents {
- tType := torrentTypeOnChain
- if _, ok := tm.localSeedFiles[ih]; ok {
- tType = torrentTypeLocal
- }
- tts[ih] = map[string]int{
- "status": tt.Status(),
- "type": tType,
- }
- }*/
-
- tm.torrents.Range(func(ih string, tt *Torrent) bool {
- tType := torrentTypeOnChain
- if _, ok := tm.localSeedFiles[ih]; ok {
- tType = torrentTypeLocal
- }
- tts[ih] = map[string]int{
- "status": tt.Status(),
- "type": tType,
- }
- return true
- })
-
- return tts
-}
-
func (tm *TorrentManager) getLimitation(value int64) int64 {
return ((value + block - 1) / block) * block
}
@@ -757,13 +614,6 @@ func (tm *TorrentManager) ColaList() mapset.Set[string] {
return tm.colaList
}*/
-func (tm *TorrentManager) GlobalTrackers() [][]string {
- tm.lock.RLock()
- defer tm.lock.RUnlock()
-
- return tm.globalTrackers
-}
-
func (tm *TorrentManager) updateInfoHash(t *Torrent, bytesRequested int64) {
if t.Status() != torrentSeeding {
if t.BytesRequested() < bytesRequested {
@@ -1058,35 +908,6 @@ func (tm *TorrentManager) init() error {
log.Info("Do simulate")
}*/
-// Search and donwload files from torrent
-func (tm *TorrentManager) Search(ctx context.Context, hex string, request uint64) error {
- if !common.IsHexAddress(hex) {
- return errors.New("invalid infohash format")
- }
-
- hex = strings.TrimPrefix(strings.ToLower(hex), common.Prefix)
-
- if params.IsBad(hex) {
- return nil
- }
-
- if request == 0x7fffffffffffffff {
- // TODO 0x7fffffffffffffff local downloading file
- // GoodFiles[hex] = false
- }
-
- //if tm.mode == params.FULL {
- //if request == 0 {
- // log.Warn("Prepare mode", "ih", hex)
- // request = uint64(block)
- //}
- //}
-
- downloadMeter.Mark(1)
-
- return tm.commit(ctx, hex, request)
-}
-
func (tm *TorrentManager) commit(ctx context.Context, hex string, request uint64) error {
select {
case tm.taskChan <- types.NewBitsFlow(hex, request):
@@ -1555,56 +1376,3 @@ func (tm *TorrentManager) zip(data []byte) ([]byte, error) {
}
return data, nil
}
-
-func (tm *TorrentManager) Metrics() time.Duration {
- return tm.Updates
-}
-
-func (tm *TorrentManager) LocalPort() int {
- return tm.client.LocalPort()
-}
-
-func (tm *TorrentManager) Congress() int {
- return int(tm.seeds.Load()) //tm.seedingTorrents.Len()
-}
-
-func (tm *TorrentManager) Candidate() int {
- return int(tm.actives.Load())
-}
-
-func (tm *TorrentManager) Nominee() int {
- //return tm.pendingTorrents.Len()
- return int(tm.pends.Load())
-}
-
-func (tm *TorrentManager) IsPending(ih string) bool {
- //return tm.pendingTorrents[ih] != nil
- //_, ok := tm.pendingTorrents.Get(ih)
- //return ok
- // return tm.pendingTorrents.Has(ih)
- if t := tm.getTorrent(ih); t != nil {
- return t.Status() == torrentPending
- }
- return false
-}
-
-func (tm *TorrentManager) IsDownloading(ih string) bool {
- //return tm.activeTorrents[ih] != nil
- //_, ok := tm.activeTorrents.Get(ih)
- //return ok
- //return tm.activeTorrents.Has(ih)
- if t := tm.getTorrent(ih); t != nil {
- return t.Status() == torrentRunning
- }
- return false
-}
-
-func (tm *TorrentManager) IsSeeding(ih string) bool {
- //return tm.seedingTorrents[ih] != nil
- //_, ok := tm.seedingTorrents.Get(ih)
- //return ok
- if t := tm.getTorrent(ih); t != nil {
- return t.Status() == torrentSeeding
- }
- return false //tm.seedingTorrents.Has(ih)
-}
diff --git a/vendor/github.com/CortexFoundation/torrentfs/backend/t.go b/vendor/github.com/CortexFoundation/torrentfs/backend/t.go
new file mode 100644
index 0000000000..9d6bda576f
--- /dev/null
+++ b/vendor/github.com/CortexFoundation/torrentfs/backend/t.go
@@ -0,0 +1,308 @@
+// Copyright 2023 The CortexTheseus Authors
+// This file is part of the CortexTheseus library.
+//
+// The CortexTheseus library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The CortexTheseus library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the CortexTheseus library. If not, see .
+
+package backend
+
+import (
+ "errors"
+ "os"
+ "path/filepath"
+ "time"
+
+ "github.com/CortexFoundation/CortexTheseus/common"
+ "github.com/CortexFoundation/CortexTheseus/common/mclock"
+ "github.com/CortexFoundation/CortexTheseus/log"
+ "github.com/anacrolix/torrent"
+ //"github.com/anacrolix/torrent/metainfo"
+ //"github.com/anacrolix/torrent/storage"
+ "github.com/CortexFoundation/torrentfs/params"
+)
+
+func (t *Torrent) QuotaFull() bool {
+ //t.RLock()
+ //defer t.RUnlock()
+
+ return t.Info() != nil && t.bytesRequested.Load() >= t.Length()
+}
+
+func (t *Torrent) Spec() *torrent.TorrentSpec {
+ return t.spec
+}
+
+func (t *Torrent) Birth() mclock.AbsTime {
+ return t.start
+}
+
+func (t *Torrent) Lock() {
+ t.lock.Lock()
+}
+
+func (t *Torrent) Unlock() {
+ t.lock.Unlock()
+}
+
+func (t *Torrent) RLock() {
+ t.lock.RLock()
+}
+
+func (t *Torrent) RUnlock() {
+ t.lock.RUnlock()
+}
+
+/*func (t *Torrent) BytesLeft() int64 {
+ if t.bytesRequested < t.bytesCompleted {
+ return 0
+ }
+ return t.bytesRequested - t.bytesCompleted
+}*/
+
+func (t *Torrent) InfoHash() string {
+ return t.infohash
+}
+
+func (t *Torrent) Status() int {
+ return int(t.status.Load())
+}
+
+func (t *Torrent) Cited() int32 {
+ return t.cited.Load()
+}
+
+func (t *Torrent) CitedInc() {
+ t.cited.Add(1)
+}
+
+func (t *Torrent) CitedDec() {
+ t.cited.Add(-1)
+}
+
+func (t *Torrent) BytesRequested() int64 {
+ return t.bytesRequested.Load()
+}
+
+func (t *Torrent) SetBytesRequested(bytesRequested int64) {
+ //t.Lock()
+ //defer t.Unlock()
+ //t.bytesRequested = bytesRequested
+ t.bytesRequested.Store(bytesRequested)
+}
+
+func (t *Torrent) Ready() bool {
+ if _, ok := params.BadFiles[t.InfoHash()]; ok {
+ return false
+ }
+
+ ret := t.IsSeeding()
+ if !ret {
+ //log.Debug("Not ready", "ih", t.InfoHash(), "status", t.status, "seed", t.Torrent.Seeding(), "seeding", torrentSeeding)
+ }
+
+ return ret
+}
+
+func (t *Torrent) Seed() bool {
+ //t.lock.Lock()
+ //defer t.lock.Unlock()
+
+ if t.Torrent.Info() == nil {
+ log.Debug("Nas info is nil", "ih", t.InfoHash())
+ return false
+ }
+ if t.status.Load() == torrentSeeding {
+ //log.Debug("Nas status is", "status", t.status, "ih", t.InfoHash())
+ return true
+ }
+ //if t.currentConns <= t.minEstablishedConns {
+ //t.setCurrentConns(t.maxEstablishedConns)
+ //t.Torrent.SetMaxEstablishedConns(t.currentConns)
+ //}
+ if t.Torrent.Seeding() {
+ //t.Lock()
+ //defer t.Unlock()
+
+ //t.status = torrentSeeding
+ t.status.Store(torrentSeeding)
+ t.stopListen()
+
+ elapsed := time.Duration(mclock.Now()) - time.Duration(t.start)
+ //if active, ok := params.GoodFiles[t.InfoHash()]; !ok {
+ // log.Info("New active nas found", "ih", t.InfoHash(), "ok", ok, "active", active, "size", common.StorageSize(t.BytesCompleted()), "files", len(t.Files()), "pieces", t.Torrent.NumPieces(), "seg", len(t.Torrent.PieceStateRuns()), "peers", t.currentConns, "status", t.status, "elapsed", common.PrettyDuration(elapsed))
+ //} else {
+ log.Info("Imported new nas segment", "ih", t.InfoHash(), "size", common.StorageSize(t.Torrent.BytesCompleted()), "files", len(t.Files()), "pieces", t.Torrent.NumPieces(), "seg", len(t.Torrent.PieceStateRuns()), "status", t.status.Load(), "elapsed", common.PrettyDuration(elapsed), "speed", common.StorageSize(float64(t.Torrent.BytesCompleted()*1000*1000*1000)/float64(elapsed)).String()+"/s")
+ //}
+
+ return true
+ }
+
+ return false
+}
+
+func (t *Torrent) IsSeeding() bool {
+ //t.RLock()
+ //defer t.RUnlock()
+
+ return t.status.Load() == torrentSeeding // && t.Torrent.Seeding()
+}
+
+func (t *Torrent) Pause() {
+ //t.Lock()
+ //defer t.Unlock()
+ //if t.currentConns > t.minEstablishedConns {
+ //t.setCurrentConns(t.minEstablishedConns)
+ //t.Torrent.SetMaxEstablishedConns(t.minEstablishedConns)
+ //}
+ if t.status.Load() != torrentPaused {
+ //t.status = torrentPaused
+ t.status.Store(torrentPaused)
+ //t.maxPieces = 0 //t.minEstablishedConns
+ t.maxPieces.Store(0)
+ t.Torrent.CancelPieces(0, t.Torrent.NumPieces())
+ }
+}
+
+func (t *Torrent) Paused() bool {
+ //t.RLock()
+ //defer t.RUnlock()
+
+ return t.status.Load() == torrentPaused
+}
+
+func (t *Torrent) Leech() error {
+ // Make sure the torrent info exists
+ if t.Torrent.Info() == nil {
+ return errors.New("info is nil")
+ }
+
+ if t.status.Load() != torrentRunning {
+ return errors.New("nas is not running")
+ }
+
+ if t.Torrent.BytesMissing() == 0 {
+ return nil
+ }
+
+ limitPieces := int((t.bytesRequested.Load()*int64(t.Torrent.NumPieces()) + t.Length() - 1) / t.Length())
+ if limitPieces > t.Torrent.NumPieces() {
+ limitPieces = t.Torrent.NumPieces()
+ }
+
+ //t.Lock()
+ //defer t.Unlock()
+
+ if limitPieces > int(t.maxPieces.Load()) {
+ if err := t.download(limitPieces); err == nil {
+ //t.maxPieces = limitPieces
+ t.maxPieces.Store(int32(limitPieces))
+ } else {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func (t *Torrent) Running() bool {
+ //t.RLock()
+ //defer t.RUnlock()
+
+ return t.status.Load() == torrentRunning
+}
+
+func (t *Torrent) Pending() bool {
+ //t.RLock()
+ //defer t.RUnlock()
+
+ return t.status.Load() == torrentPending
+}
+
+func (t *Torrent) Stopping() bool {
+ //t.RLock()
+ //defer t.RUnlock()
+
+ return t.status.Load() == torrentStopping
+}
+
+func (t *Torrent) Start() error {
+ if !t.run() {
+ return errors.New("nas run failed")
+ }
+
+ t.startOnce.Do(func() {
+ t.wg.Add(1)
+ go t.listen()
+ })
+ return nil
+}
+
+func (t *Torrent) Stop() {
+ t.Lock()
+ defer t.Unlock()
+
+ defer t.Torrent.Drop()
+
+ if t.Status() != torrentStopping {
+ log.Debug(ProgressBar(t.BytesCompleted(), t.Torrent.Length(), ""), "ih", t.InfoHash(), "total", common.StorageSize(t.Torrent.Length()), "req", common.StorageSize(t.BytesRequested()), "finish", common.StorageSize(t.Torrent.BytesCompleted()), "status", t.Status(), "cited", t.Cited())
+ //t.status = torrentStopping
+ t.status.Store(torrentStopping)
+ }
+}
+
+func (t *Torrent) stopListen() {
+ t.stopOnce.Do(func() {
+ t.Lock()
+ defer t.Unlock()
+
+ close(t.closeAll)
+ t.wg.Wait()
+
+ t.taskCh = nil
+
+ log.Debug("Nas listener stopped", "ih", t.InfoHash(), "status", t.Status())
+ })
+}
+
+func (t *Torrent) Close() {
+ t.Lock()
+ defer t.Unlock()
+
+ defer t.Torrent.Drop()
+
+ log.Info("Nas closed", "ih", t.InfoHash(), "total", common.StorageSize(t.Torrent.Length()), "req", common.StorageSize(t.BytesRequested()), "finish", common.StorageSize(t.Torrent.BytesCompleted()), "status", t.Status(), "cited", t.Cited())
+ t = nil
+}
+
+func (t *Torrent) WriteTorrent() error {
+ t.Lock()
+ defer t.Unlock()
+ if _, err := os.Stat(filepath.Join(t.filepath, TORRENT)); err == nil {
+ //t.Pause()
+ return nil
+ }
+
+ if f, err := os.OpenFile(filepath.Join(t.filepath, TORRENT), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0777); err == nil {
+ defer f.Close()
+ log.Debug("Write seed file", "path", t.filepath)
+ if err := t.Metainfo().Write(f); err != nil {
+ log.Warn("Write seed error", "err", err)
+ return err
+ }
+ } else {
+ log.Warn("Create Path error", "err", err)
+ return err
+ }
+
+ return nil
+}
diff --git a/vendor/github.com/CortexFoundation/torrentfs/backend/torrent.go b/vendor/github.com/CortexFoundation/torrentfs/backend/torrent.go
index 405e533860..e533a382ad 100644
--- a/vendor/github.com/CortexFoundation/torrentfs/backend/torrent.go
+++ b/vendor/github.com/CortexFoundation/torrentfs/backend/torrent.go
@@ -17,23 +17,15 @@
package backend
import (
- "errors"
- //"bytes"
- //"context"
"context"
- "os"
- "path/filepath"
+ "errors"
"sync"
"sync/atomic"
"time"
- "github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/common/mclock"
"github.com/CortexFoundation/CortexTheseus/log"
"github.com/anacrolix/torrent"
- //"github.com/anacrolix/torrent/metainfo"
- //"github.com/anacrolix/torrent/storage"
- "github.com/CortexFoundation/torrentfs/params"
)
const (
@@ -105,216 +97,6 @@ func NewTorrent(t *torrent.Torrent, requested int64, ih string, path string, slo
return &tor
}
-func (t *Torrent) QuotaFull() bool {
- //t.RLock()
- //defer t.RUnlock()
-
- return t.Info() != nil && t.bytesRequested.Load() >= t.Length()
-}
-
-func (t *Torrent) Spec() *torrent.TorrentSpec {
- return t.spec
-}
-
-func (t *Torrent) Birth() mclock.AbsTime {
- return t.start
-}
-
-func (t *Torrent) Lock() {
- t.lock.Lock()
-}
-
-func (t *Torrent) Unlock() {
- t.lock.Unlock()
-}
-
-func (t *Torrent) RLock() {
- t.lock.RLock()
-}
-
-func (t *Torrent) RUnlock() {
- t.lock.RUnlock()
-}
-
-/*func (t *Torrent) BytesLeft() int64 {
- if t.bytesRequested < t.bytesCompleted {
- return 0
- }
- return t.bytesRequested - t.bytesCompleted
-}*/
-
-func (t *Torrent) InfoHash() string {
- return t.infohash
-}
-
-func (t *Torrent) Status() int {
- return int(t.status.Load())
-}
-
-func (t *Torrent) Cited() int32 {
- return t.cited.Load()
-}
-
-func (t *Torrent) CitedInc() {
- t.cited.Add(1)
-}
-
-func (t *Torrent) CitedDec() {
- t.cited.Add(-1)
-}
-
-func (t *Torrent) BytesRequested() int64 {
- return t.bytesRequested.Load()
-}
-
-func (t *Torrent) SetBytesRequested(bytesRequested int64) {
- //t.Lock()
- //defer t.Unlock()
- //t.bytesRequested = bytesRequested
- t.bytesRequested.Store(bytesRequested)
-}
-
-func (t *Torrent) Ready() bool {
- if _, ok := params.BadFiles[t.InfoHash()]; ok {
- return false
- }
-
- ret := t.IsSeeding()
- if !ret {
- //log.Debug("Not ready", "ih", t.InfoHash(), "status", t.status, "seed", t.Torrent.Seeding(), "seeding", torrentSeeding)
- }
-
- return ret
-}
-
-func (t *Torrent) WriteTorrent() error {
- t.Lock()
- defer t.Unlock()
- if _, err := os.Stat(filepath.Join(t.filepath, TORRENT)); err == nil {
- //t.Pause()
- return nil
- }
-
- if f, err := os.OpenFile(filepath.Join(t.filepath, TORRENT), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0777); err == nil {
- defer f.Close()
- log.Debug("Write seed file", "path", t.filepath)
- if err := t.Metainfo().Write(f); err != nil {
- log.Warn("Write seed error", "err", err)
- return err
- }
- } else {
- log.Warn("Create Path error", "err", err)
- return err
- }
-
- return nil
-}
-
-//func (t *Torrent) BoostOff() {
-//t.isBoosting = false
-//}
-
-func (t *Torrent) Seed() bool {
- //t.lock.Lock()
- //defer t.lock.Unlock()
-
- if t.Torrent.Info() == nil {
- log.Debug("Nas info is nil", "ih", t.InfoHash())
- return false
- }
- if t.status.Load() == torrentSeeding {
- //log.Debug("Nas status is", "status", t.status, "ih", t.InfoHash())
- return true
- }
- //if t.currentConns <= t.minEstablishedConns {
- //t.setCurrentConns(t.maxEstablishedConns)
- //t.Torrent.SetMaxEstablishedConns(t.currentConns)
- //}
- if t.Torrent.Seeding() {
- //t.Lock()
- //defer t.Unlock()
-
- //t.status = torrentSeeding
- t.status.Store(torrentSeeding)
- t.stopListen()
-
- elapsed := time.Duration(mclock.Now()) - time.Duration(t.start)
- //if active, ok := params.GoodFiles[t.InfoHash()]; !ok {
- // log.Info("New active nas found", "ih", t.InfoHash(), "ok", ok, "active", active, "size", common.StorageSize(t.BytesCompleted()), "files", len(t.Files()), "pieces", t.Torrent.NumPieces(), "seg", len(t.Torrent.PieceStateRuns()), "peers", t.currentConns, "status", t.status, "elapsed", common.PrettyDuration(elapsed))
- //} else {
- log.Info("Imported new nas segment", "ih", t.InfoHash(), "size", common.StorageSize(t.Torrent.BytesCompleted()), "files", len(t.Files()), "pieces", t.Torrent.NumPieces(), "seg", len(t.Torrent.PieceStateRuns()), "status", t.status.Load(), "elapsed", common.PrettyDuration(elapsed), "speed", common.StorageSize(float64(t.Torrent.BytesCompleted()*1000*1000*1000)/float64(elapsed)).String()+"/s")
- //}
-
- return true
- }
-
- return false
-}
-
-func (t *Torrent) IsSeeding() bool {
- //t.RLock()
- //defer t.RUnlock()
-
- return t.status.Load() == torrentSeeding // && t.Torrent.Seeding()
-}
-
-func (t *Torrent) Pause() {
- //t.Lock()
- //defer t.Unlock()
- //if t.currentConns > t.minEstablishedConns {
- //t.setCurrentConns(t.minEstablishedConns)
- //t.Torrent.SetMaxEstablishedConns(t.minEstablishedConns)
- //}
- if t.status.Load() != torrentPaused {
- //t.status = torrentPaused
- t.status.Store(torrentPaused)
- //t.maxPieces = 0 //t.minEstablishedConns
- t.maxPieces.Store(0)
- t.Torrent.CancelPieces(0, t.Torrent.NumPieces())
- }
-}
-
-func (t *Torrent) Paused() bool {
- //t.RLock()
- //defer t.RUnlock()
-
- return t.status.Load() == torrentPaused
-}
-
-func (t *Torrent) Leech() error {
- // Make sure the torrent info exists
- if t.Torrent.Info() == nil {
- return errors.New("info is nil")
- }
-
- if t.status.Load() != torrentRunning {
- return errors.New("nas is not running")
- }
-
- if t.Torrent.BytesMissing() == 0 {
- return nil
- }
-
- limitPieces := int((t.bytesRequested.Load()*int64(t.Torrent.NumPieces()) + t.Length() - 1) / t.Length())
- if limitPieces > t.Torrent.NumPieces() {
- limitPieces = t.Torrent.NumPieces()
- }
-
- //t.Lock()
- //defer t.Unlock()
-
- if limitPieces > int(t.maxPieces.Load()) {
- if err := t.download(limitPieces); err == nil {
- //t.maxPieces = limitPieces
- t.maxPieces.Store(int32(limitPieces))
- } else {
- return err
- }
- }
-
- return nil
-}
-
// Find out the start and end
func (t *Torrent) download(p int) error {
var s, e int
@@ -376,73 +158,3 @@ func (t *Torrent) listen() {
}
}
}
-
-func (t *Torrent) Running() bool {
- //t.RLock()
- //defer t.RUnlock()
-
- return t.status.Load() == torrentRunning
-}
-
-func (t *Torrent) Pending() bool {
- //t.RLock()
- //defer t.RUnlock()
-
- return t.status.Load() == torrentPending
-}
-
-func (t *Torrent) Stopping() bool {
- //t.RLock()
- //defer t.RUnlock()
-
- return t.status.Load() == torrentStopping
-}
-
-func (t *Torrent) Start() error {
- if !t.run() {
- return errors.New("nas run failed")
- }
-
- t.startOnce.Do(func() {
- t.wg.Add(1)
- go t.listen()
- })
- return nil
-}
-
-func (t *Torrent) Stop() {
- t.Lock()
- defer t.Unlock()
-
- defer t.Torrent.Drop()
-
- if t.Status() != torrentStopping {
- log.Debug(ProgressBar(t.BytesCompleted(), t.Torrent.Length(), ""), "ih", t.InfoHash(), "total", common.StorageSize(t.Torrent.Length()), "req", common.StorageSize(t.BytesRequested()), "finish", common.StorageSize(t.Torrent.BytesCompleted()), "status", t.Status(), "cited", t.Cited())
- //t.status = torrentStopping
- t.status.Store(torrentStopping)
- }
-}
-
-func (t *Torrent) stopListen() {
- t.stopOnce.Do(func() {
- t.Lock()
- defer t.Unlock()
-
- close(t.closeAll)
- t.wg.Wait()
-
- t.taskCh = nil
-
- log.Debug("Nas listener stopped", "ih", t.InfoHash(), "status", t.Status())
- })
-}
-
-func (t *Torrent) Close() {
- t.Lock()
- defer t.Unlock()
-
- defer t.Torrent.Drop()
-
- log.Info("Nas closed", "ih", t.InfoHash(), "total", common.StorageSize(t.Torrent.Length()), "req", common.StorageSize(t.BytesRequested()), "finish", common.StorageSize(t.Torrent.BytesCompleted()), "status", t.Status(), "cited", t.Cited())
- t = nil
-}
diff --git a/vendor/github.com/CortexFoundation/torrentfs/file.go b/vendor/github.com/CortexFoundation/torrentfs/file.go
index ac4764674d..b31eda36d5 100644
--- a/vendor/github.com/CortexFoundation/torrentfs/file.go
+++ b/vendor/github.com/CortexFoundation/torrentfs/file.go
@@ -254,31 +254,6 @@ func (fs *TorrentFS) Drop(ih string) error {
return nil
}
-// Download is used to download file with request, broadcast when not found locally
-func (fs *TorrentFS) download(ctx context.Context, ih string, request uint64) error {
- ih = strings.ToLower(ih)
- _, p, err := fs.monitor.DB().SetTorrentProgress(ih, request)
- if err != nil {
- return err
- }
- if exist, _, _, _ := fs.storage().ExistsOrActive(ctx, ih, request); !exist {
- fs.wg.Add(1)
- go func(ih string, p uint64) {
- defer fs.wg.Done()
- s := fs.broadcast(ih, p)
- if s {
- log.Debug("Nas "+params.ProtocolVersionStr+" tunnel", "ih", ih, "request", common.StorageSize(float64(p)), "tunnel", fs.tunnel.Len(), "peers", fs.Neighbors())
- }
- }(ih, p)
- }
- // local search
- if err := fs.storage().Search(ctx, ih, p); err != nil {
- return err
- }
-
- return nil
-}
-
func (fs *TorrentFS) Download(ctx context.Context, ih string, request uint64) error {
return fs.bitsflow(ctx, ih, request)
//return fs.download(ctx, ih, request)
@@ -323,22 +298,3 @@ func (fs *TorrentFS) Nominee() int {
func (fs *TorrentFS) IsActive(err error) bool {
return !errors.Is(err, backend.ErrInactiveTorrent)
}
-
-// Available is used to check the file status
-func (fs *TorrentFS) wakeup(ctx context.Context, ih string) error {
- if p, e := fs.progress(ih); e == nil {
- return fs.storage().Search(ctx, ih, p)
- } else {
- return e
- }
-}
-
-func (fs *TorrentFS) encounter(ih string) {
- if !fs.worm.Contains(ih) {
- fs.worm.Add(ih)
- }
-}
-
-func (fs *TorrentFS) progress(ih string) (uint64, error) {
- return fs.monitor.DB().GetTorrentProgress(ih)
-}
diff --git a/vendor/github.com/CortexFoundation/torrentfs/fs.go b/vendor/github.com/CortexFoundation/torrentfs/fs.go
index 95f505c606..bc7beab8bb 100644
--- a/vendor/github.com/CortexFoundation/torrentfs/fs.go
+++ b/vendor/github.com/CortexFoundation/torrentfs/fs.go
@@ -85,10 +85,6 @@ func (t *TorrentFS) storage() *backend.TorrentManager {
return t.handler
}
-/*func (t *TorrentFS) chain() *backend.ChainDB {
- return t.db
-}*/
-
var (
inst *TorrentFS = nil
mut sync.RWMutex
diff --git a/vendor/github.com/CortexFoundation/torrentfs/infohash.go b/vendor/github.com/CortexFoundation/torrentfs/infohash.go
new file mode 100644
index 0000000000..d3ba85b570
--- /dev/null
+++ b/vendor/github.com/CortexFoundation/torrentfs/infohash.go
@@ -0,0 +1,113 @@
+// Copyright 2023 The CortexTheseus Authors
+// This file is part of the CortexTheseus library.
+//
+// The CortexTheseus library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The CortexTheseus library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the CortexTheseus library. If not, see
+
+package torrentfs
+
+import (
+ "context"
+ "strings"
+ "time"
+
+ "github.com/CortexFoundation/CortexTheseus/common"
+ "github.com/CortexFoundation/CortexTheseus/log"
+ "github.com/CortexFoundation/torrentfs/params"
+ "github.com/ucwong/go-ttlmap"
+)
+
+// Available is used to check the file status
+func (fs *TorrentFS) wakeup(ctx context.Context, ih string) error {
+ if p, e := fs.progress(ih); e == nil {
+ return fs.storage().Search(ctx, ih, p)
+ } else {
+ return e
+ }
+}
+
+func (fs *TorrentFS) encounter(ih string) {
+ if !fs.worm.Contains(ih) {
+ fs.worm.Add(ih)
+ }
+}
+
+func (fs *TorrentFS) progress(ih string) (uint64, error) {
+ return fs.monitor.DB().GetTorrentProgress(ih)
+}
+
+// Download is used to download file with request, broadcast when not found locally
+func (fs *TorrentFS) download(ctx context.Context, ih string, request uint64) error {
+ ih = strings.ToLower(ih)
+ _, p, err := fs.monitor.DB().SetTorrentProgress(ih, request)
+ if err != nil {
+ return err
+ }
+ if exist, _, _, _ := fs.storage().ExistsOrActive(ctx, ih, request); !exist {
+ fs.wg.Add(1)
+ go func(ih string, p uint64) {
+ defer fs.wg.Done()
+ s := fs.broadcast(ih, p)
+ if s {
+ log.Debug("Nas "+params.ProtocolVersionStr+" tunnel", "ih", ih, "request", common.StorageSize(float64(p)), "tunnel", fs.tunnel.Len(), "peers", fs.Neighbors())
+ }
+ }(ih, p)
+ }
+ // local search
+ if err := fs.storage().Search(ctx, ih, p); err != nil {
+ return err
+ }
+
+ return nil
+}
+
+func (fs *TorrentFS) collapse(ih string, rawSize uint64) bool {
+ if s, err := fs.tunnel.Get(ih); err == nil && s.Value().(uint64) >= rawSize {
+ return true
+ }
+
+ return false
+}
+
+func (fs *TorrentFS) traverse(ih string, rawSize uint64) error {
+ if err := fs.tunnel.Set(ih, ttlmap.NewItem(rawSize, ttlmap.WithTTL(60*time.Second)), nil); err == nil {
+ log.Trace("Wormhole traverse", "ih", ih, "size", common.StorageSize(rawSize))
+ } else {
+ return err
+ }
+ return nil
+}
+
+func (fs *TorrentFS) broadcast(ih string, rawSize uint64) bool {
+ if !common.IsHexAddress(ih) {
+ return false
+ }
+
+ //if s, err := fs.tunnel.Get(ih); err == nil && s.Value().(uint64) >= rawSize {
+ if fs.collapse(ih, rawSize) {
+ return false
+ }
+
+ //fs.tunnel.Set(ih, ttlmap.NewItem(rawSize, ttlmap.WithTTL(60*time.Second)), nil)
+ if err := fs.traverse(ih, rawSize); err != nil {
+ return false
+ }
+
+ return true
+}
+
+func (fs *TorrentFS) record(id string) {
+ if !fs.history.Contains(id) {
+ fs.history.Add(id)
+ }
+}
diff --git a/vendor/github.com/CortexFoundation/torrentfs/neighbors.go b/vendor/github.com/CortexFoundation/torrentfs/neighbors.go
index 5a80c8e8d3..ba46d27307 100644
--- a/vendor/github.com/CortexFoundation/torrentfs/neighbors.go
+++ b/vendor/github.com/CortexFoundation/torrentfs/neighbors.go
@@ -19,13 +19,11 @@ package torrentfs
import (
"context"
"errors"
- "time"
"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/log"
"github.com/CortexFoundation/CortexTheseus/p2p"
"github.com/CortexFoundation/torrentfs/params"
-
"github.com/ucwong/go-ttlmap"
)
@@ -33,19 +31,6 @@ func (fs *TorrentFS) MaxMessageSize() uint32 {
return params.DefaultMaxMessageSize
}
-/*func (fs *TorrentFS) find(ih string) (*Peer, error) {
- for s, p := range fs.peers {
- if p.seeding.Contains(ih) {
- // TODO
- log.Debug("Seed found !!!", "from", s, "ih", ih)
- return p, nil
- }
- }
-
- log.Debug("Seed not found !!!", "neighbors", len(fs.peers), "ih", ih)
- return nil, nil
-}*/
-
func (fs *TorrentFS) HandlePeer(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
//tfsPeer := newPeer(fmt.Sprintf("%x", peer.ID().Bytes()[:8]), fs, peer, rw)
tfsPeer := newPeer(peer.ID().String(), fs, peer, rw)
@@ -118,10 +103,12 @@ func (fs *TorrentFS) handleMsg(p *Peer) error {
return errors.New("invalid address")
}
+ // already in
if ok := fs.collapse(info.Hash, info.Size); ok {
return nil
}
+ // wake up service
if err := fs.wakeup(context.Background(), info.Hash); err == nil {
if err := fs.traverse(info.Hash, info.Size); err == nil {
fs.received.Add(1)
@@ -147,39 +134,12 @@ func (fs *TorrentFS) handleMsg(p *Peer) error {
return nil
}
-func (fs *TorrentFS) collapse(ih string, rawSize uint64) bool {
- if s, err := fs.tunnel.Get(ih); err == nil && s.Value().(uint64) >= rawSize {
- return true
- }
-
- return false
-}
-
-func (fs *TorrentFS) traverse(ih string, rawSize uint64) error {
- if err := fs.tunnel.Set(ih, ttlmap.NewItem(rawSize, ttlmap.WithTTL(60*time.Second)), nil); err == nil {
- log.Trace("Wormhole traverse", "ih", ih, "size", common.StorageSize(rawSize))
- } else {
- return err
- }
- return nil
-}
-
-func (fs *TorrentFS) broadcast(ih string, rawSize uint64) bool {
- if !common.IsHexAddress(ih) {
- return false
- }
-
- //if s, err := fs.tunnel.Get(ih); err == nil && s.Value().(uint64) >= rawSize {
- if fs.collapse(ih, rawSize) {
- return false
- }
-
- //fs.tunnel.Set(ih, ttlmap.NewItem(rawSize, ttlmap.WithTTL(60*time.Second)), nil)
- if err := fs.traverse(ih, rawSize); err != nil {
- return false
+func (fs *TorrentFS) Neighbors() int {
+ if fs.net != nil {
+ return fs.net.PeerCount()
}
- return true
+ return len(fs.peers)
}
func (fs *TorrentFS) Envelopes() *ttlmap.Map {
@@ -188,17 +148,3 @@ func (fs *TorrentFS) Envelopes() *ttlmap.Map {
return fs.tunnel
}
-
-func (fs *TorrentFS) Neighbors() int {
- if fs.net != nil {
- return fs.net.PeerCount()
- }
-
- return len(fs.peers)
-}
-
-func (fs *TorrentFS) record(id string) {
- if !fs.history.Contains(id) {
- fs.history.Add(id)
- }
-}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index dd12ad34d8..70a4c687e6 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -43,7 +43,7 @@ github.com/CortexFoundation/robot/backend
# github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
## explicit; go 1.16
github.com/CortexFoundation/statik
-# github.com/CortexFoundation/torrentfs v1.0.55-0.20231007121016-6eb55dfda9e1
+# github.com/CortexFoundation/torrentfs v1.0.55-0.20231009075214-e36a3a83f0a7
## explicit; go 1.21
github.com/CortexFoundation/torrentfs
github.com/CortexFoundation/torrentfs/backend