storage

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AdminAccess represents full access.
	AdminAccess = "admin"
	// UserAccess represents privilege access.
	UserAccess = "user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	AccessType string `json:"access_type"`
	Token      string `json:"token"`
	ExpiresAt  int64  `json:"expires_at"`
}

AccessToken represents an access token.

type CreateStorageAccessTokenRequest added in v1.3.0

type CreateStorageAccessTokenRequest struct {
	UserAccessType string `json:"user_access_type"`
}

CreateStorageAccessTokenRequest represents the request for creating a new storage token.

type FileMetadata

type FileMetadata struct {
	FileName       string `json:"file_name"`
	MerkleRootHash string `json:"merkle_root_hash"`
	Hash           string `json:"hash"`
	FilePath       string `json:"file_path"`
	Size           int64  `json:"size"`
	RemotePeer     string `json:"remote_peer"`
	Timestamp      int64  `json:"timestamp"`
	FeesPerByte    string `json:"fees_per_byte"`
	PublicKeyOwner string `json:"public_key_owner"`
}

FileMetadata holds the metadata for a file.

type FileMetadataWithDBKey added in v1.1.29

type FileMetadataWithDBKey struct {
	FileMetadata
	Key              string `json:"key"`
	FileExistsOnNode bool   `json:"file_exists_on_node"`
}

FileMetadataWithDBKey holds the file metatada and the key.

type Interface

type Interface interface {
	StoragePath() string
	Enabled() bool
	SetEnabled(val bool)
	CreateSubfolders() (string, error)
	SaveToken(token AccessToken) error
	SaveFileMetadata(fileHash, peerID string, metadata FileMetadata) error
	DeleteFileMetadata(fileHash, peerID string) error
	GetFileMetadata(fileHash string, peerID string) (FileMetadata, error)
	CanAccess(token string) (bool, AccessToken, error)
	HandleIncomingFileUploads(stream network.Stream)
	ListFiles(currentPage, pageSize int, order string) ([]FileMetadataWithDBKey, uint64, error)
	DeleteFileFromDB(key string) error
	ExportFiles() ([]FileMetadataWithDBKey, error)
	ImportFiles(string) (int, error)
}

Interface defines the functionalities of the storage engine.

type IntrospectAccessTokenResponse added in v1.3.0

type IntrospectAccessTokenResponse struct {
	AccessToken       AccessToken `json:"access_token"`
	AllowFeesOverride bool        `json:"allow_fees_override"`
	Platform          string      `json:"platform"`
	FeesPerByte       string      `json:"fees_per_byte"`
	PublicKey         string      `json:"public_key"`
	StorageCapacity   uint64      `json:"storage_capacity"`
	PeerID            string      `json:"storage_provider_peer_addr"`
	UptimeSeconds     int64       `json:"uptime_seconds"`
}

IntrospectAccessTokenResponse contains the token info and some info about the storage node.

type Storage

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

Storage represents the storage engine and the metadata.

func New

func New(db database.Database, storagePath string, enabled bool, adminToken string, merkleTreeTotalSegments int, peerID string, allowFeesOverride bool, publicKey, feesPerByte string, uptime int64) (*Storage, error)

New creates a new storage instance.

func (*Storage) CanAccess

func (s *Storage) CanAccess(token string) (bool, AccessToken, error)

CanAccess authorizes access.

func (*Storage) CreateStorageAccessToken added in v1.3.0

func (s *Storage) CreateStorageAccessToken(w http.ResponseWriter, r *http.Request)

CreateStorageAccessToken creates a storage access token.

func (*Storage) CreateSubfolders

func (s *Storage) CreateSubfolders() (string, error)

CreateSubfolders creates sub folders with current date inside the data directory.

func (*Storage) DeleteFileFromDB added in v1.1.29

func (s *Storage) DeleteFileFromDB(key string) error

DeleteFileFromDB deletes a file from local db.

func (*Storage) DeleteFileMetadata added in v1.2.1

func (s *Storage) DeleteFileMetadata(fileHash, peerID string) error

DeleteFileMetadata deletes the metadata from the db.

func (*Storage) Enabled

func (s *Storage) Enabled() bool

Enabled return if storage functionality is enabled.

func (*Storage) ExportFiles added in v1.2.1

func (s *Storage) ExportFiles() ([]FileMetadataWithDBKey, error)

ExportFiles gets all the uploaded files.

func (*Storage) GetFileMetadata

func (s *Storage) GetFileMetadata(fileHash string, peerID string) (FileMetadata, error)

GetFileMetadata gets a file's metadata in the database.

func (*Storage) GetTotalFilesStored added in v1.1.20

func (s *Storage) GetTotalFilesStored() uint64

GetTotalFilesStored returns the total number of files stored on this node.

func (*Storage) HandleIncomingFileUploads added in v1.1.16

func (s *Storage) HandleIncomingFileUploads(stream network.Stream)

ServeHTTP handles file uploading.

func (*Storage) ImportFiles added in v1.2.1

func (s *Storage) ImportFiles(importedFile string) (int, error)

ImportFiles gets all the uploaded files list

func (*Storage) IntrospectAccessToken added in v1.3.0

func (s *Storage) IntrospectAccessToken(w http.ResponseWriter, r *http.Request)

IntrospectAccessToken returns the payload of an access token.

func (*Storage) ListFiles added in v1.1.19

func (s *Storage) ListFiles(currentPage, pageSize int, order string) ([]FileMetadataWithDBKey, uint64, error)

ListFiles the uploaded files.

func (*Storage) SaveFileMetadata

func (s *Storage) SaveFileMetadata(fileHash, peerID string, metadata FileMetadata) error

SaveFileMetadata saves a file's metadata in the database.

func (*Storage) SaveToken

func (s *Storage) SaveToken(token AccessToken) error

SaveToken saves an access token into the database.

func (*Storage) ServeHTTP

func (s *Storage) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles file uploading.

func (*Storage) SetEnabled

func (s *Storage) SetEnabled(val bool)

SetEnabled return if storage functionality is enabled.

func (*Storage) StoragePath

func (s *Storage) StoragePath() string

StoragePath return the storage path.

Jump to

Keyboard shortcuts

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