mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-21 22:46:09 +05:00
init 1.2.x
This commit is contained in:
@@ -1 +0,0 @@
|
||||
package filecache
|
||||
@@ -1,69 +0,0 @@
|
||||
package filecache
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"server/settings"
|
||||
"server/torr/storage"
|
||||
"server/torr/storage/state"
|
||||
|
||||
"github.com/anacrolix/missinggo/filecache"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
storage2 "github.com/anacrolix/torrent/storage"
|
||||
)
|
||||
|
||||
type Storage struct {
|
||||
storage.Storage
|
||||
|
||||
caches map[metainfo.Hash]*filecache.Cache
|
||||
capacity int64
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewStorage(capacity int64) storage.Storage {
|
||||
stor := new(Storage)
|
||||
stor.capacity = capacity
|
||||
stor.caches = make(map[metainfo.Hash]*filecache.Cache)
|
||||
return stor
|
||||
}
|
||||
|
||||
func (s *Storage) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage2.TorrentImpl, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
path := filepath.Join(settings.Path, "cache", infoHash.String())
|
||||
cache, err := filecache.NewCache(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cache.SetCapacity(s.capacity)
|
||||
s.caches[infoHash] = cache
|
||||
return storage2.NewResourcePieces(cache.AsResourceProvider()).OpenTorrent(info, infoHash)
|
||||
}
|
||||
|
||||
func (s *Storage) GetStats(hash metainfo.Hash) *state.CacheState {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Storage) Clean() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *Storage) CloseHash(hash metainfo.Hash) {
|
||||
if s.caches == nil {
|
||||
return
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
}
|
||||
|
||||
func (s *Storage) Close() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package state
|
||||
|
||||
type CacheState struct {
|
||||
Hash string
|
||||
Capacity int64
|
||||
Filled int64
|
||||
PiecesLength int64
|
||||
PiecesCount int
|
||||
Pieces map[int]ItemState
|
||||
}
|
||||
|
||||
type ItemState struct {
|
||||
Id int
|
||||
Accessed int64
|
||||
BufferSize int64
|
||||
Completed bool
|
||||
Hash string
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"server/torr/storage/state"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"github.com/anacrolix/torrent/storage"
|
||||
)
|
||||
@@ -10,6 +8,5 @@ import (
|
||||
type Storage interface {
|
||||
storage.ClientImpl
|
||||
|
||||
GetStats(hash metainfo.Hash) *state.CacheState
|
||||
CloseHash(hash metainfo.Hash)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package memcache
|
||||
package torrstor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -53,7 +53,6 @@ func (b *BufferPool) GetBuffer(p *Piece) (buff []byte, index int) {
|
||||
buff = buf.buf
|
||||
index = id
|
||||
b.frees--
|
||||
//fmt.Printf("Get buffer: %v %v %v %p\n", id, p.Id, b.frees, buff)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package memcache
|
||||
package torrstor
|
||||
|
||||
import (
|
||||
"log"
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
|
||||
"server/settings"
|
||||
"server/torr/reader"
|
||||
"server/torr/storage/state"
|
||||
"server/utils"
|
||||
"server/torr/utils"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"github.com/anacrolix/torrent/storage"
|
||||
@@ -101,30 +100,6 @@ func (c *Cache) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetState() state.CacheState {
|
||||
cState := state.CacheState{}
|
||||
cState.Capacity = c.capacity
|
||||
cState.PiecesLength = c.pieceLength
|
||||
cState.PiecesCount = c.pieceCount
|
||||
cState.Hash = c.hash.HexString()
|
||||
|
||||
stats := make(map[int]state.ItemState, 0)
|
||||
c.muPiece.Lock()
|
||||
var fill int64 = 0
|
||||
for _, value := range c.pieces {
|
||||
stat := value.Stat()
|
||||
if stat.BufferSize > 0 {
|
||||
fill += stat.BufferSize
|
||||
stats[stat.Id] = stat
|
||||
}
|
||||
}
|
||||
c.filled = fill
|
||||
c.muPiece.Unlock()
|
||||
cState.Filled = c.filled
|
||||
cState.Pieces = stats
|
||||
return cState
|
||||
}
|
||||
|
||||
func (c *Cache) cleanPieces() {
|
||||
if c.isRemove {
|
||||
return
|
||||
@@ -220,7 +195,7 @@ func (c *Cache) ReadersLen() int {
|
||||
func (c *Cache) AdjustRA(readahead int64) {
|
||||
c.muReader.Lock()
|
||||
defer c.muReader.Unlock()
|
||||
if settings.Get().CacheSize == 0 {
|
||||
if settings.BTsets.CacheSize == 0 {
|
||||
c.capacity = readahead * 3
|
||||
}
|
||||
for r, _ := range c.readers {
|
||||
@@ -1,4 +1,4 @@
|
||||
package memcache
|
||||
package torrstor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"server/torr/storage/state"
|
||||
|
||||
"github.com/anacrolix/torrent/storage"
|
||||
)
|
||||
|
||||
@@ -103,13 +101,10 @@ func (p *Piece) Release() {
|
||||
p.complete = false
|
||||
}
|
||||
|
||||
func (p *Piece) Stat() state.ItemState {
|
||||
itm := state.ItemState{
|
||||
Id: p.Id,
|
||||
Hash: p.Hash,
|
||||
Accessed: p.accessed,
|
||||
Completed: p.complete,
|
||||
BufferSize: p.Size,
|
||||
}
|
||||
return itm
|
||||
func WriteToDisk(b []byte, off int64) (n int, err error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func ReadFromDisk(b []byte, off int64) (n int, err error) {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
package memcache
|
||||
package torrstor
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"server/torr/storage"
|
||||
"server/torr/storage/state"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
storage2 "github.com/anacrolix/torrent/storage"
|
||||
@@ -34,16 +33,6 @@ func (s *Storage) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (stor
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (s *Storage) GetStats(hash metainfo.Hash) *state.CacheState {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if c, ok := s.caches[hash]; ok {
|
||||
st := c.GetState()
|
||||
return &st
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Storage) CloseHash(hash metainfo.Hash) {
|
||||
if s.caches == nil {
|
||||
return
|
||||
Reference in New Issue
Block a user