kedge

package module
v0.0.0-...-e6641ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2021 License: MIT Imports: 9 Imported by: 0

README

kedgecli

Client library of kedge with Golang

interfaces


type ClientI interface {
	Add(rd io.Reader, hat string) error
	Drop(hash string) error
	DropWithData(hash string) error
	Exist(hash string) bool
	GetHashes() Hashes
	GetTorrents() ([]TorrentStatus, error)
	GetTorrent(hash string) (*TorrentStatus, error)
	Session() (*TeSession, error)
	Stats() (*TeStatistics, error)
}

usage


	root := "/var/lib/store/root"
	uri := "http://localhost:16180"
	c := kedgecli.New(root, uri)

	// read metainfo as mi *MetaInfo
	var buf bytes.Buffer
	if err := mi.Write(&buf); err != nil {
		return
	}
	err := c.Add(buf, "subdir")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Timeout          = 12 * time.Second
	KeepAliveTimeout = 60 * time.Second
	IdleConnTimeout  = 30 * time.Second
)

vars

Functions

This section is empty.

Types

type ClientI

type ClientI interface {
	Add(rd io.Reader, hat string) error
	Drop(hash string) error
	DropWithData(hash string) error
	Exist(hash string) bool
	GetHashes() Hashes
	GetTorrents() ([]TorrentStatus, error)
	GetTorrent(hash string) (*TorrentStatus, error)
	Session() (*TeSession, error)
	Stats() (*TeStatistics, error)
}

ClientI interface of kedge client

func New

func New(args ...string) ClientI

New return a client instance with args: [root[, uri]]

type Hashes

type Hashes []InfoHash

Hashes slice of InfoHash

type InfoHash

type InfoHash string

InfoHash hex string

type State

type State int16

State value of torrentStatus.state

const (
	QueuedForChecking   State = iota
	CheckingFiles             // 1
	DownloadingMetadata       // 2
	Downloading               // 3
	Finished                  // 4
	Seeding                   // 5
	Allocating                // 6
	CheckingResumeData        // 7
)

const of state, value from libtorrent/torrent_status.hpp

type TeSession

type TeSession struct {
	PeerPort uint16 `json:"peerPort,omitempty"`
	PeerID   string `json:"peerID,omitempty"`
	UptimeMs int64  `json:"uptimeMs,omitempty"` // Milliseconds
	Version  string `json:"version,omitempty"`
}

TeSession represent session basic infomation

type TeStatistics

type TeStatistics struct {
	BytesRecv       uint64 `json:"bytesRecv,omitempty"`
	BytesSent       uint64 `json:"bytesSent,omitempty"`
	BytesDataRecv   uint64 `json:"bytesDataRecv,omitempty"`
	BytesDataSent   uint64 `json:"bytesDataSent,omitempty"`
	RateRecv        uint64 `json:"rateRecv,omitempty"`
	RateSent        uint64 `json:"rateSent,omitempty"`
	BytesFailed     uint64 `json:"bytesFailed,omitempty"`
	BytesQueued     uint64 `json:"bytesQueued,omitempty"`
	BytesWasted     uint64 `json:"bytesWasted,omitempty"`
	UptimeMs        uint64 `json:"uptimeMs,omitempty"`
	Uptime          uint32 `json:"uptime,omitempty"`
	NumConnected    uint16 `json:"numPeersConnected,omitempty"`
	NumHalfOpen     uint16 `json:"numPeersHalfOpen,omitempty"`
	TaskCount       uint16 `json:"taskCount,omitempty"`
	ActiveTaskCount uint16 `json:"activeCount,omitempty"`
	PausedTaskCount uint16 `json:"pausedCount,omitempty"`
	Version         string `json:"version,omitempty"`
}

TeStatistics represent session statistics

type TorrentStatus

type TorrentStatus struct {
	ActiveDuration      int64    `json:"active_duration,omitempty"`
	FinishedDuration    int64    `json:"finished_duration,omitempty"`
	SeedingDuration     int64    `json:"seeding_duration,omitempty"`
	AddedTime           int64    `json:"added_time,omitempty"`     // unix timestamp
	CompletedTime       int64    `json:"completed_time,omitempty"` // unix timestamp
	TotalDone           uint64   `json:"total_done,omitempty"`
	TotalWanted         uint64   `json:"total_wanted,omitempty"`
	TotalWantedDone     uint64   `json:"total_wanted_done,omitempty"`
	TotalDownloaded     uint64   `json:"total_downloaded,omitempty"`         // this session
	TotalUploaded       uint64   `json:"total_uploaded,omitempty"`           // this session
	TotalDataDownloaded uint64   `json:"total_payload_downloaded,omitempty"` // this session
	TotalDataUploaded   uint64   `json:"total_payload_uploaded,omitempty"`   // this session
	AllTimeDownloaded   uint64   `json:"all_time_download,omitempty"`
	AllTimeUploaded     uint64   `json:"all_time_upload,omitempty"`
	DownloadPayloadRate int      `json:"download_payload_rate,omitempty"`
	UploadPayloadRate   int      `json:"upload_payload_rate,omitempty"`
	ConnectCandidates   int      `json:"connect_candidates,omitempty"`
	NumConnections      int      `json:"num_connections,omitempty"`
	ListSeeds           int      `json:"list_seeds,omitempty"`
	ListPeers           int      `json:"list_peers,omitempty"`
	NumPieces           int      `json:"num_pieces,omitempty"`
	Infohash            InfoHash `json:"info_hash"`
	State               State    `json:"state"`
	Name                string   `json:"name"`
	SavePath            string   `json:"save_path"`
	CurrentTracker      string   `json:"current_tracker,omitempty"`
	Progress            float32  `json:"progress,omitempty"`
	ProgressPpm         int      `json:"progress_ppm,omitempty"`
	IsFinished          bool     `json:"is_finished,omitempty"`
	IsSeeding           bool     `json:"is_seeding,omitempty"`
}

TorrentStatus ... Ratio = allTimeUploaded / TotalDone

func (*TorrentStatus) GetETA

func (ts *TorrentStatus) GetETA() int64

GetETA return seconds of remaining

func (*TorrentStatus) GetRatio

func (ts *TorrentStatus) GetRatio() float64

GetRatio return a ratio of shared bytes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL