tstor/daemons/atorrent/delivery/graphql/mappers.go

57 lines
1.3 KiB
Go
Raw Normal View History

2025-01-08 13:39:01 +00:00
package graphql
2025-01-07 22:25:46 +00:00
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),
}
}