This commit is contained in:
YouROK
2021-05-17 14:55:57 +03:00
parent 29f13fd482
commit e578628886
40 changed files with 1319 additions and 656 deletions

View File

@@ -65,6 +65,11 @@ func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) {
spec.Trackers = [][]string{utils.GetDefTrackers()}
}
trackers := utils.GetTrackerFromFile()
if len(trackers) > 0 {
spec.Trackers = append(spec.Trackers, [][]string{trackers}...)
}
goTorrent, _, err := bt.client.AddTorrentSpec(spec)
if err != nil {
return nil, err
@@ -104,6 +109,7 @@ func (t *Torrent) WaitInfo() bool {
case <-t.Torrent.GotInfo():
t.cache = t.bt.storage.GetCache(t.Hash())
t.cache.SetTorrent(t.Torrent)
go t.cache.LoadPiecesOnDisk()
return true
case <-t.closed:
return false
@@ -167,7 +173,9 @@ func (t *Torrent) progressEvent() {
t.BytesReadUsefulData = st.BytesRead.Int64()
t.BytesWrittenData = st.BytesWritten.Int64()
t.PreloadedBytes = t.cache.GetState().Filled
if t.cache != nil {
t.PreloadedBytes = t.cache.GetState().Filled
}
} else {
t.DownloadSpeed = 0
t.UploadSpeed = 0
@@ -352,9 +360,7 @@ func (t *Torrent) Close() {
t.Stat = state.TorrentClosed
t.bt.mu.Lock()
if _, ok := t.bt.torrents[t.Hash()]; ok {
delete(t.bt.torrents, t.Hash())
}
delete(t.bt.torrents, t.Hash())
t.bt.mu.Unlock()
t.drop()