common

package
v0.0.74 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package common contains code that is useful to replicas and couriers.

Package common contains code that is useful to replicas and couriers.

Index

Constants

View Source
const (
	// K represents the number of shards per entry into the system.
	K = 2
)
View Source
const ReplicaEpochPeriod = 7 * (24 * time.Hour)

ReplicaEpochPeriod is the length of time of the Repica Epoch. Storage Replicas garbage collect their replica keys every Replica Epoch.

Variables

View Source
var MKEMNikeScheme = mkem.NewScheme(NikeScheme)
View Source
var NikeScheme nike.Scheme = schemes.ByName("CTIDH1024-X25519")

Functions

func ConvertNormalToReplicaEpoch

func ConvertNormalToReplicaEpoch(normalEpoch uint64) uint64

ConvertNormalToReplicaEpoch converts a 20-minute epoch number to a weekly replica epoch.

func GetConfiguredReplicaKeys added in v0.0.73

func GetConfiguredReplicaKeys(doc *pki.Document) ([][]byte, error)

GetConfiguredReplicaKeys returns the stable set of replica identity keys from the authority configuration. This set does NOT change when replicas go offline, ensuring consistent sharding.

func GetRemoteShards

func GetRemoteShards(replicaIdPubKey sign.PublicKey, boxid *[32]byte, doc *pki.Document) ([]*pki.ReplicaDescriptor, error)

func GetShards

func GetShards(boxid *[32]byte, doc *pki.Document) ([]*pki.ReplicaDescriptor, error)

GetShards returns the ReplicaDescriptors for the replicas that should store data for a boxID. Uses the stable ConfiguredReplicaIdentityKeys for consistent sharding. Only returns descriptors for replicas that are currently online (present in StorageReplicas). The returned slice may have fewer than K elements if some shard replicas are offline.

func ReplicaNow

func ReplicaNow() (current uint64, elapsed, till time.Duration)

ReplicaNow returns the current Replica Epoch, time since the start of the current epoch, and time till the next epoch for a weekly epoch duration.

func ReplicaNum

func ReplicaNum(replicaID uint8, doc *pki.Document) (*pki.ReplicaDescriptor, error)

ReplicaNum looks up a replica by its static ReplicaID. The replicaID parameter is the static uint8 identifier assigned to a replica, not an array index into StorageReplicas.

func Shard

func Shard(boxID *[32]byte, serverIdKeys [][]byte) [][]byte

Shard is slower than Shard2. therefore use Shard2 instead.

func Shard2

func Shard2(boxID *[32]byte, serverIdKeys [][]byte) [][]byte

Shard2 implements our consistent hashing scheme for the sharded pigeonhole database where K is fixed to 2. It returns the first K`th entries from our sorted list of hashes where each hash is the hash of the boxID concatenated with the server ID key.

Types

type EnvelopeKey

type EnvelopeKey struct {
	PrivateKey nike.PrivateKey
	PublicKey  nike.PublicKey
}

EnvelopeKey encapsulates the public and private NIKE keys.

func EnvelopeKeyFromFiles

func EnvelopeKeyFromFiles(dataDir string, scheme nike.Scheme, epoch uint64) (*EnvelopeKey, error)

EnvelopeKeyFromFiles loads the PEM key files from disk.

func NewEnvelopeKey

func NewEnvelopeKey(scheme nike.Scheme) *EnvelopeKey

NewEnvelopeKey creates a new EnvelopeKey type.

func (*EnvelopeKey) KeyFileNames

func (e *EnvelopeKey) KeyFileNames(dataDir string, scheme nike.Scheme, epoch uint64) (string, string)

func (*EnvelopeKey) PurgeKeyFiles

func (e *EnvelopeKey) PurgeKeyFiles(dataDir string, scheme nike.Scheme, epoch uint64)

func (*EnvelopeKey) WriteKeyFiles

func (e *EnvelopeKey) WriteKeyFiles(dataDir string, scheme nike.Scheme, epoch uint64) error

WriteKeyFiles generates and writes new key files, or loads existing ones if they already exist. This ensures that a replica can safely restart or re-publish for the same epoch without errors.

type ReplicaMap

type ReplicaMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewReplicaMap

func NewReplicaMap() *ReplicaMap

func (*ReplicaMap) Copy

func (r *ReplicaMap) Copy() map[[32]byte]*pki.ReplicaDescriptor

func (*ReplicaMap) GetReplicaDescriptor

func (r *ReplicaMap) GetReplicaDescriptor(nodeID *[32]byte) (*pki.ReplicaDescriptor, bool)

func (*ReplicaMap) Replace

func (r *ReplicaMap) Replace(newMap map[[32]byte]*pki.ReplicaDescriptor)

func (*ReplicaMap) UpdateFromPKIDoc

func (r *ReplicaMap) UpdateFromPKIDoc(doc *pki.Document)

Jump to

Keyboard shortcuts

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