revert to _9 and add save info bytes

This commit is contained in:
YouROK
2020-04-18 15:19:39 +03:00
parent 0bc5ea3084
commit 45b2bfdd05
12 changed files with 93 additions and 72 deletions

View File

@@ -31,19 +31,18 @@ type Settings struct {
RetrackersMode int //0 - don`t add, 1 - add retrackers, 2 - remove retrackers
//BT Config
EnableIPv6 bool
DisableTCP bool
DisableUTP bool
DisableUPNP bool
DisableDHT bool
DisableUpload bool
//Encryption int // 0 - Enable, 1 - disable, 2 - force
EnableIPv6 bool
DisableTCP bool
DisableUTP bool
DisableUPNP bool
DisableDHT bool
DisableUpload bool
Encryption int // 0 - Enable, 1 - disable, 2 - force
DownloadRateLimit int // in kb, 0 - inf
UploadRateLimit int // in kb, 0 - inf
ConnectionsLimit int
DhtConnectionLimit int // 0 - inf
PeersListenPort int
PeerStrategy int // 0 - Timeout, 1 - Fastest, 2 - Fuzzing
TorrentDisconnectTimeout int // in seconds
}

View File

@@ -10,6 +10,7 @@ import (
type Torrent struct {
Name string
Magnet string
InfoBytes []byte
Hash string
Size int64
Timestamp int64
@@ -83,6 +84,10 @@ func SaveTorrentDB(torrent *Torrent) error {
if err != nil {
return fmt.Errorf("error save torrent: %v", err)
}
err = hdb.Put([]byte("InfoBytes"), torrent.InfoBytes)
if err != nil {
return fmt.Errorf("error save torrent: %v", err)
}
err = hdb.Put([]byte("Size"), i2b(torrent.Size))
if err != nil {
return fmt.Errorf("error save torrent: %v", err)
@@ -172,6 +177,13 @@ func LoadTorrentDB(hash string) (*Torrent, error) {
}
torr.Magnet = string(tmp)
tmp = hdb.Get([]byte("InfoBytes"))
if len(tmp) > 0 {
torr.InfoBytes = tmp
} else {
torr.InfoBytes = nil
}
tmp = hdb.Get([]byte("Size"))
if tmp == nil {
return fmt.Errorf("error load torrent")