argo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 15 Imported by: 0

README

argo/rpc

aria2 rpc ctl, support websocket

Go Report Card GoDoc

Install

go get github.com/atopx/argo/rpc@latest

Interface

  AddURI(uris []string, options ...interface{}) (gid string, err error)
  AddTorrent(filename string, options ...interface{}) (gid string, err error)
  AddMetalink(filename string, options ...interface{}) (gid []string, err error)
  Remove(gid string) (msg string, err error)
  ForceRemove(gid string) (msg string, err error)
  Pause(gid string) (msg string, err error)
  PauseAll() (msg string, err error)
  ForcePause(gid string) (msg string, err error)
  ForcePauseAll() (msg string, err error)
  Unpause(gid string) (msg string, err error)
  UnpauseAll() (msg string, err error)
  TellStatus(gid string, keys ...string) (o Option, err error)
  GetUris(gid string) (o Option, err error)
  GetFiles(gid string) (o Option, err error)
  GetPeers(gid string) (o []Option, err error)
  GetServers(gid string) (o []Option, err error)
  TellActive(keys ...string) (o []Option, err error)
  TellWaiting(offset, num int, keys ...string) (o []Option, err error)
  TellStopped(offset, num int, keys ...string) (o []Option, err error)
  ChangePosition(gid string, pos int, how string) (p int, err error)
  ChangeURI(gid string, fileindex int, delUris []string, addUris []string, position ...int) (p []int, err error)
  GetOption(gid string) (o Option, err error)
  ChangeOption(gid string, options Option) (msg string, err error)
  GetGlobalOption() (o Option, err error)
  ChangeGlobalOption(options Option) (msg string, err error)
  GetGlobalStat() (o Option, err error)
  PurgeDowloadResult() (msg string, err error)
  RemoveDownloadResult(gid string) (msg string, err error)
  GetVersion() (o Option, err error)
  GetSessionInfo() (o Option, err error)
  Shutdown() (msg string, err error)
  ForceShutdown() (msg string, err error)
  Multicall(methods []Option) (r []interface{}, err error)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNullResult = errors.New("result is null")

Functions

func DecodeClientResponse

func DecodeClientResponse(r io.Reader, reply interface{}) error

DecodeClientResponse decodes the response body of a client request into the interface reply.

func EncodeClientRequest

func EncodeClientRequest(method string, params interface{}) (*bytes.Buffer, error)

EncodeClientRequest encodes parameters for a JSON-RPC client request.

Types

type Caller

type Caller interface {
	// Call sends a request of rpc to aria2 daemon
	Call(method string, params, reply interface{}) (err error)
	Close()
}

type Client

type Client interface {
	Protocol
	Close()
}

func New

func New(ctx context.Context, uri string, token string, timeout time.Duration, notifier Notifier) (Client, error)

New returns an instance of Client

type DefaultNotifier

type DefaultNotifier struct{}

func (DefaultNotifier) OnBtDownloadComplete

func (DefaultNotifier) OnBtDownloadComplete(events []Event)

func (DefaultNotifier) OnDownloadComplete

func (DefaultNotifier) OnDownloadComplete(events []Event)

func (DefaultNotifier) OnDownloadError

func (DefaultNotifier) OnDownloadError(events []Event)

func (DefaultNotifier) OnDownloadPause

func (DefaultNotifier) OnDownloadPause(events []Event)

func (DefaultNotifier) OnDownloadStart

func (DefaultNotifier) OnDownloadStart(events []Event)

func (DefaultNotifier) OnDownloadStop

func (DefaultNotifier) OnDownloadStop(events []Event)

type Error

type Error struct {
	// A Number that indicates the error type that occurred.
	Code ErrorCode `json:"code"` /* required */

	// A String providing a short description of the error.
	// The message SHOULD be limited to a concise single sentence.
	Message string `json:"message"` /* required */

	// A Primitive or Structured value that contains additional information about the error.
	Data interface{} `json:"data"` /* optional */
}

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int
const (
	E_PARSE       ErrorCode = -32700
	E_INVALID_REQ ErrorCode = -32600
	E_NO_METHOD   ErrorCode = -32601
	E_BAD_PARAMS  ErrorCode = -32602
	E_INTERNAL    ErrorCode = -32603
	E_SERVER      ErrorCode = -32000
)

type Event

type Event struct {
	Gid string `json:"gid"` // GID of the download
}

type FileInfo

type FileInfo struct {
	Index           string    `json:"index"`           // Index of the file, starting at 1, in the same order as files appear in the multi-file torrent.
	Path            string    `json:"path"`            // File path.
	Length          string    `json:"length"`          // File size in bytes.
	CompletedLength string    `json:"completedLength"` // Completed length of this file in bytes. Please note that it is possible that sum of completedLength is less than the completedLength returned by the aria2.tellStatus() method. This is because completedLength in aria2.getFiles() only includes completed pieces. On the other hand, completedLength in aria2.tellStatus() also includes partially completed pieces.
	Selected        string    `json:"selected"`        // true if this file is selected by --select-file option. If --select-file is not specified or this is single-file torrent or not a torrent download at all, this value is always true. Otherwise false.
	URIs            []URIInfo `json:"uris"`            // Returns a list of URIs for this file. The element type is the same struct used in the aria2.getUris() method.
}

FileInfo represents an element of response of aria2.getFiles

type GlobalStatInfo

type GlobalStatInfo struct {
	DownloadSpeed   string `json:"downloadSpeed"`   // Overall download speed (byte/sec).
	UploadSpeed     string `json:"uploadSpeed"`     // Overall upload speed(byte/sec).
	NumActive       string `json:"numActive"`       // The number of active downloads.
	NumWaiting      string `json:"numWaiting"`      // The number of waiting downloads.
	NumStopped      string `json:"numStopped"`      // The number of stopped downloads in the current session. This value is capped by the --max-download-result option.
	NumStoppedTotal string `json:"numStoppedTotal"` // The number of stopped downloads in the current session and not capped by the --max-download-result option.
}

GlobalStatInfo represents response of aria2.getGlobalStat

type HttpCaller

type HttpCaller struct {
	// contains filtered or unexported fields
}

func (*HttpCaller) Call

func (h *HttpCaller) Call(method string, params, reply interface{}) (err error)

func (*HttpCaller) Close

func (h *HttpCaller) Close()

type Method

type Method struct {
	Name   string        `json:"methodName"` // Method name to call
	Params []interface{} `json:"params"`     // Array containing parameters to the method call
}

Method is an element of parameters used in system.multicall

type Notifier

type Notifier interface {
	// OnDownloadStart will be sent when a download is started.
	OnDownloadStart([]Event)
	// OnDownloadPause will be sent when a download is paused.
	OnDownloadPause([]Event)
	// OnDownloadStop will be sent when a download is stopped by the user.
	OnDownloadStop([]Event)
	// OnDownloadComplete will be sent when a download is complete. For BitTorrent downloads, this notification is sent when the download is complete and seeding is over.
	OnDownloadComplete([]Event)
	// OnDownloadError will be sent when a download is stopped due to an error.
	OnDownloadError([]Event)
	// OnBtDownloadComplete will be sent when a torrent download is complete but seeding is still going on.
	OnBtDownloadComplete([]Event)
}

Notifier handles rpc notification from aria2 server

type Option

type Option map[string]interface{}

Option is a container for specifying Call parameters and returning results

type PeerInfo

type PeerInfo struct {
	PeerId        string `json:"peerId"`        // Percent-encoded peer ID.
	IP            string `json:"ip"`            // IP address of the peer.
	Port          string `json:"port"`          // Port number of the peer.
	BitField      string `json:"bitfield"`      // Hexadecimal representation of the download progress of the peer. The highest bit corresponds to the piece at index 0. Set bits indicate the piece is available and unset bits indicate the piece is missing. Any spare bits at the end are set to zero.
	AmChoking     string `json:"amChoking"`     // true if aria2 is choking the peer. Otherwise false.
	PeerChoking   string `json:"peerChoking"`   // true if the peer is choking aria2. Otherwise false.
	DownloadSpeed string `json:"downloadSpeed"` // Download speed (byte/sec) that this client obtains from the peer.
	UploadSpeed   string `json:"uploadSpeed"`   // Upload speed(byte/sec) that this client uploads to the peer.
	Seeder        string `json:"seeder"`        // true if this peer is a seeder. Otherwise false.
}

PeerInfo represents an element of response of aria2.getPeers

type Protocol

type Protocol interface {
	AddURI(uris []string, options ...interface{}) (gid string, err error)
	AddTorrent(filename string, options ...interface{}) (gid string, err error)
	AddMetalink(filename string, options ...interface{}) (gid []string, err error)
	Remove(gid string) (g string, err error)
	ForceRemove(gid string) (g string, err error)
	Pause(gid string) (g string, err error)
	PauseAll() (ok string, err error)
	ForcePause(gid string) (g string, err error)
	ForcePauseAll() (ok string, err error)
	Unpause(gid string) (g string, err error)
	UnpauseAll() (ok string, err error)
	TellStatus(gid string, keys ...string) (info StatusInfo, err error)
	GetURIs(gid string) (infos []URIInfo, err error)
	GetFiles(gid string) (infos []FileInfo, err error)
	GetPeers(gid string) (infos []PeerInfo, err error)
	GetServers(gid string) (infos []ServerInfo, err error)
	TellActive(keys ...string) (infos []StatusInfo, err error)
	TellWaiting(offset, num int, keys ...string) (infos []StatusInfo, err error)
	TellStopped(offset, num int, keys ...string) (infos []StatusInfo, err error)
	ChangePosition(gid string, pos int, how string) (p int, err error)
	ChangeURI(gid string, fileindex int, delUris []string, addUris []string, position ...int) (p []int, err error)
	GetOption(gid string) (m Option, err error)
	ChangeOption(gid string, option Option) (ok string, err error)
	GetGlobalOption() (m Option, err error)
	ChangeGlobalOption(options Option) (ok string, err error)
	GetGlobalStat() (info GlobalStatInfo, err error)
	PurgeDownloadResult() (ok string, err error)
	RemoveDownloadResult(gid string) (ok string, err error)
	GetVersion() (info VersionInfo, err error)
	GetSessionInfo() (info SessionInfo, err error)
	Shutdown() (ok string, err error)
	ForceShutdown() (ok string, err error)
	SaveSession() (ok string, err error)
	Multicall(methods []Method) (r []interface{}, err error)
	ListMethods() (methods []string, err error)
}

Protocol is a set of rpc methods that aria2 daemon supports

type ResponseProcFn

type ResponseProcFn func(resp clientResponse) error

type ResponseProcessor

type ResponseProcessor struct {
	// contains filtered or unexported fields
}

func NewResponseProcessor

func NewResponseProcessor() *ResponseProcessor

func (*ResponseProcessor) Add

func (r *ResponseProcessor) Add(id uint64, fn ResponseProcFn)

func (*ResponseProcessor) Process

func (r *ResponseProcessor) Process(resp clientResponse) error

Process called by recv routine

type ServerInfo

type ServerInfo struct {
	Index   string `json:"index"` // Index of the file, starting at 1, in the same order as files appear in the multi-file metalink.
	Servers []struct {
		URI           string `json:"uri"`           // Original URI.
		CurrentURI    string `json:"currentUri"`    // This is the URI currently used for downloading. If redirection is involved, currentUri and uri may differ.
		DownloadSpeed string `json:"downloadSpeed"` // Download speed (byte/sec)
	} `json:"servers"` // A list of structs which contain the following keys.
}

ServerInfo represents an element of response of aria2.getServers

type SessionInfo

type SessionInfo struct {
	Id string `json:"sessionId"` // Session ID, which is generated each time when aria2 is invoked.
}

SessionInfo represents response of aria2.getSessionInfo

type StatusInfo

type StatusInfo struct {
	Gid             string     `json:"gid"`             // GID of the download.
	Status          string     `json:"status"`          // active for currently downloading/seeding downloads. waiting for downloads in the queue; download is not started. paused for paused downloads. error for downloads that were stopped because of error. complete for stopped and completed downloads. removed for the downloads removed by user.
	TotalLength     string     `json:"totalLength"`     // Total length of the download in bytes.
	CompletedLength string     `json:"completedLength"` // Completed length of the download in bytes.
	UploadLength    string     `json:"uploadLength"`    // Uploaded length of the download in bytes.
	BitField        string     `json:"bitfield"`        // Hexadecimal representation of the download progress. The highest bit corresponds to the piece at index 0. Any set bits indicate loaded pieces, while unset bits indicate not yet loaded and/or missing pieces. Any overflow bits at the end are set to zero. When the download was not started yet, this key will not be included in the response.
	DownloadSpeed   string     `json:"downloadSpeed"`   // Download speed of this download measured in bytes/sec.
	UploadSpeed     string     `json:"uploadSpeed"`     // Upload speed of this download measured in bytes/sec.
	InfoHash        string     `json:"infoHash"`        // InfoHash. BitTorrent only.
	NumSeeders      string     `json:"numSeeders"`      // The number of seeders aria2 has connected to. BitTorrent only.
	Seeder          string     `json:"seeder"`          // true if the local endpoint is a seeder. Otherwise false. BitTorrent only.
	PieceLength     string     `json:"pieceLength"`     // Piece length in bytes.
	NumPieces       string     `json:"numPieces"`       // The number of pieces.
	Connections     string     `json:"connections"`     // The number of peers/servers aria2 has connected to.
	ErrorCode       string     `json:"errorCode"`       // The code of the last error for this item, if any. The value is a string. The error codes are defined in the EXIT STATUS section. This value is only available for stopped/completed downloads.
	ErrorMessage    string     `json:"errorMessage"`    // The (hopefully) human readable error message associated to errorCode.
	FollowedBy      []string   `json:"followedBy"`      // List of GIDs which are generated as the result of this download. For example, when aria2 downloads a Metalink file, it generates downloads described in the Metalink (see the --follow-metalink option). This value is useful to track auto-generated downloads. If there are no such downloads, this key will not be included in the response.
	BelongsTo       string     `json:"belongsTo"`       // GID of a parent download. Some downloads are a part of another download. For example, if a file in a Metalink has BitTorrent resources, the downloads of ".torrent" files are parts of that parent. If this download has no parent, this key will not be included in the response.
	Dir             string     `json:"dir"`             // Directory to save files.
	Files           []FileInfo `json:"files"`           // Returns the list of files. The elements of this list are the same structs used in aria2.getFiles() method.
	BitTorrent      struct {
		AnnounceList [][]string `json:"announceList"` // List of lists of announce URIs. If the torrent contains announce and no announce-list, announce is converted to the announce-list format.
		Comment      string     `json:"comment"`      // The comment of the torrent. comment.utf-8 is used if available.
		CreationDate int64      `json:"creationDate"` // The creation time of the torrent. The value is an integer since the epoch, measured in seconds.
		Mode         string     `json:"mode"`         // File mode of the torrent. The value is either single or multi.
		Info         struct {
			Name string `json:"name"` // name in info dictionary. name.utf-8 is used if available.
		} `json:"info"` // Struct which contains data from Info dictionary. It contains following keys.
	} `json:"bittorrent"` // Struct which contains information retrieved from the .torrent (file). BitTorrent only. It contains following keys.
}

StatusInfo represents response of aria2.tellStatus

type URIInfo

type URIInfo struct {
	URI    string `json:"uri"`    // URI
	Status string `json:"status"` // 'used' if the URI is in use. 'waiting' if the URI is still waiting in the queue.
}

URIInfo represents an element of response of aria2.getUris

type VersionInfo

type VersionInfo struct {
	Version  string   `json:"version"`         // Version number of aria2 as a string.
	Features []string `json:"enabledFeatures"` // List of enabled features. Each feature is given as a string.
}

VersionInfo represents response of aria2.getVersion

Jump to

Keyboard shortcuts

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