core

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const Version string = "v1.1.0"

Variables

View Source
var (
	Engine     Eng
	Info       = log.New(os.Stderr, "[INFO] ", log.LstdFlags) // Info Logger
	Warn       = log.New(os.Stderr, "[WARN] ", log.LstdFlags) // Logger for Warnings
	Err        = log.New(os.Stderr, "[ERR ] ", log.LstdFlags) // Error Logger
	Flagconfig = struct {
		ListenAddress string
		UnixSocket    string
		TLSKeyPath    string
		TLSCertPath   string
	}{}
	Dirconfig = struct {
		DirPath   string
		ConfigDir string
		CacheDir  string
		DataDir   string
		TrntDir   string
	}{}
	Configmu sync.Mutex
)
View Source
var MachInfo machInfo = loadMachInfo()
View Source
var MachStats machStats

Functions

func AbandonTorrent

func AbandonTorrent(User string, infohash metainfo.Hash)

AbandonTorrent unlinks Torrent from User

func AddMetaCache

func AddMetaCache(ih metainfo.Hash, mi metainfo.MetaInfo)

func AddTrackerstoTorrent

func AddTrackerstoTorrent(User string, infohash metainfo.Hash, announcelist [][]string)

AddTrackerstoTorrent Adds Tracker to Torrent

func AddfromSpec

func AddfromSpec(User string, spec *torrent.TorrentSpec, dontstart bool, nofsdb bool)

AddfromSpec Adds Torrent by Torrent Spec

func AuthCheck

func AuthCheck(w http.ResponseWriter, r *http.Request)

func DeleteFilePath

func DeleteFilePath(User string, infohash metainfo.Hash, fp string)

DeleteFilePath deletes the file or Folder

func DeleteTorrent

func DeleteTorrent(User string, infohash metainfo.Hash)

DeleteTorrent in addition to Removing Torrent from Client also Deletes it from Storage

func EmptyMetaCache

func EmptyMetaCache()

func GetFsDirInfo

func GetFsDirInfo(ih metainfo.Hash, fp string) (ret []byte)

func GetFsFileInfo

func GetFsFileInfo(ih metainfo.Hash, fp string) (ret []byte)

func GetMetaCache

func GetMetaCache(ih metainfo.Hash) (spec *torrent.TorrentSpec, reterr error)

func GetTorrentFileInfo

func GetTorrentFileInfo(ih metainfo.Hash, fp string) (ret []byte)

func GetTorrentFiles

func GetTorrentFiles(ih metainfo.Hash) (ret []byte)

func GetTorrentInfo

func GetTorrentInfo(ih metainfo.Hash) (ret []byte)

func GetTorrentInfoStat

func GetTorrentInfoStat(ih metainfo.Hash) (ret []byte)

func GetTorrentKnownSwarm

func GetTorrentKnownSwarm(ih metainfo.Hash) (ret []byte)

func GetTorrentMetainfo

func GetTorrentMetainfo(ih metainfo.Hash) (ret []byte)

func GetTorrentNumpieces

func GetTorrentNumpieces(ih metainfo.Hash) (ret []byte)

func GetTorrentPeerConns

func GetTorrentPeerConns(ih metainfo.Hash) (ret []byte)

func GetTorrentPieceStateRuns

func GetTorrentPieceStateRuns(ih metainfo.Hash) (ret []byte)

func GetTorrentStats

func GetTorrentStats(ih metainfo.Hash) (ret []byte)

func GetTorrents

func GetTorrents(lt []metainfo.Hash) (ret []byte)

func Initialize

func Initialize()

func MetafromHex

func MetafromHex(infohash string) (h metainfo.Hash, err error)

MetafromHex returns metainfo.Hash from given infohash string

func RemMetaCache

func RemMetaCache(ih metainfo.Hash)

func RemTrackersSpec

func RemTrackersSpec(spec *torrent.TorrentSpec)

RemTrackersSpec removes trackers from torrent.Spec

func RemoveTorrent

func RemoveTorrent(User string, infohash metainfo.Hash)

RemoveTorrent Removes Torrent from Torrent Client

func SocketAPI

func SocketAPI(w http.ResponseWriter, r *http.Request)

func SpecfromB64String

func SpecfromB64String(trnt string) (spec *torrent.TorrentSpec, reterr error)

SpecfromB64String Returns Torrent Spec from Base64 Encoded Torrent File

func SpecfromBytes

func SpecfromBytes(trnt []byte) (spec *torrent.TorrentSpec, reterr error)

SpecfromBytes Returns Torrent Spec from Bytes

func SpecfromPath

func SpecfromPath(path string) (spec *torrent.TorrentSpec, reterr error)

SpecfromPath Returns Torrent Spec from File Path

func SpecfromURL

func SpecfromURL(torrentURL string) (spec *torrent.TorrentSpec, reterr error)

SpecfromURL Returns Torrent Spec from HTTP URL

func StartFile

func StartFile(User string, infohash metainfo.Hash, fp string)

StartFile Starts File in Torrent given infohash and Filepath

func StartTorrent

func StartTorrent(User string, infohash metainfo.Hash, nofsdb bool)

StartTorrent Starts Torrent given infohash

func StopFile

func StopFile(User string, infohash metainfo.Hash, fp string)

StopFile Stops File in Torrent given infohash and Filepath

func StopTorrent

func StopTorrent(User string, infohash metainfo.Hash)

StopTorrent Stops Torrent given infohash

func StreamFile

func StreamFile(w http.ResponseWriter, r *http.Request)

func TarDir

func TarDir(dirpath string, w http.ResponseWriter, name string)

func TorrentRoutine

func TorrentRoutine()

TorrentRoutine Stops Torrent on Reaching Global SeedRatio

func TorrentServe

func TorrentServe(w http.ResponseWriter, r *http.Request)

func UpdateTrackers

func UpdateTrackers()

UpdateTrackers Updates the Trackers from TrackerURL

func ZipDir

func ZipDir(dirpath string, w http.ResponseWriter, name string)

Types

type ConReq

type ConReq struct {
	Command string `json:"command"`
	Data1   string `json:"data1"`
	Data2   string `json:"data2"`
	Data3   string `json:"data3"`
	Aop     int    `json:"aop"`
}

type ConnectionMsg

type ConnectionMsg struct {
	Type    string `json:"usertype"`
	Session string `json:"session"`
}

type DataMsg

type DataMsg struct {
	Type     string      `json:"type"`
	Data     interface{} `json:"data,omitempty"`
	Infohash string      `json:"infohash,omitempty"`
}

type DiskUsageStat

type DiskUsageStat struct {
	Total       uint64  `json:"total"`
	Free        uint64  `json:"free"`
	Used        uint64  `json:"used"`
	UsedPercent float64 `json:"usedPercent"`
}

type Eng

type Eng struct {
	Tconfig TorConfig
	Econfig EngConfig
	PsqlCon string

	Torc *torrent.Client

	PcDb      db.PcDb
	TorDb     db.TorrentDb
	TrackerDB db.TrackerDb
	FsDb      db.FileStateDb
	LsDb      db.LockStateDb
	UDb       db.UserDb
	TUDb      db.TorrentUserDb
	// contains filtered or unexported fields
}

type EngConfig

type EngConfig struct {
	DisableLocalCache bool   `json:"disableonlinecache"` // Disables Local Torrent Storage
	OnlineCacheURL    string `json:"onlinecacheurl"`     // Default is https://itorrents.org/torrent/%s.torrent , Setting Empty Disables OnlineCache

	TrackerRefresh  int64    `json:"trackerrefreshinterval"` // In Minutes
	TrackerListURLs []string `json:"trackerlisturls"`        // Default List is []string{"https://ngosang.github.io/trackerslist/trackers_best.txt"}

	DisAllowTrackersUser  bool `json:"disallowtrackersforuser"`  // If set to true , Remove all Trackers that is Added by User to magnet/torrent file. Also disallow adding trackers to torrent
	DisAllowTrackersCache bool `json:"disallowtrackersforcache"` // If set to true , Remove all Trackers from Torrent File fetched from Online/Local Cache

	GlobalSeedRatio     float64 `json:"globalseedratio"`        // Stops Torrent on Reaching Provided SeedRatio
	SRRefresh           int64   `json:"seedratiocheckinterval"` // In Minutes
	DontRemoveCacheInfo bool    `json:"dontremovecacheinfo"`    // When Torrent is Deleted from Storage, it's cache file(.torrent) from Local Cache is not Deleted

	LockbyDefault bool `json:"lockbydefault"` // If set to true , locks every torrent on Add

	ListenCompletion bool   `json:"listencompletion"`
	HookPostURL      string `json:"hookposturl"`
	NotifyOnComplete bool   `json:"notifyoncomplete"`
}

EngConfig is Engine Configuration Structure which doesn't require restart of Torrent Client

func (*EngConfig) DRCI

func (ec *EngConfig) DRCI() (ret bool)

func (*EngConfig) GetDLC

func (ec *EngConfig) GetDLC() (ret bool)

func (*EngConfig) GetDTC

func (ec *EngConfig) GetDTC() (ret bool)

func (*EngConfig) GetDTU

func (ec *EngConfig) GetDTU() (ret bool)

func (*EngConfig) GetGSR

func (ec *EngConfig) GetGSR() (ret float64)

func (*EngConfig) GetHPU added in v0.0.6

func (ec *EngConfig) GetHPU() (ret string)

func (*EngConfig) GetLBD

func (ec *EngConfig) GetLBD() (ret bool)

func (*EngConfig) GetListenC added in v0.0.6

func (ec *EngConfig) GetListenC() (ret bool)

func (*EngConfig) GetNOC added in v0.0.6

func (ec *EngConfig) GetNOC() (ret bool)

func (*EngConfig) GetOCU

func (ec *EngConfig) GetOCU() (ret string)

func (*EngConfig) GetSRR

func (ec *EngConfig) GetSRR() (ret int64)

func (*EngConfig) GetTLU

func (ec *EngConfig) GetTLU() (ret []string)

func (*EngConfig) GetTR

func (ec *EngConfig) GetTR() (ret int64)

func (*EngConfig) WriteConfig

func (ec *EngConfig) WriteConfig() (err error)

type FileInfo

type FileInfo struct {
	BytesCompleted int64  `json:"bytescompleted"`
	DisplayPath    string `json:"displaypath"`
	Length         int64  `json:"length"`
	Offset         int64  `json:"offset"`
	Path           string `json:"path"`
	Priority       byte   `json:"priority"`
}

type FsFileInfo

type FsFileInfo struct {
	Name  string `json:"name"`
	Path  string `json:"path"`
	Size  int64  `json:"size"`
	IsDir bool   `json:"isdir"`
}

type Hub

type Hub struct {
	sync.RWMutex
	Conns map[string]*UserConn
}

Hub

var MainHub Hub = Hub{
	RWMutex: sync.RWMutex{},
	Conns:   make(map[string]*UserConn),
}

func (*Hub) Add

func (h *Hub) Add(Uc *UserConn)

func (*Hub) ListUsers

func (h *Hub) ListUsers() (ret []byte)

func (*Hub) Remove

func (h *Hub) Remove(Uc *UserConn)

func (*Hub) RemoveUser

func (h *Hub) RemoveUser(Username string)

func (*Hub) SendMsg

func (h *Hub) SendMsg(User string, Type string, State string, Resp string)

func (*Hub) SendMsgU

func (h *Hub) SendMsgU(User string, Type string, Infohash string, State string, Resp string)

type MutInt

type MutInt struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*MutInt) Dec

func (M *MutInt) Dec()

func (*MutInt) Get

func (M *MutInt) Get() (ret int)

func (*MutInt) Inc

func (M *MutInt) Inc()

func (*MutInt) Set

func (M *MutInt) Set(v int)

type Mutbool

type Mutbool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Mutbool) Get

func (M *Mutbool) Get() (ret bool)

func (*Mutbool) Set

func (M *Mutbool) Set(v bool)

type Resp

type Resp struct {
	Type     string `json:"type"`
	State    string `json:"state"`
	Infohash string `json:"infohash,omitempty"`
	Msg      string `json:"message"`
}

type TorConfig

type TorConfig struct {
	ListenHost                        *string
	ListenPort                        *int
	NoDefaultPortForwarding           *bool
	UpnpID                            *string
	DisableTrackers                   *bool
	DisablePEX                        *bool
	NoDHT                             *bool
	PeriodicallyAnnounceTorrentsToDht *bool
	NoUpload                          *bool
	DisableAggressiveUpload           *bool
	Seed                              *bool
	UploadLimiterLimit                *float64
	UploadLimiterBurst                *int
	DownloadLimiterLimit              *float64
	DownloadLimiterBurst              *int
	MaxUnverifiedBytes                *int64
	PeerID                            *string
	DisableUTP                        *bool
	DisableTCP                        *bool
	HeaderObfuscationPolicy           *string
	CryptoProvides                    *uint32
	IPBlocklist                       *bool
	DisableIPv6                       *bool
	DisableIPv4                       *bool
	DisableIPv4Peers                  *bool
	Debug                             *bool
	Logger                            *bool
	HTTPUserAgent                     *string
	ExtendedHandshakeClientVersion    *string
	Bep20                             *string
	NominalDialTimeout                *int64
	MinDialTimeout                    *int64
	EstablishedConnsPerTorrent        *int
	HalfOpenConnsPerTorrent           *int
	TotalHalfOpenConns                *int
	TorrentPeersHighWater             *int
	TorrentPeersLowWater              *int
	HandshakesTimeout                 *int64
	PublicIP4                         *string
	PublicIP6                         *string
	DisableAcceptRateLimiting         *bool
	DropDuplicatePeerIds              *bool
	DropMutuallyCompletePeers         *bool
	AcceptPeerConnections             *bool
	DisableWebtorrent                 *bool
	DisableWebseeds                   *bool
}

func (*TorConfig) ToTorrentConfig

func (t *TorConfig) ToTorrentConfig() (tc *torrent.ClientConfig)

type Torrent1

type Torrent1 struct {
	Infohash       string `json:"infohash"`
	Name           string `json:"name,omitempty"`
	BytesCompleted int64  `json:"bytescompleted,omitempty"`
	BytesMissing   int64  `json:"bytesmissing,omitempty"`
	Length         int64  `json:"length,omitempty"`
	State          string `json:"state"`
	Seeding        bool   `json:"seeding,omitempty"`
}

type Torrent2

type Torrent2 struct {
	Torrent1
	StartedAt time.Time `json:"startedat"`
	AddedAt   time.Time `json:"addedat"`
}

type UserConn

type UserConn struct {
	Sendmu    sync.Mutex
	Username  string
	IsAdmin   bool
	Time      time.Time
	Conn      *websocket.Conn
	Stream    sync.Mutex
	Streamers MutInt
}

UserConn

func NewUserConn

func NewUserConn(Username string, Conn *websocket.Conn, IsAdmin bool) (uc *UserConn)

func (*UserConn) Close

func (uc *UserConn) Close()

func (*UserConn) Send

func (uc *UserConn) Send(v []byte) (err error)

func (*UserConn) SendMsg

func (uc *UserConn) SendMsg(Type string, State string, Msg string) (err error)

func (*UserConn) SendMsgU

func (uc *UserConn) SendMsgU(Type string, State string, Infohash string, Msg string) (err error)

func (*UserConn) StopStream

func (uc *UserConn) StopStream()

type UserConnMsg

type UserConnMsg struct {
	Username string    `json:"username"`
	IsAdmin  bool      `json:"isadmin"`
	Time     time.Time `json:"contime"`
}

Jump to

Keyboard shortcuts

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