Documentation ¶
Index ¶
- Constants
- func NewDB(dataDir string, network string) (*sql.DB, error)
- func NewStorage(config storage.PortalStorageConfig, db *sql.DB) (storage.ContentStorage, error)
- type ContentStorage
- func (p *ContentStorage) Close() error
- func (p *ContentStorage) ContentCount() (uint64, error)
- func (p *ContentStorage) ContentSize() (uint64, error)
- func (p *ContentStorage) EstimateNewRadius(currentRadius *uint256.Int) (*uint256.Int, error)
- func (p *ContentStorage) ForcePrune(radius *uint256.Int) error
- func (p *ContentStorage) Get(contentKey []byte, contentId []byte) ([]byte, error)
- func (p *ContentStorage) GetLargestDistance() (*uint256.Int, error)
- func (p *ContentStorage) Put(contentKey []byte, contentId []byte, content []byte) error
- func (p *ContentStorage) Radius() *uint256.Int
- func (p *ContentStorage) ReclaimSpace() error
- func (p *ContentStorage) Size() (uint64, error)
- func (p *ContentStorage) SizeByKey(contentId []byte) (uint64, error)
- func (p *ContentStorage) SizeByKeys(ids [][]byte) (uint64, error)
- func (p *ContentStorage) SizeOutRadius(radius *uint256.Int) (uint64, error)
- func (p *ContentStorage) UnusedSize() (uint64, error)
- func (p *ContentStorage) UsedSize() (uint64, error)
- type PutResult
Constants ¶
const (
XorFindFarthestQuery = `SELECT
xor(key, (?1)) as distance
FROM kvstore
ORDER BY distance DESC`
)
Variables ¶
This section is empty.
Functions ¶
func NewStorage ¶
func NewStorage(config storage.PortalStorageConfig, db *sql.DB) (storage.ContentStorage, error)
Types ¶
type ContentStorage ¶
type ContentStorage struct {
// contains filtered or unexported fields
}
func (*ContentStorage) Close ¶
func (p *ContentStorage) Close() error
func (*ContentStorage) ContentCount ¶
func (p *ContentStorage) ContentCount() (uint64, error)
ContentCount return the total content count
func (*ContentStorage) ContentSize ¶
func (p *ContentStorage) ContentSize() (uint64, error)
func (*ContentStorage) EstimateNewRadius ¶
EstimateNewRadius calculates an estimated new radius based on the current radius, used size, and storage capacity. The method takes the currentRadius as input and returns the estimated new radius and an error (if any). It calculates the size ratio of usedSize to storageCapacityInBytes and adjusts the currentRadius accordingly. If the size ratio is greater than 0, it performs the adjustment; otherwise, it returns the currentRadius unchanged. The method returns an error if there is any issue in determining the used size.
func (*ContentStorage) ForcePrune ¶
func (p *ContentStorage) ForcePrune(radius *uint256.Int) error
ForcePrune delete the content which distance is further than the given radius
func (*ContentStorage) Get ¶
func (p *ContentStorage) Get(contentKey []byte, contentId []byte) ([]byte, error)
Get the content according to the contentId
func (*ContentStorage) GetLargestDistance ¶
func (p *ContentStorage) GetLargestDistance() (*uint256.Int, error)
GetLargestDistance find the largest distance
func (*ContentStorage) Put ¶
func (p *ContentStorage) Put(contentKey []byte, contentId []byte, content []byte) error
func (*ContentStorage) Radius ¶
func (p *ContentStorage) Radius() *uint256.Int
func (*ContentStorage) ReclaimSpace ¶
func (p *ContentStorage) ReclaimSpace() error
ReclaimSpace reclaims space in the ContentStorage's SQLite database by performing a VACUUM operation. It returns an error if the VACUUM operation encounters any issues.
func (*ContentStorage) Size ¶
func (p *ContentStorage) Size() (uint64, error)
Size get database size, content size and similar
func (*ContentStorage) SizeByKey ¶
func (p *ContentStorage) SizeByKey(contentId []byte) (uint64, error)
func (*ContentStorage) SizeByKeys ¶
func (p *ContentStorage) SizeByKeys(ids [][]byte) (uint64, error)
func (*ContentStorage) SizeOutRadius ¶
func (p *ContentStorage) SizeOutRadius(radius *uint256.Int) (uint64, error)
func (*ContentStorage) UnusedSize ¶
func (p *ContentStorage) UnusedSize() (uint64, error)
func (*ContentStorage) UsedSize ¶
func (p *ContentStorage) UsedSize() (uint64, error)
UsedSize = Size - UnusedSize