package model import ( "context" "git.kmsign.ru/royalcat/tstor/daemons/atorrent" "github.com/anacrolix/torrent" ) func MapPeerSource(source torrent.PeerSource) string { switch source { case torrent.PeerSourceDirect: return "Direct" case torrent.PeerSourceUtHolepunch: return "Ut Holepunch" case torrent.PeerSourceDhtAnnouncePeer: return "DHT Announce" case torrent.PeerSourceDhtGetPeers: return "DHT" case torrent.PeerSourceIncoming: return "Incoming" case torrent.PeerSourceTracker: return "Tracker" case torrent.PeerSourcePex: return "PEX" default: return "Unknown" } } func MapTorrent(ctx context.Context, t *atorrent.Controller) (*Torrent, error) { prio, err := t.Priority(ctx) if err != nil { return nil, err } return &Torrent{ Infohash: t.InfoHash(), Name: t.Name(), BytesCompleted: t.BytesCompleted(), BytesMissing: t.BytesMissing(), Priority: prio, T: t, }, nil } func MapTorrentStats(s atorrent.TorrentStats) *TorrentStats { return &TorrentStats{ Timestamp: s.Timestamp, DownloadedBytes: uint(s.DownloadedBytes), UploadedBytes: uint(s.UploadedBytes), TotalPeers: uint(s.TotalPeers), ActivePeers: uint(s.ActivePeers), ConnectedSeeders: uint(s.ConnectedSeeders), } }