pool

package
v0.0.0-...-cba2ebf Latest Latest
Warning

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

Go to latest
Published: Feb 8, 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 IdentityFolder = "identities"
View Source
const SafeConfigFile = ".safepool-pool.json"

Variables

View Source
var CachePath string
View Source
var CacheSizeMB = 16
View Source
var Connections = map[string]transport.Exchanger{}
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 ErrInvalidSignature = errors.New("signature is invalid")
View Source
var ErrInvalidToken = errors.New("provided token is invalid: missing name or configs")
View Source
var ErrNoExchange = errors.New("no Exchange available")
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 = time.Hour //30 * 24 * time.Hour

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

View Source
var ReplicaPeriod = time.Hour

Functions

func Define

func Define(c Config) error

func EncodeToken

func EncodeToken(t Token, guestId string) (string, error)

func List

func List() []string

func Save

func Save(name string, config Config) error

Types

type AcceptFunc

type AcceptFunc func(feed Feed)

type Access

type Access struct {
	Id      string
	State   State
	ModTime time.Time
}

type AccessFile

type AccessFile struct {
	Version     float32
	AccessKeys  []AccessKey
	Nonce       []byte
	MasterKeyId uint64
	Keystore    []byte
	Apps        []string
}

type AccessKey

type AccessKey struct {
	Access Access
	Key    []byte
}

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
	Public  []string
	Private []string
}

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 Feed) bool
}

type Feed

type Feed struct {
	Id        uint64
	Name      string
	Size      int64
	Hash      []byte
	ModTime   time.Time
	AuthorId  string
	Signature []byte
	Meta      []byte
	Offset    int    `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 Identity

type Identity struct {
	security.Identity
	//Since is the keyId used when the identity was added to the Pool access
	Since uint64
	//AddedOn is the timestamp when the identity is stored on the local DB
	AddedOn time.Time
}

type Keystore

type Keystore map[uint64][]byte

type Pool

type Pool struct {
	Name    string            `json:"name"`
	Self    security.Identity `json:"self"`
	Apps    []string          `json:"apps"`
	Trusted bool              `json:"trusted"`
	// contains filtered or unexported fields
}

func Create

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

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) CreateBranch

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

func (*Pool) Delete

func (p *Pool) Delete() 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) Identities

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

func (*Pool) List

func (p *Pool) List(offset int) ([]Feed, error)

func (*Pool) Receive

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

func (*Pool) Send

func (p *Pool) Send(name string, r io.Reader, meta []byte) (Feed, error)

func (*Pool) SetAccess

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

func (*Pool) Sync

func (p *Pool) Sync() error

func (*Pool) ToString

func (p *Pool) ToString() string

type State

type State int
const (
	Disabled State = iota
	Active
)

type Token

type Token struct {
	Config Config
	Host   security.Identity
}

func DecodeToken

func DecodeToken(guest security.Identity, token string) (Token, error)

Jump to

Keyboard shortcuts

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