Skip to content

Stash

import "github.com/eljojo/nara/services/stash"

EncryptedStash is what we store for other naras.

type EncryptedStash struct {
OwnerID types.NaraID
Nonce []byte
Ciphertext []byte
StoredAt time.Time
}

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() *Service

NewService creates a new stash service.

func (s *Service) ClearMyStash()

ClearMyStash clears the local stash data (used for testing restart scenarios).

func (s *Service) Confidants() []types.NaraID

func (s *Service) DistributeToConfidants() error

DistributeToConfidants distributes the current stash to all configured confidants.

func (s *Service) GetStashData() (data []byte, timestamp int64)

GetStashData returns the current stash data.

func (s *Service) GetStoredStash(ownerID types.NaraID) *EncryptedStash

func (s *Service) HasStashData() bool

HasStashData returns true if we have stash data configured.

func (s *Service) HasStashFor(ownerID types.NaraID) bool

HasStashFor returns true if we’re storing a stash for the given owner.

func (s *Service) Init() error

func (s *Service) MarshalState() ([]byte, error)

MarshalState returns the service’s state as JSON for debugging.

func (s *Service) Name() string

func (s *Service) PushTo(ownerID types.NaraID) error

Confidants 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 (s *Service) RecoverFromAny() ([]byte, error)

RecoverFromAny attempts to recover from any available confidant.

Tries all configured confidants and returns the first successful recovery.

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 (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() error

SelectConfidantsAutomatically picks 3 confidants automatically: - First: peer with highest uptime - Second and third: random peers Returns error if unable to find 3 willing peers.

func (s *Service) SetConfidants(confidantIDs []types.NaraID)

SetConfidants configures the list of confidants to use.

func (s *Service) SetStashData(data []byte) error

SetStashData updates the stash data and distributes it to all confidants. If fewer than targetConfidants are configured, it automatically selects peers.

func (s *Service) Start() error

func (s *Service) Stop() error

func (s *Service) StorageLimit() int

StorageLimit returns the maximum number of stashes this nara can store for others. Based on memory mode: low=5, medium=20, high=50.

func (s *Service) StoreWith(confidantID types.NaraID, data []byte) error

StoreWith stores encrypted data with a confidant.

This is a synchronous call that blocks until the confidant acknowledges receipt or the request times out.

func (s *Service) StoredCount() int

StoredCount returns the number of stashes currently stored for other naras.

func (s *Service) TargetConfidants() int

TargetConfidants returns the target number of confidants.

Generated by gomarkdoc