storage

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolID represents the response protocol id and version.
	ProtocolID = "/ffg/storagequery_response/1.0.0"
	// DiscoveredPeersProtocolID is a discovered peer protocol id and version.
	DiscoveredPeersProtocolID = "/ffg/disc_peers/1.0.0"
	// SpeedTestProtocolID is a speed test protocol id and version.
	SpeedTestProtocolID = "/ffg/storage_speed/1.0.0"
	// FileUploadProtocolID is a file upload protocol id and version.
	FileUploadProtocolID = "/ffg/storage_upload/1.0.0"
	// StorageCapabilitiesProtocolID is a protocol to indicate the capabilities of a storage node.
	StorageCapabilitiesProtocolID = "/ffg/storage_cap/1.0.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GeoIPLocator added in v1.1.19

type GeoIPLocator interface {
	Country(ipAddress net.IP) (*geoip2.Country, error)
}

GeoIPLocator given an ip address it returns the country info.

type Interface

type Interface interface {
	SendStorageQueryResponse(ctx context.Context, peerID peer.ID, payload *messages.StorageQueryResponseProto) error
	GetDiscoveredStorageProviders() []ProviderWithCountry
	TestSpeedWithRemotePeer(ctx context.Context, peerID peer.ID, fileSize uint64) (time.Duration, error)
	UploadFileWithMetadata(ctx context.Context, peerID peer.ID, filePath string, publicKeyOwner []byte, feesPerByte string) (storage.FileMetadata, error)
	GetUploadProgress(peerID peer.ID, filePath string) (int, string, error)
	SetUploadingStatus(peerID peer.ID, filePath, fileHash string, err error)
	SetCancelFileUpload(peerID peer.ID, filePath string, cancelled bool, cancel context.CancelFunc)
	GetCancelFileUploadStatus(peerID peer.ID, filePath string) (bool, context.CancelFunc)
	ResetProgressAndCancelStatus(peerID peer.ID, filePath string)
	SendDiscoveredStorageTransferRequest(ctx context.Context, peerID peer.ID) (int, error)
	GetStorageCapabilities(ctx context.Context, peerID peer.ID) (*messages.StorageCapabilitiesProto, error)
}

Interface represents a set of functionalities by the storage query.

type Protocol

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

Protocol wraps the storage protocols and handlers.

func New

func New(h host.Host, storage storage.Interface, ipLocator GeoIPLocator, storagePublic bool, uptime int64, allowFeesOverride bool, feesPerByte string, showStorageCapacity bool) (*Protocol, error)

New creates a storage protocol.

func (*Protocol) GetCancelFileUploadStatus added in v1.1.26

func (p *Protocol) GetCancelFileUploadStatus(peerID peer.ID, filePath string) (bool, context.CancelFunc)

GetCancelFileUploadStatus returns the status of a cancelled file upload.

func (*Protocol) GetDiscoveredStorageProviders

func (p *Protocol) GetDiscoveredStorageProviders() []ProviderWithCountry

GetDiscoveredStorageProviders returns a list of discovered storage providers.

func (*Protocol) GetStorageCapabilities added in v1.3.0

func (p *Protocol) GetStorageCapabilities(ctx context.Context, peerID peer.ID) (*messages.StorageCapabilitiesProto, error)

GetStorageCapabilities sends a request to remote peer to get its storage capabilities.

func (*Protocol) GetUploadProgress

func (p *Protocol) GetUploadProgress(peerID peer.ID, filePath string) (int, string, error)

GetUploadProgress returns the number of bytes transferred to the remote node.

func (*Protocol) HandleIncomingFileUploads

func (p *Protocol) HandleIncomingFileUploads(s network.Stream)

HandleIncomingFileUploads handles incoming file uploads.

func (*Protocol) ResetProgressAndCancelStatus added in v1.1.26

func (p *Protocol) ResetProgressAndCancelStatus(peerID peer.ID, filePath string)

ResetProgressAndCancelStatus resets the upload progress and if a previous cancellation was there, deletes it.

func (*Protocol) SendDiscoveredStorageTransferRequest added in v1.1.29

func (p *Protocol) SendDiscoveredStorageTransferRequest(ctx context.Context, peerID peer.ID) (int, error)

SendDiscoveredStorageTransferRequest sends a request to remote peer to get its discovered storage peers. it returns the number of peers transferred.

func (*Protocol) SendStorageQueryResponse

func (p *Protocol) SendStorageQueryResponse(ctx context.Context, peerID peer.ID, payload *messages.StorageQueryResponseProto) error

SendStorageQueryResponse sends back the storage query response to initiator.

func (*Protocol) SetCancelFileUpload added in v1.1.26

func (p *Protocol) SetCancelFileUpload(peerID peer.ID, filePath string, cancelled bool, cancel context.CancelFunc)

SetCancelFileUpload sets a cancel file upload.

func (*Protocol) SetUploadingStatus added in v1.1.17

func (p *Protocol) SetUploadingStatus(peerID peer.ID, filePath, fileHash string, err error)

SetUploadingStatus sets an error or fhash if upload failed or completed.

func (*Protocol) TestSpeedWithRemotePeer

func (p *Protocol) TestSpeedWithRemotePeer(ctx context.Context, peerID peer.ID, fileSize uint64) (time.Duration, error)

TestSpeedWithRemotePeer performs a speed test with a remote node.

func (*Protocol) UploadFileWithMetadata

func (p *Protocol) UploadFileWithMetadata(ctx context.Context, peerID peer.ID, filePath string, publicKeyOwner []byte, feesPerByte string) (storage.FileMetadata, error)

UploadFileWithMetadata uploads a file content, its name and if its associated with a channel node item.

type ProviderWithCountry added in v1.1.19

type ProviderWithCountry struct {
	Country  *geoip2.Country                     `json:"country"`
	Response *messages.StorageQueryResponseProto `json:"response"`
}

ProviderWithCountry contain the response and the country if available.

Jump to

Keyboard shortcuts

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