skyd

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSkylinkAlreadyPinned is returned when the skylink we're trying to pin
	// is already pinned.
	ErrSkylinkAlreadyPinned = errors.New("skylink already pinned")
	// ErrSkylinkIsBlocked is returned when the skylinks we're trying to pin is
	// blocked by skyd.
	ErrSkylinkIsBlocked = errors.New("skylink is blocked")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	// Blocklist gets the list of blocked skylinks.
	Blocklist() (blocklist api.SkynetBlocklistGET, err error)
	// ContractData returns the total data from Active and Passive contracts.
	ContractData() (uint64, error)
	// DiffPinnedSkylinks returns two lists of skylinks - the ones that
	// belong to the given list but are not pinned by skyd (unknown) and the
	// ones that are pinned by skyd but are not on the list (missing).
	DiffPinnedSkylinks(skylinks []string) (unknown []string, missing []string)
	// FileHealth returns the health of the given sia file.
	// Perfect health is 0.
	FileHealth(sp skymodules.SiaPath) (float64, error)
	// Metadata returns the metadata of the skylink
	Metadata(skylink string) (skymodules.SkyfileMetadata, error)
	// Pin instructs the local skyd to pin the given skylink.
	Pin(skylink string) (skymodules.SiaPath, error)
	// RebuildCache rebuilds the cache of skylinks pinned by the local skyd.
	RebuildCache() RebuildCacheResult
	// RenterDirRootGet is a direct proxy to the skyd client method with the
	// same name.
	RenterDirRootGet(siaPath skymodules.SiaPath) (rd api.RenterDirectory, err error)
	// Resolve resolves a V2 skylink to a V1 skylink. Returns an error if
	// the given skylink is not V2.
	Resolve(skylink string) (string, error)
	// Unpin instructs the local skyd to unpin the given skylink.
	Unpin(skylink string) error
}

Client describes the interface exposed by client.

func NewClient

func NewClient(host, port, password string, cache *PinnedSkylinksCache, logger logger.Logger) Client

NewClient creates a new skyd client.

type ClientMock added in v0.1.0

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

ClientMock is a mock of skyd.Client

func NewSkydClientMock added in v0.1.0

func NewSkydClientMock() *ClientMock

NewSkydClientMock returns an initialised copy of ClientMock

func (*ClientMock) Blocklist added in v0.6.1

func (c *ClientMock) Blocklist() (blocklist api.SkynetBlocklistGET, err error)

Blocklist gets the list of blocked skylinks. Noop.

func (*ClientMock) ContractData added in v0.6.0

func (c *ClientMock) ContractData() (uint64, error)

ContractData returns the total data from Active and Passive contracts.

func (c *ClientMock) DiffPinnedSkylinks(skylinks []string) (unknown []string, missing []string)

DiffPinnedSkylinks is a carbon copy of PinnedSkylinksCache's version of the method.

func (*ClientMock) FileHealth added in v0.1.0

func (c *ClientMock) FileHealth(sp skymodules.SiaPath) (float64, error)

FileHealth returns the health of the given skylink. Note that the mock will return 0 (fully healthy) by default.

func (*ClientMock) IsPinning added in v0.1.0

func (c *ClientMock) IsPinning(skylink string) bool

IsPinning checks whether skyd is pinning the given skylink.

func (*ClientMock) Metadata added in v0.1.0

func (c *ClientMock) Metadata(skylink string) (skymodules.SkyfileMetadata, error)

Metadata returns the metadata of the skylink or the pre-set error.

func (*ClientMock) MockFilesystem added in v0.1.0

func (c *ClientMock) MockFilesystem() []string

MockFilesystem returns an initialised NodeSkydClientMock and a list of all skylinks contained in it.

The mocked structure is the following:

SkynetFolder/ (three dirs, one file)

dirA/ (two files, one skylink each)
   fileA1 (CAClyosjvI9Fg75N-LRylcfba79bam9Ljp-4qfxS08Q_A1)
   fileA2 (CAClyosjvI9Fg75N-LRylcfba79bam9Ljp-4qfxS08Q_A2)
dirB/ (one file, one dir)
   dirC/ (one file, two skylinks)
      fileC (CAClyosjvI9Fg75N-LRylcfba79bam9Ljp-4qfxS08Q_C1, C2_uSb3BpGxmSbRAg1xj5T8SdB4hiSFiEW2sEEzxt5MNkg)
   fileB (CAClyosjvI9Fg75N-LRylcfba79bam9Ljp-4qfxS08Q__B)
dirD/ (empty)
file (CAClyosjvI9Fg75N-LRylcfba79bam9Ljp-4qfxS08Q___)

func (*ClientMock) Pin added in v0.1.0

func (c *ClientMock) Pin(skylink string) (skymodules.SiaPath, error)

Pin mocks a pin action and responds with a predefined error. If the predefined error is nil, it adds the given skylink to the list of skylinks pinned in the mock.

func (*ClientMock) RebuildCache added in v0.1.0

func (c *ClientMock) RebuildCache() RebuildCacheResult

RebuildCache is a noop mock that takes at least 100ms.

func (*ClientMock) RenterDirRootGet added in v0.1.0

func (c *ClientMock) RenterDirRootGet(siaPath skymodules.SiaPath) (rd api.RenterDirectory, err error)

RenterDirRootGet is a functional mock.

func (*ClientMock) Resolve added in v0.1.0

func (c *ClientMock) Resolve(skylink string) (string, error)

Resolve is a noop mock.

func (*ClientMock) SetBlocklist added in v0.6.1

func (c *ClientMock) SetBlocklist(bl api.SkynetBlocklistGET)

SetBlocklist allows us to set the blocklist.

func (*ClientMock) SetContractData added in v0.6.0

func (c *ClientMock) SetContractData(n uint64)

SetContractData sets the contract data value returned by the mock.

func (*ClientMock) SetHealth added in v0.6.0

func (c *ClientMock) SetHealth(sp skymodules.SiaPath, h float64)

SetHealth allows us to set the health of a sia file.

func (*ClientMock) SetMapping added in v0.1.0

func (c *ClientMock) SetMapping(siaPath skymodules.SiaPath, rdrt RDReturnType)

SetMapping allows us to set the state of the filesystem mock.

func (*ClientMock) SetMetadata added in v0.1.0

func (c *ClientMock) SetMetadata(skylink string, meta skymodules.SkyfileMetadata, err error)

SetMetadata sets the metadata or error returned when fetching metadata for a given skylink. If both are provided the error takes precedence.

func (*ClientMock) SetPinError added in v0.1.0

func (c *ClientMock) SetPinError(e error)

SetPinError sets the pin error

func (*ClientMock) SetUnpinError added in v0.1.0

func (c *ClientMock) SetUnpinError(e error)

SetUnpinError sets the unpin error

func (c *ClientMock) Skylinks() []string

Skylinks returns a list of all skylinks being held by this mock.

func (*ClientMock) Unpin added in v0.1.0

func (c *ClientMock) Unpin(skylink string) error

Unpin mocks an unpin action and responds with a predefined error. If the error is nil, Unpin removes the skylink from the list of pinned skylinks.

type PinnedSkylinksCache added in v0.1.0

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

PinnedSkylinksCache is a simple cache of the renter's directory information, so we don't need to fetch that for each skylink we potentially want to pin/unpin.

func NewCache added in v0.1.0

func NewCache() *PinnedSkylinksCache

NewCache returns a new cache instance.

func (*PinnedSkylinksCache) Add added in v0.1.0

func (psc *PinnedSkylinksCache) Add(skylinks ...string)

Add registers the given skylinks in the cache.

func (*PinnedSkylinksCache) Contains added in v0.1.0

func (psc *PinnedSkylinksCache) Contains(skylink string) bool

Contains returns true when the given skylink is in the cache.

func (*PinnedSkylinksCache) Diff added in v0.1.0

func (psc *PinnedSkylinksCache) Diff(sls []string) (unknown []string, missing []string)

Diff returns two lists of skylinks - the ones that are in the given list but are not in the cache (missing) and the ones that are in the cache but are not in the given list (removed).

func (*PinnedSkylinksCache) Rebuild added in v0.1.0

func (psc *PinnedSkylinksCache) Rebuild(skydClient Client) RebuildCacheResult

Rebuild rebuilds the cache of skylinks pinned by the local skyd. The rebuilding happens in a goroutine, allowing the method to return a channel on which the caller can either wait or select. The caller can check whether the rebuild was successful by calling Error().

func (*PinnedSkylinksCache) Remove added in v0.1.0

func (psc *PinnedSkylinksCache) Remove(skylinks ...string)

Remove removes the given skylinks in the cache.

type RDReturnType added in v0.7.6

type RDReturnType struct {
	RD  api.RenterDirectory
	Err error
}

RDReturnType describes the return values of RenterDirRootGet and allows us to build a directory structure representation in NodeSkydClientMock.

type RebuildCacheResult added in v0.1.0

type RebuildCacheResult struct {
	// ErrAvail indicates the status of the cache rebuild progress -
	// if it's not closed then the rebuild is still in progress. We expose
	// it as a <-chan, so the receiver cannot close it.
	ErrAvail <-chan struct{}
	// ExternErr holds the error state of the cache rebuild process. It must
	// only be read after ErrAvail is closed.
	ExternErr error
	// contains filtered or unexported fields
}

RebuildCacheResult informs the caller on the status of a cache rebuild. The error should not be read before the channel is closed.

func NewRebuildCacheResult added in v0.2.0

func NewRebuildCacheResult() *RebuildCacheResult

NewRebuildCacheResult returns a new RebuildCacheResult

Jump to

Keyboard shortcuts

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