tstor/daemons/atorrent/delivery/graphql/mappers.go
royalcat a89b9e7303
Some checks failed
docker / build-docker (push) Failing after 57s
fix atorrent submodule error
2025-01-08 16:39:01 +03:00

56 lines
1.3 KiB
Go

package graphql
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),
}
}