pool

package
v0.0.0-...-8027ee6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 28 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ID_CREATE       = 0x0
	ID_FORCE_CREATE = 0x1
)
View Source
const All = ""
View Source
const FeedsFolder = "feeds"
View Source
const SyncAccessFrequency = 5 * time.Minute

Variables

View Source
var CachePath string
View Source
var CacheSizeMB = 16
View Source
var Connections = map[string]storage.Storage{}
View Source
var ConnectionsMutex = &sync.Mutex{}
View Source
var ErrAlreadyExist = errors.New("pool already exists")
View Source
var ErrInvalidConfig = errors.New("provided config is invalid: missing name or configs")
View Source
var ErrInvalidId = errors.New("provided id not a valid ed25519 public key")
View Source
var ErrInvalidName = errors.New("provided pool has invalid name")
View Source
var ErrInvalidToken = errors.New("provided token is invalid: missing name or configs")
View Source
var ErrNoStorage = errors.New("no Storage available")
View Source
var ErrNoSyncClock = errors.New("cannot sync with global time server")
View Source
var ErrNotAuthorized = errors.New("no authorization for this file")
View Source
var ErrNotTrusted = errors.New("the author is not a trusted user")
View Source
var FeedDateFormat = "20060102"
View Source
var ForceCreation = false
View Source
var LifeSpan = 30 * 24 * time.Hour

LifeSpan is the maximal time data should stay in the pool. It is default to 30 days.

Functions

func Define

func Define(c Config) error

func List

func List() []string

func Save

func Save(name string, config Config) error

Types

type AcceptFunc

type AcceptFunc func(feed Head)

type Access

type Access struct {
	UserId string    `json:"userId"`
	State  State     `json:"state"`
	Since  time.Time `json:"since"`
}

type AccessFile

type AccessFile struct {
	Id          uint64      `json:"id"`
	Version     float32     `json:"version"`
	PoolId      uint64      `json:"poolId"`
	Keys        []AccessKey `json:"keys"`
	Nonce       []byte      `json:"nonce"`
	MasterKeyId uint64      `json:"masterKeyId"`
	Keystore    []byte      `json:"keystore"`
	Apps        []string    `json:"apps"`
}

type AccessKey

type AccessKey struct {
	UserId string    `json:"userId"`
	Value  []byte    `json:"key"`
	Since  time.Time `json:"since"`
}

type Bandwidth

type Bandwidth int
const (
	LowBandwidth Bandwidth = iota
	MediumBandwidth
	HighBandwith
)
var AvailableBandwidth Bandwidth = HighBandwith

type CacheWriter

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

func (*CacheWriter) Close

func (c *CacheWriter) Close()

func (*CacheWriter) Write

func (c *CacheWriter) Write(p []byte) (n int, err error)

type Config

type Config struct {
	Name          string   `json:"name"`
	Public        []string `json:"public"`
	Private       []string `json:"private"`
	Apps          []string `json:"apps"`
	LifeSpanHours int      `json:"lifeSpan"`
}

func GetConfig

func GetConfig(name string) (Config, error)

func Load

func Load(name string) (Config, error)

type Consumer

type Consumer interface {
	TimeOffset(s *Pool) time.Time
	Accept(s *Pool, h Head) bool
}
type Head struct {
	Id        uint64    `json:"id"`
	Name      string    `json:"name"`
	Size      int64     `json:"size"`
	Hash      []byte    `json:"hash"`
	ModTime   time.Time `json:"modTime"`
	AuthorId  string    `json:"authorId"`
	Signature []byte    `json:"signature"`
	Meta      []byte    `json:"meta"`
	CTime     int64     `json:"-"`
	Slot      string    `json:"-"`
}
type Header struct {
	Version float32 `json:"v"`
	Thread  uint64  `json:"t"`
	Key     uint64  `json:"k"`
	Hash    []byte  `json:"h"`
	Name    string  `json:"s"`
}

type Keystore

type Keystore map[uint64][]byte

type Pool

type Pool struct {
	Name          string            `json:"name"`
	Id            uint64            `json:"id"`
	Self          security.Identity `json:"self"`
	Apps          []string          `json:"apps"`
	LifeSpanHours int               `json:"lifeSpanHours"`
	Trusted       bool              `json:"trusted"`
	Connection    string            `json:"connection"`
	// contains filtered or unexported fields
}

func Create

func Create(self security.Identity, name string, apps []string) (*Pool, error)

Create creates a new pool on the defined exchanges

func Open

func Open(self security.Identity, name string) (*Pool, error)

Init initialized a domain on the specified exchangers

func (*Pool) BaseId

func (p *Pool) BaseId() uint64

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) Delete

func (p *Pool) Delete()

func (*Pool) Dump

func (p *Pool) Dump() map[string]any

func (*Pool) ExportSelf

func (p *Pool) ExportSelf(force bool) error

func (*Pool) HouseKeeping

func (p *Pool) HouseKeeping()

HouseKeeping removes old files from the pool. It is called automatically when you use Sync after an hour; use explicitly only when your application does not use sync or does not live longer than 1 hour

func (*Pool) Leave

func (p *Pool) Leave() error

func (*Pool) List

func (p *Pool) List(ctime int64) ([]Head, error)

func (*Pool) Receive

func (p *Pool) Receive(id uint64, rang *storage.Range, w io.Writer) error

func (*Pool) Send

func (p *Pool) Send(name string, r io.ReadSeekCloser, size int64, meta []byte) (Head, error)

func (*Pool) SetAccess

func (p *Pool) SetAccess(userId string, state State) error

func (*Pool) Sub

func (p *Pool) Sub(sub string, ids []string, apps []string) (Config, error)

func (*Pool) Sync

func (p *Pool) Sync() ([]Head, error)

func (*Pool) SyncAccess

func (p *Pool) SyncAccess(ignoreGuard bool) error

func (*Pool) ToString

func (p *Pool) ToString() string

func (*Pool) Users

func (p *Pool) Users() ([]security.Identity, error)

type State

type State int
const (
	Disabled State = iota
	Active
)

Jump to

Keyboard shortcuts

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