torrentfs

package
v0.0.2-beta Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: GPL-3.0, GPL-3.0 Imports: 36 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{
	Host:            "localhost",
	Port:            8085,
	DefaultTrackers: "http://torrent.cortexlabs.ai:5008/announce",

	SyncMode: "full",
	TestMode: false,
}

DefaultConfig contains default settings for the storage.

View Source
var (
	ErrReadDataFromBoltDB = errors.New("Bolt DB Read Error")
)

Functions

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 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 Config

type Config struct {
	DataDir string `toml:",omitempty"`
	RpcURI  string `toml:",omitempty"`
	IpcPath string `toml:",omitempty"`
	// Host is the host interface on which to start the storage server. If this
	// field is empty, no storage will be started.
	Host string `toml:",omitempty"`
	// Port is the TCP port number on which to start the storage server. The
	// default zero value is/ valid and will pick a port number randomly.
	Port            int    `toml:",omitempty"`
	DefaultTrackers string `toml:",omitempty"`
	SyncMode        string `toml:",omitempty"`
	TestMode        bool   `toml:",omitempty"`
}

Config ...

type FileInfo

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

func NewFileInfo

func NewFileInfo(Meta *FileMeta) *FileInfo

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 {
	// Author Address
	AuthorAddr *common.Address
	// Download InfoHash, should be in magnetURI format
	URI string
	// The raw size of the file counted in bytes
	RawSize  uint64
	BlockNum uint64
}

FileMeta ...

func (*FileMeta) DisplayName

func (m *FileMeta) DisplayName() string

DisplayName ...

func (*FileMeta) InfoHash

func (m *FileMeta) InfoHash() *metainfo.Hash

InfoHash ...

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
	// contains filtered or unexported fields
}

func NewFileStorage

func NewFileStorage(config *Config) (*FileStorage, 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) WriteBlock added in v1.0.0

func (fs *FileStorage) WriteBlock(b *Block) 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 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) 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) Run

func (t *Torrent) Run()

Run ...

func (*Torrent) Running

func (t *Torrent) Running() bool

Running ...

func (*Torrent) Seed

func (t *Torrent) Seed()

func (*Torrent) Seeding

func (t *Torrent) Seeding() bool

type TorrentFS

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

TorrentFS contains the torrent file system internals.

func New

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

New creates a new dashboard instance with the given configuration.

func (*TorrentFS) APIs

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

APIs implements the node.Service interface.

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 ...

func NewTorrentManager

func NewTorrentManager(config *Config) *TorrentManager

NewTorrentManager ...

func (*TorrentManager) AddMagnet

func (tm *TorrentManager) AddMagnet(uri string)

AddMagnet ...

func (*TorrentManager) AddTorrent

func (tm *TorrentManager) AddTorrent(filePath string)

func (*TorrentManager) Close added in v1.0.0

func (tm *TorrentManager) Close() error

func (*TorrentManager) DropMagnet

func (tm *TorrentManager) DropMagnet(uri string) bool

DropMagnet ...

func (*TorrentManager) NewTorrent

func (tm *TorrentManager) NewTorrent(input string) error

func (*TorrentManager) RemoveTorrent

func (tm *TorrentManager) RemoveTorrent(input string) error

func (*TorrentManager) SetTrackers

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

func (*TorrentManager) Start added in v1.0.0

func (tm *TorrentManager) Start() error

func (*TorrentManager) UpdateMagnet

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

UpdateMagnet ...

func (*TorrentManager) UpdateTorrent

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

type TorrentManagerAPI

type TorrentManagerAPI interface {
	Start() error
	Close() error
	NewTorrent(string) error
	RemoveTorrent(string) 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"`
}

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