torrentfs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: GPL-3.0, GPL-3.0 Imports: 42 Imported by: 0

README

torrentfs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBuildConn      = errors.New("build internal-rpc connection failed")
	ErrGetLatestBlock = errors.New("get latest block failed")
	ErrNoRPCClient    = errors.New("no rpc client")

	ErrBlockHash = errors.New("block or parent block hash invalid")
)

Errors that are used throughout the Torrent API.

View Source
var DefaultConfig = Config{
	Port:            30090,
	DefaultTrackers: params.MainnetTrackers,
	BoostNodes:      params.TorrentBoostNodes,
	SyncMode:        "full",
	DisableUTP:      true,
	DisableDHT:      false,
	MaxSeedingNum:   640,
	MaxActiveNum:    400,
}

DefaultConfig contains default settings for the storage.

View Source
var (
	ErrReadDataFromBoltDB = errors.New("Bolt DB Read Error")
)
View Source
var Str404NotFound []byte = []byte{} /* 178 elements not displayed */
View Source
var TorrentAPIAvailable sync.Mutex

Functions

func Available added in v1.0.0

func Available(infohash string, rawSize int64) bool

func Exist added in v1.0.0

func Exist(infohash string) bool

func ExistTorrent added in v1.0.0

func ExistTorrent(infohash string) bool

func GetFile added in v1.0.0

func GetFile(infohash string, path string) ([]byte, error)

func GetMagnetURI added in v1.0.0

func GetMagnetURI(infohash metainfo.Hash) string

func SetConnection added in v1.0.0

func SetConnection(clientURI string) (*rpc.Client, error)

SetConnection method builds connection to remote or local communicator.

Types

type ActiveTorrentList added in v1.0.0

type ActiveTorrentList []*Torrent

func (ActiveTorrentList) Len added in v1.0.0

func (s ActiveTorrentList) Len() int

func (ActiveTorrentList) Less added in v1.0.0

func (s ActiveTorrentList) Less(i, j int) bool

func (ActiveTorrentList) Swap added in v1.0.0

func (s ActiveTorrentList) Swap(i, j int)

type Block

type Block struct {
	Number     uint64        `json:"number"           gencodec:"required"`
	Hash       common.Hash   `json:"Hash"             gencodec:"required"`
	ParentHash common.Hash   `json:"parentHash"       gencodec:"required"`
	Txs        []Transaction `json:"Transactions"     gencodec:"required"`
}

gencodec -type Block -field-override blockMarshaling -out gen_block_json.go Block ... block struct

func (Block) MarshalJSON

func (b Block) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type BoostDataFetcher added in v1.0.0

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

func NewBoostDataFetcher added in v1.0.0

func NewBoostDataFetcher(nodes []string) *BoostDataFetcher

func (*BoostDataFetcher) GetFile added in v1.0.0

func (f *BoostDataFetcher) GetFile(ih, subpath string) ([]byte, error)

func (*BoostDataFetcher) GetTorrent added in v1.0.0

func (f *BoostDataFetcher) GetTorrent(ih string) ([]byte, error)

type CVMStorage added in v1.0.0

type CVMStorage interface {
	Available(infohash string, rawSize int64) bool
	GetFile(infohash string, path string) ([]byte, error)
}
var Torrentfs_handle CVMStorage

New creates a new dashboard instance with the given configuration.

func CreateStorage added in v1.0.0

func CreateStorage(storage_type string, config Config) CVMStorage

func GetStorage added in v1.0.0

func GetStorage() CVMStorage

type Config

type Config struct {
	// Host is the host interface on which to start the storage server. If this
	// field is empty, no storage will be started.
	Port            int      `toml:",omitempty"`
	DataDir         string   `toml:",omitempty"`
	RpcURI          string   `toml:",omitempty"`
	IpcPath         string   `toml:",omitempty"`
	DisableUTP      bool     `toml:",omitempty"`
	DisableDHT      bool     `toml:",omitempty"`
	DefaultTrackers []string `toml:",omitempty"`
	BoostNodes      []string `toml:",omitempty"`
	SyncMode        string   `toml:",omitempty"`
	MaxSeedingNum   int      `toml:",omitempty"`
	MaxActiveNum    int      `toml:",omitempty"`
}

Config ...

func GetConfig added in v1.0.0

func GetConfig() *Config

func InitConfig added in v1.0.0

func InitConfig() *Config

type FileInfo

type FileInfo struct {
	Meta *FileMeta
	// Transaction hash
	TxHash *common.Hash
	// Contract Address
	ContractAddr *common.Address
	LeftSize     uint64
	Index        uint64
}

func (FileInfo) MarshalJSON

func (f FileInfo) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*FileInfo) UnmarshalJSON

func (f *FileInfo) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type FileMeta

type FileMeta struct {
	InfoHash metainfo.Hash `json:"InfoHash"         gencodec:"required"`
	Name     string        `json:"Name"             gencodec:"required"`
	// The raw size of the file counted in bytes
	RawSize  uint64 `json:"RawSize"          gencodec:"required"`
	BlockNum uint64 `json:"BlockNum"         gencodec:"required"`
}

FileMeta ...

func (*FileMeta) DisplayName

func (m *FileMeta) DisplayName() string

DisplayName ...

func (FileMeta) MarshalJSON

func (f FileMeta) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*FileMeta) UnmarshalJSON

func (f *FileMeta) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type FileStorage

type FileStorage struct {
	LastListenBlockNumber uint64
	LastFileIndex         uint64
	// contains filtered or unexported fields
}

func NewFileStorage

func NewFileStorage(config *Config) (*FileStorage, error)

func (*FileStorage) AddCachedFile added in v1.0.0

func (fs *FileStorage) AddCachedFile(x *FileInfo) error

func (*FileStorage) AddFile

func (fs *FileStorage) AddFile(x *FileInfo) error

func (*FileStorage) Close added in v1.0.0

func (fs *FileStorage) Close() error

func (*FileStorage) GetBlockByNumber added in v1.0.0

func (fs *FileStorage) GetBlockByNumber(blockNum uint64) *Block

func (*FileStorage) GetFileByAddr

func (fs *FileStorage) GetFileByAddr(addr common.Address) *FileInfo

func (*FileStorage) GetFileByNumber added in v1.0.0

func (fs *FileStorage) GetFileByNumber(index uint64) *FileInfo

func (*FileStorage) NewFileInfo added in v1.0.0

func (fs *FileStorage) NewFileInfo(Meta *FileMeta) *FileInfo

func (*FileStorage) WriteBlock added in v1.0.0

func (fs *FileStorage) WriteBlock(b *Block) error

func (*FileStorage) WriteFile added in v1.0.0

func (fs *FileStorage) WriteFile(f *FileInfo) error

type FlowControlMeta

type FlowControlMeta struct {
	InfoHash       metainfo.Hash
	BytesRequested uint64
}

type GeneralMessage

type GeneralMessage struct {
	Version string `json:"version,omitempty"`
	Commit  string `json:"commit,omitempty"`
}

type HTTPMonitor

type HTTPMonitor struct {
	Addr string
	// contains filtered or unexported fields
}

HTTPMonitor ... Monitor for serving http services.

func NewHTTPMonitor

func NewHTTPMonitor(addr string) *HTTPMonitor

NewHTTPMonitor ... Create a http monitor instance.

func (*HTTPMonitor) Finalize

func (m *HTTPMonitor) Finalize()

func (*HTTPMonitor) Initilize

func (m *HTTPMonitor) Initilize()

func (*HTTPMonitor) ServeHTTP

func (m *HTTPMonitor) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*HTTPMonitor) Update

func (m *HTTPMonitor) Update(path string, value interface{})

type InfoHashFileSystem added in v1.0.0

type InfoHashFileSystem struct {
	DataDir string
}

func (InfoHashFileSystem) Available added in v1.0.0

func (fs InfoHashFileSystem) Available(infohash string, rawSize int64) bool

func (InfoHashFileSystem) GetFile added in v1.0.0

func (fs InfoHashFileSystem) GetFile(infohash string, subpath string) ([]byte, error)

type Monitor

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

Monitor observes the data changes on the blockchain and synchronizes. cl for ipc/rpc communication, dl for download manager, and fs for data storage.

func NewMonitor

func NewMonitor(flag *Config) (*Monitor, error)

NewMonitor creates a new instance of monitor. Once Ipcpath is settle, this method prefers to build socket connection in order to get higher communicating performance. IpcPath is unavailable on windows.

func (*Monitor) Start

func (m *Monitor) Start() error

Start ... start ListenOn on the rpc port of a blockchain full node

func (*Monitor) Stop added in v1.0.0

func (m *Monitor) Stop()

type MutexCounter added in v1.0.0

type MutexCounter int32

func (*MutexCounter) Decrease added in v1.0.0

func (mc *MutexCounter) Decrease()

func (*MutexCounter) Increase added in v1.0.0

func (mc *MutexCounter) Increase()

func (*MutexCounter) IsZero added in v1.0.0

func (mc *MutexCounter) IsZero() bool

type Torrent

type Torrent struct {
	*torrent.Torrent
	// contains filtered or unexported fields
}

Torrent ...

func (*Torrent) BytesLeft added in v1.0.0

func (t *Torrent) BytesLeft() int64

func (*Torrent) GetFile added in v1.0.0

func (t *Torrent) GetFile(subpath string) ([]byte, error)

func (*Torrent) HasTorrent added in v1.0.0

func (t *Torrent) HasTorrent() bool

func (*Torrent) InfoHash added in v1.0.0

func (t *Torrent) InfoHash() string

func (*Torrent) IsAvailable added in v1.0.0

func (t *Torrent) IsAvailable() bool

func (*Torrent) Length added in v1.0.0

func (t *Torrent) Length() int64

func (*Torrent) NumPieces added in v1.0.0

func (t *Torrent) NumPieces() int

func (*Torrent) Pause

func (t *Torrent) Pause()

Pause ...

func (*Torrent) Paused

func (t *Torrent) Paused() bool

Paused ...

func (*Torrent) Pending

func (t *Torrent) Pending() bool

Pending ...

func (*Torrent) ReloadFile added in v1.0.0

func (t *Torrent) ReloadFile(files []string, datas [][]byte, tm *TorrentManager)

func (*Torrent) ReloadTorrent added in v1.0.0

func (t *Torrent) ReloadTorrent(data []byte, tm *TorrentManager)

func (*Torrent) Run

func (t *Torrent) Run()

Run ...

func (*Torrent) Running

func (t *Torrent) Running() bool

Running ...

func (*Torrent) Seed

func (t *Torrent) Seed()

func (*Torrent) SeedInQueue added in v1.0.0

func (t *Torrent) SeedInQueue()

func (*Torrent) Seeding

func (t *Torrent) Seeding() bool

func (*Torrent) WriteTorrent added in v1.0.0

func (t *Torrent) WriteTorrent()

type TorrentFS

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

TorrentFS contains the torrent file system internals.

func GetTorrentInstance added in v1.0.0

func GetTorrentInstance() *TorrentFS

func New

func New(config *Config, commit string) (*TorrentFS, error)

New creates a new torrentfs instance with the given configuration.

func (*TorrentFS) APIs

func (tfs *TorrentFS) APIs() []rpc.API

APIs implements the node.Service interface.

func (TorrentFS) Available added in v1.0.0

func (fs TorrentFS) Available(infohash string, rawSize int64) bool

func (*TorrentFS) Config added in v1.0.0

func (t *TorrentFS) Config() *Config

func (TorrentFS) GetFile added in v1.0.0

func (fs TorrentFS) GetFile(infohash string, subpath string) ([]byte, error)

func (*TorrentFS) Monitor added in v1.0.0

func (t *TorrentFS) Monitor() *Monitor

func (*TorrentFS) Protocols

func (tfs *TorrentFS) Protocols() []p2p.Protocol

Protocols implements the node.Service interface.

func (*TorrentFS) Start

func (tfs *TorrentFS) Start(server *p2p.Server) error

Start starts the data collection thread and the listening server of the dashboard. Implements the node.Service interface.

func (*TorrentFS) Stop

func (tfs *TorrentFS) Stop() error

Stop stops the data collection thread and the connection listener of the dashboard. Implements the node.Service interface.

type TorrentManager

type TorrentManager struct {
	DataDir    string
	TmpDataDir string
	// contains filtered or unexported fields
}

TorrentManager ...

var CurrentTorrentManager *TorrentManager = nil

func NewTorrentManager

func NewTorrentManager(config *Config) *TorrentManager

NewTorrentManager ...

func (*TorrentManager) AddInfoHash added in v1.0.0

func (tm *TorrentManager) AddInfoHash(ih metainfo.Hash, BytesRequested int64)

func (*TorrentManager) AddTorrent

func (tm *TorrentManager) AddTorrent(filePath string, BytesRequested int64)

func (*TorrentManager) Close added in v1.0.0

func (tm *TorrentManager) Close() error

func (*TorrentManager) CreateTorrent added in v1.0.0

func (tm *TorrentManager) CreateTorrent(t *torrent.Torrent, requested int64, status int, ih metainfo.Hash) *Torrent

func (*TorrentManager) DropMagnet

func (tm *TorrentManager) DropMagnet(ih metainfo.Hash) bool

DropMagnet ...

func (*TorrentManager) GetTorrent added in v1.0.0

func (tm *TorrentManager) GetTorrent(ih metainfo.Hash) *Torrent

func (*TorrentManager) NewTorrent

func (tm *TorrentManager) NewTorrent(input interface{}) error

func (*TorrentManager) RemoveTorrent

func (tm *TorrentManager) RemoveTorrent(input metainfo.Hash) error

func (*TorrentManager) SetTorrent added in v1.0.0

func (tm *TorrentManager) SetTorrent(ih metainfo.Hash, torrent *Torrent)

func (*TorrentManager) SetTrackers

func (tm *TorrentManager) SetTrackers(trackers []string)

func (*TorrentManager) Start added in v1.0.0

func (tm *TorrentManager) Start() error

func (*TorrentManager) UpdateInfoHash added in v1.0.0

func (tm *TorrentManager) UpdateInfoHash(ih metainfo.Hash, BytesRequested int64)

UpdateInfoHash ...

func (*TorrentManager) UpdateTorrent

func (tm *TorrentManager) UpdateTorrent(input interface{}) error

type TorrentManagerAPI

type TorrentManagerAPI interface {
	Start() error
	Close() error
	NewTorrent(interface{}) error
	RemoveTorrent(metainfo.Hash) error
	UpdateTorrent(interface{}) error
}

type Transaction

type Transaction struct {
	Price     *big.Int        `json:"gasPrice" gencodec:"required"`
	Amount    *big.Int        `json:"value"    gencodec:"required"`
	GasLimit  uint64          `json:"gas"      gencodec:"required"`
	Payload   []byte          `json:"input"    gencodec:"required"`
	From      *common.Address `json:"from"     gencodec:"required"`
	Recipient *common.Address `json:"to"       rlp:"nil"` // nil means contract creation
	Hash      *common.Hash    `json:"hash"     gencodec:"required"`
	Receipt   *TxReceipt      `json:"receipt"  rlp:"nil"`
}

Transaction ... Tx struct

func (*Transaction) Data

func (t *Transaction) Data() []byte

Data ...

func (*Transaction) IsFlowControl

func (t *Transaction) IsFlowControl() bool

IsFlowControl ...

func (Transaction) MarshalJSON

func (t Transaction) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Transaction) Op

func (t *Transaction) Op() (op int)

Op ...

func (*Transaction) Parse

func (t *Transaction) Parse() *FileMeta

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type TxReceipt

type TxReceipt struct {
	// Contract Address
	ContractAddr *common.Address `json:"ContractAddress"  gencodec:"required"`
	// Transaction Hash
	TxHash *common.Hash `json:"TransactionHash"  gencodec:"required"`
	//Receipt   *TxReceipt      `json:"receipt"  rlp:"nil"`
	GasUsed uint64 `json:"gasUsed" gencodec:"required"`
	Status  uint64 `json:"status"`
}

TxReceipt ...

func (TxReceipt) MarshalJSON

func (r TxReceipt) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*TxReceipt) UnmarshalJSON

func (r *TxReceipt) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

Jump to

Keyboard shortcuts

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