modules

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2015 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AcceptTermsResponse = "accept"
)
View Source
const (
	// Denotes a host announcement in the Arbitrary Data section.
	PrefixHostAnnouncement = "HostAnnouncement"
)

Variables

View Source
var (
	BootstrapPeers = []NetAddress{
		"23.239.14.98:9988",
	}
)

TODO: Move this and it's functionality into the gateway package.

View Source
var (
	LowBalanceErr = errors.New("Insufficient Balance")
)

Functions

This section is empty.

Types

type ContractTerms

type ContractTerms struct {
	FileSize           uint64                    // How large the file is.
	Duration           consensus.BlockHeight     // How long the file is to be stored.
	DurationStart      consensus.BlockHeight     // The block height that the storing starts (typically required to start immediately, unless it's a chained contract).
	WindowSize         consensus.BlockHeight     // How long the host has to submit a proof of storage.
	Price              consensus.Currency        // Client contribution towards payout each window
	Collateral         consensus.Currency        // Host contribution towards payout each window
	ValidProofOutputs  []consensus.SiacoinOutput // Where money goes if the storage proof is successful.
	MissedProofOutputs []consensus.SiacoinOutput // Where the money goes if the storage proof fails.
}

ContractTerms are the parameters agreed upon by a client and a host when forming a FileContract.

type DownloadInfo

type DownloadInfo interface {
	// Complete returns whether the file is ready to be used. Note that
	// Received == Filesize does not imply Complete, because the file may
	// require additional processing (e.g. decryption) after all of the raw
	// bytes have been downloaded.
	Complete() bool

	// Filesize is the size of the file being downloaded.
	Filesize() uint64

	// Received is the number of bytes downloaded so far.
	Received() uint64

	// Destination is the filepath that the file was downloaded into.
	Destination() string

	// Nickname is the identifier assigned to the file when it was uploaded.
	Nickname() string
}

DownloadInfo is an interface providing information about a file that has been requested for download.

type FileInfo

type FileInfo interface {
	// Available indicates whether the file is available for downloading or
	// not.
	Available() bool

	// Nickname gives the nickname of the file.
	Nickname() string

	// Repairing indicates whether the file is actively being repaired. If
	// there are files being repaired, it is best to let them finish before
	// shutting down the program.
	Repairing() bool

	// TimeRemaining indicates how many blocks remain before the file expires.
	TimeRemaining() consensus.BlockHeight
}

FileInfo is an interface providing information about a file.

type Gateway

type Gateway interface {
	// Bootstrap joins the Sia network and establishes an initial peer list.
	Bootstrap(NetAddress) error

	// AddPeer adds a peer to the Gateway's peer list. The peer
	// may be rejected. AddPeer is also an RPC.
	AddPeer(NetAddress) error

	// RemovePeer removes a peer from the Gateway's peer list.
	RemovePeer(NetAddress) error

	// RandomPeer returns a random peer from the Gateway's peer list.
	RandomPeer() (NetAddress, error)

	// RPC establishes a connection to the supplied address and writes the RPC
	// header, indicating which function will handle the connection. The
	// supplied function takes over from there.
	RPC(NetAddress, string, RPCFunc) error

	// RegisterRPC registers a function to handle incoming connections that
	// supply the given RPC ID.
	RegisterRPC(string, RPCFunc)

	// Synchronize synchronizes the local consensus set with the set of the
	// given peer.
	Synchronize(NetAddress) error

	// RelayBlock broadcasts a block to the Gateway's peers.
	RelayBlock(consensus.Block)

	// RelayTransaction broadcasts a transaction to the Gateway's peers.
	RelayTransaction(consensus.Transaction)

	// Info reports metadata about the Gateway.
	Info() GatewayInfo
}

A Gateway facilitates the interactions between the local node and remote nodes (peers). It relays incoming blocks and transactions to local modules, and broadcasts outgoing blocks and transactions to peers. In a broad sense, it is responsible for ensuring that the local consensus set is consistent with the "network" consensus set.

type GatewayInfo

type GatewayInfo struct {
	Address NetAddress
	Peers   []NetAddress
}

type Host

type Host interface {
	// Announce announces the host on the blockchain.
	Announce(NetAddress) error

	// NegotiateContract is an RPC that enables a client to communicate with
	// the host to propose a contract.
	//
	// TODO: enhance this documentataion. For now, see the host package for a
	// reference implementation.
	NegotiateContract(NetConn) error

	// RetrieveFile is an RPC that enables a client to download a file from
	// the host.
	RetrieveFile(NetConn) error

	// SetConfig sets the hosting parameters of the host.
	SetSettings(HostSettings)

	// Settings is an RPC that returns the host's settings.
	Settings(NetConn) error

	// Info returns info about the host, including its hosting parameters, the
	// amount of storage remaining, and the number of active contracts.
	Info() HostInfo
}

type HostAnnouncement

type HostAnnouncement struct {
	IPAddress NetAddress
}

HostAnnouncements are stored in the Arbitrary Data section of transactions on the blockchain. They announce the willingness of a node to host files. Renters can contact the host privately to obtain more detailed hosting parameters (see HostSettings). To mitigate Sybil attacks, HostAnnouncements are paired with a volume of 'frozen' coins. The FreezeIndex indicates which output in the transaction contains the frozen coins, and the SpendConditions indicate the number of blocks the coins are frozen for.

type HostDB

type HostDB interface {
	// FlagHost alerts the HostDB that a host is not behaving as expected. The
	// HostDB may decide to remove the host, or just reduce the weight, or it
	// may decide to ignore the flagging. If the flagging is ignored, an error
	// will be returned explaining why.
	FlagHost(NetAddress) error

	// Insert adds a host to the database.
	Insert(HostEntry) error

	// NumHosts returns the number of hosts that are being selected from. The
	// renter uses this to make sure that the pool is big enough before
	// uploading a file.
	NumHosts() int

	// RandomHost pulls a host entry at random from the database, weighted
	// according to whatever score is assigned the hosts.
	RandomHost() (HostEntry, error)

	// Remove deletes the host with the given address from the database.
	Remove(NetAddress) error
}

type HostEntry

type HostEntry struct {
	HostSettings
	IPAddress NetAddress
}

A HostEntry is an entry in the HostDB. It contains the HostSettings, as well as the IP address where the host can be found, and the value of the coins frozen in the host's announcement transaction.

type HostInfo

type HostInfo struct {
	HostSettings

	StorageRemaining int64
	NumContracts     int
}

type HostSettings

type HostSettings struct {
	TotalStorage int64 // Can go negative.
	MinFilesize  uint64
	MaxFilesize  uint64
	MinDuration  consensus.BlockHeight
	MaxDuration  consensus.BlockHeight
	WindowSize   consensus.BlockHeight
	Price        consensus.Currency
	Collateral   consensus.Currency
	UnlockHash   consensus.UnlockHash
}

HostSettings are the parameters advertised by the host. These are the values that the HostDB will request from the host in order to build its database.

type NetAddress

type NetAddress string

A NetAddress contains the information needed to contact a peer.

func (NetAddress) Host

func (na NetAddress) Host() string

Host returns the NetAddress' IP.

func (NetAddress) Port

func (na NetAddress) Port() string

Port returns the NetAddress' port number.

type NetConn

type NetConn interface {
	io.ReadWriteCloser

	// ReadWriters support reading and writing objects, which are encoded and
	// decoded via the encoding package.
	encoding.ReadWriter

	// Addr returns the NetAddress of the remote end of the connection.
	Addr() NetAddress
}

A NetConn is a monitored network connection.

type RPCFunc

type RPCFunc func(NetConn) error

RPCFunc is the type signature of functions that handle incoming RPCs.

type RentInfo

type RentInfo struct {
	Files []string
}

RentInfo contains a list of all files by nickname. (deprecated)

type Renter

type Renter interface {
	// Download downloads a file to the given filepath.
	Download(nickname, filepath string) error

	// DownloadQueue lists all the files that have been scheduled for download.
	DownloadQueue() []DownloadInfo

	// FileList returns information on all of the files stored by the renter.
	FileList() []FileInfo

	// Info returns the list of all files by nickname. (deprecated)
	Info() RentInfo

	// Rename changes the nickname of a file.
	Rename(currentName, newName string) error

	// Upload uploads a file using the input parameters.
	Upload(UploadParams) error
}

A Renter uploads, tracks, repairs, and downloads a set of files for the user.

type TransactionPool

type TransactionPool interface {
	// AcceptTransaction takes a transaction, analyzes it, and either rejects
	// it or adds it to the transaction pool, returning an error if the
	// transaction is rejected.
	AcceptTransaction(consensus.Transaction) error

	// IsStandardTransaction returns `err = nil` if the transaction is
	// standard, otherwise it returns an error explaining what is not standard.
	IsStandardTransaction(consensus.Transaction) error

	// OutputDiffs returns the set of diffs that are in the transaction pool
	// but haven't been confirmed by a block yet.
	UnconfirmedSiacoinOutputDiffs() []consensus.SiacoinOutputDiff

	// TransactionSet will return a set of transactions not exceeding the block
	// size that can be inserted into a block in order.
	//
	// TransactionSet has special behavior, it will always update with the
	// state before returning anything. A function can safely update from both
	// the transaction pool and the state by read locking the state, then
	// updating from the transaction pool, then the state, and then unlocking
	// the state.
	TransactionSet() ([]consensus.Transaction, error)
}

type UploadParams

type UploadParams struct {
	Filename string
	Duration consensus.BlockHeight
	Nickname string
	Pieces   int
}

UploadParams contains the information used by the Renter to upload a file.

type Wallet

type Wallet interface {
	// Balance returns the total number of coins accessible to the wallet. If
	// full == true, the number of coins returned will also include coins that
	// have been spent in unconfirmed transactions.
	Balance(full bool) consensus.Currency

	// CoinAddress return an address into which coins can be paid.
	CoinAddress() (consensus.UnlockHash, consensus.UnlockConditions, error)

	// TimelockedCoinAddress returns an address that can only be spent after block `unlockHeight`.
	TimelockedCoinAddress(unlockHeight consensus.BlockHeight) (consensus.UnlockHash, consensus.UnlockConditions, error)

	// RegisterTransaction creates a transaction out of an existing transaction
	// which can be modified by the wallet, returning an id that can be used to
	// reference the transaction.
	RegisterTransaction(consensus.Transaction) (id string, err error)

	// FundTransaction will add `amount` to a transaction's inputs. The funded
	// transaction is returned with an error.
	FundTransaction(id string, amount consensus.Currency) (consensus.Transaction, error)

	// AddSiacoinInput adds a siacoin input to the transaction. When
	// 'SignTransaction' gets called, this input will be left unsigned. The
	// updated transaction is returned along with the index of the new siacoin
	// input within the transaction.
	AddSiacoinInput(id string, input consensus.SiacoinInput) (consensus.Transaction, uint64, error)

	// AddMinerFee adds a single miner fee of value `fee`. The transaction is
	// returned, along with the index that the added fee ended up at.
	AddMinerFee(id string, fee consensus.Currency) (consensus.Transaction, uint64, error)

	// AddOutput adds an output to a transaction. It returns the transaction
	// with index of the output that got added.
	AddOutput(id string, output consensus.SiacoinOutput) (consensus.Transaction, uint64, error)

	// AddFileContract adds a file contract to a transaction, returning the
	// transaction and the index that the file contract was put at.
	AddFileContract(id string, fc consensus.FileContract) (consensus.Transaction, uint64, error)

	// AddStorageProof adds a storage proof to a transaction, returning the
	// transaction and the index that the storage proof was put at.
	AddStorageProof(id string, sp consensus.StorageProof) (consensus.Transaction, uint64, error)

	// AddArbitraryData adds a byte slice to the arbitrary data section of the
	// transaction, returning the transaction and the index of the new
	// arbitrary data.
	AddArbitraryData(id string, arb string) (consensus.Transaction, uint64, error)

	// AddSignature adds a signature to the transaction, the signature should
	// already be valid, and shouldn't sign any of the inputs that were added
	// by calling 'FundTransaction'. The updated transaction and the index of
	// the new signature are returned.
	AddSignature(id string, sig consensus.TransactionSignature) (consensus.Transaction, uint64, error)

	// Sign transaction will sign the transaction associated with the id and
	// then return the transaction. If wholeTransaction is set to true, then
	// the wholeTransaction flag will be set in CoveredFields for each
	// signature. After being signed, the transaction is deleted from the
	// wallet and must be reregistered if more changes are to be made.
	SignTransaction(id string, wholeTransaction bool) (consensus.Transaction, error)

	Info() WalletInfo

	SpendCoins(amount consensus.Currency, dest consensus.UnlockHash) (consensus.Transaction, error)
}

Wallet in an interface that helps to build and sign transactions. The user can make a new transaction-in-progress by calling Register, and then can add outputs, fees, etc. This gives other modules full flexibility in creating dynamic transactions.

type WalletInfo

type WalletInfo struct {
	Balance      consensus.Currency
	FullBalance  consensus.Currency
	NumAddresses int
}

WalletInfo contains basic information about the wallet.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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