Stash
import "github.com/eljojo/nara/services/stash"- type EncryptedStash
- type Service
- func NewService() *Service
- func (s *Service) ClearMyStash()
- func (s *Service) Confidants() []types.NaraID
- func (s *Service) DistributeToConfidants() error
- func (s *Service) GetStashData() (data []byte, timestamp int64)
- func (s *Service) GetStoredStash(ownerID types.NaraID) *EncryptedStash
- func (s *Service) HasStashData() bool
- func (s *Service) HasStashFor(ownerID types.NaraID) bool
- func (s *Service) Init() error
- func (s *Service) MarshalState() ([]byte, error)
- func (s *Service) Name() string
- func (s *Service) PushTo(ownerID types.NaraID) error
- func (s *Service) RecoverFromAny() ([]byte, error)
- func (s *Service) RegisterBehaviors(rt runtime.RuntimeInterface)
- func (s *Service) RequestFrom(confidantID types.NaraID) ([]byte, error)
- func (s *Service) SelectConfidantsAutomatically() error
- func (s *Service) SetConfidants(confidantIDs []types.NaraID)
- func (s *Service) SetStashData(data []byte) error
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) StorageLimit() int
- func (s *Service) StoreWith(confidantID types.NaraID, data []byte) error
- func (s *Service) StoredCount() int
- func (s *Service) TargetConfidants() int
type EncryptedStash
Section titled “type EncryptedStash”EncryptedStash is what we store for other naras.
type EncryptedStash struct { OwnerID types.NaraID Nonce []byte Ciphertext []byte StoredAt time.Time}type Service
Section titled “type Service”Service implements distributed encrypted storage (stash).
Naras store their encrypted state with trusted peers (confidants) instead of on disk. Only the owner can decrypt, but confidants hold the ciphertext.
type Service struct { runtime.ServiceBase // Provides RT and Log (auto-populated by runtime) // contains filtered or unexported fields}func NewService
Section titled “func NewService”func NewService() *ServiceNewService creates a new stash service.
func (*Service) ClearMyStash
Section titled “func (*Service) ClearMyStash”func (s *Service) ClearMyStash()ClearMyStash clears the local stash data (used for testing restart scenarios).
func (*Service) Confidants
Section titled “func (*Service) Confidants”func (s *Service) Confidants() []types.NaraIDfunc (*Service) DistributeToConfidants
Section titled “func (*Service) DistributeToConfidants”func (s *Service) DistributeToConfidants() errorDistributeToConfidants distributes the current stash to all configured confidants.
func (*Service) GetStashData
Section titled “func (*Service) GetStashData”func (s *Service) GetStashData() (data []byte, timestamp int64)GetStashData returns the current stash data.
func (*Service) GetStoredStash
Section titled “func (*Service) GetStoredStash”func (s *Service) GetStoredStash(ownerID types.NaraID) *EncryptedStashfunc (*Service) HasStashData
Section titled “func (*Service) HasStashData”func (s *Service) HasStashData() boolHasStashData returns true if we have stash data configured.
func (*Service) HasStashFor
Section titled “func (*Service) HasStashFor”func (s *Service) HasStashFor(ownerID types.NaraID) boolHasStashFor returns true if we’re storing a stash for the given owner.
func (*Service) Init
Section titled “func (*Service) Init”func (s *Service) Init() errorfunc (*Service) MarshalState
Section titled “func (*Service) MarshalState”func (s *Service) MarshalState() ([]byte, error)MarshalState returns the service’s state as JSON for debugging.
func (*Service) Name
Section titled “func (*Service) Name”func (s *Service) Name() stringfunc (*Service) PushTo
Section titled “func (*Service) PushTo”func (s *Service) PushTo(ownerID types.NaraID) errorConfidants returns the list of current confidants. PushTo sends the stored stash to the owner. This is used for recovery - when we see a peer come online (hey-there), we proactively send them their stash if we have it.
func (*Service) RecoverFromAny
Section titled “func (*Service) RecoverFromAny”func (s *Service) RecoverFromAny() ([]byte, error)RecoverFromAny attempts to recover from any available confidant.
Tries all configured confidants and returns the first successful recovery.
func (*Service) RegisterBehaviors
Section titled “func (*Service) RegisterBehaviors”func (s *Service) RegisterBehaviors(rt runtime.RuntimeInterface)RegisterBehaviors registers all stash message behaviors with the runtime.
This is called during service initialization to declare how each stash message kind should be handled.
Behaviors are registered locally with the runtime for test isolation.
func (*Service) RequestFrom
Section titled “func (*Service) RequestFrom”func (s *Service) RequestFrom(confidantID types.NaraID) ([]byte, error)RequestFrom requests stored data from a confidant.
Returns the decrypted data if the confidant has it, or an error.
func (*Service) SelectConfidantsAutomatically
Section titled “func (*Service) SelectConfidantsAutomatically”func (s *Service) SelectConfidantsAutomatically() errorSelectConfidantsAutomatically picks 3 confidants automatically: - First: peer with highest uptime - Second and third: random peers Returns error if unable to find 3 willing peers.
func (*Service) SetConfidants
Section titled “func (*Service) SetConfidants”func (s *Service) SetConfidants(confidantIDs []types.NaraID)SetConfidants configures the list of confidants to use.
func (*Service) SetStashData
Section titled “func (*Service) SetStashData”func (s *Service) SetStashData(data []byte) errorSetStashData updates the stash data and distributes it to all confidants. If fewer than targetConfidants are configured, it automatically selects peers.
func (*Service) Start
Section titled “func (*Service) Start”func (s *Service) Start() errorfunc (*Service) Stop
Section titled “func (*Service) Stop”func (s *Service) Stop() errorfunc (*Service) StorageLimit
Section titled “func (*Service) StorageLimit”func (s *Service) StorageLimit() intStorageLimit returns the maximum number of stashes this nara can store for others. Based on memory mode: low=5, medium=20, high=50.
func (*Service) StoreWith
Section titled “func (*Service) StoreWith”func (s *Service) StoreWith(confidantID types.NaraID, data []byte) errorStoreWith stores encrypted data with a confidant.
This is a synchronous call that blocks until the confidant acknowledges receipt or the request times out.
func (*Service) StoredCount
Section titled “func (*Service) StoredCount”func (s *Service) StoredCount() intStoredCount returns the number of stashes currently stored for other naras.
func (*Service) TargetConfidants
Section titled “func (*Service) TargetConfidants”func (s *Service) TargetConfidants() intTargetConfidants returns the target number of confidants.
Generated by gomarkdoc