store

package
v0.0.0-...-840fb12 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CHKBlock constants
	CHKDataLength          = 32768 // Fixed data block size
	CHKTotalHeadersLength  = 36    // Fixed header size
	CHKMaxCompressedLength = 32764 // Maximum compressed payload (DATA_LENGTH - 4)
)
View Source
const (
	// Entry metadata size (128 bytes per slot)
	EntryMetadataSize = 128

	// Entry flags
	EntryFlagOccupied = 0x01
	EntryFlagPlainKey = 0x02
	EntryNewBlock     = 0x04
	EntryWrongStore   = 0x08

	// Slot filter flags
	SlotChecked    = 0x80000000
	SlotOccupied   = 0x40000000
	SlotNewBlock   = 0x20000000
	SlotWrongStore = 0x10000000

	// Probing
	OptionMaxProbe = 5
)
View Source
const (
	// SSKBlock constants
	SSKDataLength             = 1024 // Fixed data block size
	SSKMaxCompressedLength    = 1022 // Maximum compressed payload (DATA_LENGTH - 2)
	SSKTotalHeadersLength     = 135  // Total header size
	SSKEncryptedHeadersLength = 36   // Length of encrypted portion
	SSKSigRLength             = 32   // Signature R component length
	SSKSigSLength             = 32   // Signature S component length
	SSKEHDocnameLength        = 32   // Encrypted hashed docname length
	SSKHeadersOffset          = 36   // Start of encrypted fields
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockMetadata

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

BlockMetadata contains metadata about a block fetch/store operation

func NewBlockMetadata

func NewBlockMetadata() *BlockMetadata

NewBlockMetadata creates a new BlockMetadata

func (*BlockMetadata) IsOldBlock

func (m *BlockMetadata) IsOldBlock() bool

IsOldBlock returns whether the block is marked as old

func (*BlockMetadata) SetOldBlock

func (m *BlockMetadata) SetOldBlock()

SetOldBlock marks the block as old

type CHKBlock

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

CHKBlock represents a Content Hash Key block (immutable content)

func NewCHKBlock

func NewCHKBlock(data, headers []byte, key *keys.NodeCHK, verify bool) (*CHKBlock, error)

NewCHKBlock creates a new CHKBlock with verification

func ReadCHKBlock

func ReadCHKBlock(r io.Reader, key *keys.NodeCHK, verify bool) (*CHKBlock, error)

ReadCHKBlock deserializes a CHKBlock from a reader

func (*CHKBlock) Clone

func (b *CHKBlock) Clone() *CHKBlock

Clone creates a deep copy of the block

func (*CHKBlock) Equals

func (b *CHKBlock) Equals(other StorableBlock) bool

Equals checks if two CHKBlocks are equal

func (*CHKBlock) GetClientKey

func (b *CHKBlock) GetClientKey() *keys.ClientCHK

GetClientKey returns the client-level CHK key (if available)

func (*CHKBlock) GetCryptoAlgorithm

func (b *CHKBlock) GetCryptoAlgorithm() byte

GetCryptoAlgorithm returns the crypto algorithm

func (*CHKBlock) GetFullKey

func (b *CHKBlock) GetFullKey() []byte

GetFullKey returns the full key (type + routing key)

func (*CHKBlock) GetHashIdentifier

func (b *CHKBlock) GetHashIdentifier() int16

GetHashIdentifier returns the hash algorithm identifier

func (*CHKBlock) GetKey

func (b *CHKBlock) GetKey() keys.Key

GetKey returns the underlying NodeCHK

func (*CHKBlock) GetPubkeyBytes

func (b *CHKBlock) GetPubkeyBytes() []byte

GetPubkeyBytes returns nil (CHK blocks don't have pubkeys)

func (*CHKBlock) GetRawData

func (b *CHKBlock) GetRawData() []byte

GetRawData returns the raw data bytes

func (*CHKBlock) GetRawHeaders

func (b *CHKBlock) GetRawHeaders() []byte

GetRawHeaders returns the raw header bytes

func (*CHKBlock) GetRoutingKey

func (b *CHKBlock) GetRoutingKey() []byte

GetRoutingKey returns the routing key

func (*CHKBlock) GetTotalLength

func (b *CHKBlock) GetTotalLength() int

GetTotalLength returns the total block length (headers + data)

func (*CHKBlock) SetClientKey

func (b *CHKBlock) SetClientKey(clientKey *keys.ClientCHK)

SetClientKey sets the client-level CHK key

func (*CHKBlock) VerifyHash

func (b *CHKBlock) VerifyHash() error

VerifyHash verifies the block's hash matches the key

func (*CHKBlock) Write

func (b *CHKBlock) Write(w io.Writer) error

Write serializes the block to a writer

type CHKStoreCallback

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

CHKStoreCallback implements StoreCallback for CHK blocks

func NewCHKStoreCallback

func NewCHKStoreCallback(store FreenetStore) *CHKStoreCallback

NewCHKStoreCallback creates a new CHK store callback

func (*CHKStoreCallback) CollisionPossible

func (c *CHKStoreCallback) CollisionPossible() bool

CollisionPossible returns false - CHK blocks are content-addressed

func (*CHKStoreCallback) Construct

func (c *CHKStoreCallback) Construct(data, headers, routingKey, fullKey []byte,
	canReadClientCache, canReadSlashdotCache bool,
	meta *BlockMetadata, knownPubKey *dsa.PublicKey) (KeyBlock, error)

Construct creates a CHK block from raw data

func (*CHKStoreCallback) ConstructNeedsKey

func (c *CHKStoreCallback) ConstructNeedsKey() bool

ConstructNeedsKey returns false - CHK construction doesn't need the key

func (*CHKStoreCallback) DataLength

func (c *CHKStoreCallback) DataLength() int

DataLength returns the fixed CHK data length

func (*CHKStoreCallback) FullKeyLength

func (c *CHKStoreCallback) FullKeyLength() int

FullKeyLength returns the full CHK key length (34 bytes)

func (*CHKStoreCallback) HeaderLength

func (c *CHKStoreCallback) HeaderLength() int

HeaderLength returns the fixed CHK header length

func (*CHKStoreCallback) RoutingKeyFromFullKey

func (c *CHKStoreCallback) RoutingKeyFromFullKey(keyBuf []byte) []byte

RoutingKeyFromFullKey extracts the routing key from a full key

func (*CHKStoreCallback) RoutingKeyLength

func (c *CHKStoreCallback) RoutingKeyLength() int

RoutingKeyLength returns the CHK routing key length (32 bytes)

func (*CHKStoreCallback) StoreFullKeys

func (c *CHKStoreCallback) StoreFullKeys() bool

StoreFullKeys returns true - CHK blocks store full keys

type Entry

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

Entry represents metadata for a stored block

type FreenetStore

type FreenetStore interface {
	// Fetch retrieves a block by routing key
	Fetch(routingKey, fullKey []byte, dontPromote, canReadClientCache,
		canReadSlashdotCache, ignoreOldBlocks bool, meta *BlockMetadata) (StorableBlock, error)

	// Put stores a block
	Put(block StorableBlock, data, header []byte, overwrite, oldBlock bool) error

	// SetMaxKeys changes the store size
	SetMaxKeys(maxStoreKeys int64, shrinkNow bool) error

	// GetMaxKeys returns the maximum number of keys
	GetMaxKeys() int64

	// Statistics
	Hits() int64
	Misses() int64
	Writes() int64
	KeyCount() int64
	GetBloomFalsePositive() int64

	// ProbablyInStore checks if a key might be in the store (bloom filter)
	ProbablyInStore(routingKey []byte) bool

	// Lifecycle
	Start() error
	Close() error
}

FreenetStore is the main interface for all datastores

type KeyBlock

type KeyBlock interface {
	StorableBlock

	// GetKey returns the underlying key (NodeCHK or NodeSSK)
	GetKey() keys.Key

	// GetRawHeaders returns the raw header bytes
	GetRawHeaders() []byte

	// GetRawData returns the raw data bytes
	GetRawData() []byte

	// GetPubkeyBytes returns the serialized public key (SSK only, nil for CHK)
	GetPubkeyBytes() []byte
}

KeyBlock extends StorableBlock with key-specific methods

type RAMFreenetStore

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

RAMFreenetStore is a simple in-memory LRU datastore

func NewRAMFreenetStore

func NewRAMFreenetStore(callback StoreCallback, maxKeys int64) *RAMFreenetStore

NewRAMFreenetStore creates a new RAM-based datastore

func (*RAMFreenetStore) Close

func (s *RAMFreenetStore) Close() error

Close shuts down the store

func (*RAMFreenetStore) Fetch

func (s *RAMFreenetStore) Fetch(routingKey, fullKey []byte, dontPromote, canReadClientCache,
	canReadSlashdotCache, ignoreOldBlocks bool, meta *BlockMetadata) (StorableBlock, error)

Fetch retrieves a block by routing key

func (*RAMFreenetStore) GetBloomFalsePositive

func (s *RAMFreenetStore) GetBloomFalsePositive() int64

GetBloomFalsePositive returns 0 (no bloom filter in RAM store)

func (*RAMFreenetStore) GetMaxKeys

func (s *RAMFreenetStore) GetMaxKeys() int64

GetMaxKeys returns the maximum number of keys

func (*RAMFreenetStore) GetStats

func (s *RAMFreenetStore) GetStats() StoreStats

GetStats returns statistics about the store

func (*RAMFreenetStore) Hits

func (s *RAMFreenetStore) Hits() int64

Hits returns the number of cache hits

func (*RAMFreenetStore) KeyCount

func (s *RAMFreenetStore) KeyCount() int64

KeyCount returns the current number of keys

func (*RAMFreenetStore) Misses

func (s *RAMFreenetStore) Misses() int64

Misses returns the number of cache misses

func (*RAMFreenetStore) ProbablyInStore

func (s *RAMFreenetStore) ProbablyInStore(routingKey []byte) bool

ProbablyInStore checks if a key is in the store

func (*RAMFreenetStore) Put

func (s *RAMFreenetStore) Put(block StorableBlock, data, header []byte, overwrite, isOldBlock bool) error

Put stores a block

func (*RAMFreenetStore) SetMaxKeys

func (s *RAMFreenetStore) SetMaxKeys(maxStoreKeys int64, shrinkNow bool) error

SetMaxKeys changes the maximum number of keys

func (*RAMFreenetStore) Start

func (s *RAMFreenetStore) Start() error

Start initializes the store (no-op for RAM store)

func (*RAMFreenetStore) Writes

func (s *RAMFreenetStore) Writes() int64

Writes returns the number of writes

type SSKBlock

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

SSKBlock represents a Signed Subspace Key block (mutable content)

func NewSSKBlock

func NewSSKBlock(data, headers []byte, nodeKey *keys.NodeSSK, dontVerify bool) (*SSKBlock, error)

NewSSKBlock creates a new SSKBlock with signature verification

func ReadSSKBlock

func ReadSSKBlock(r io.Reader, nodeKey *keys.NodeSSK, dontVerify bool) (*SSKBlock, error)

ReadSSKBlock deserializes an SSKBlock from a reader

func (*SSKBlock) Clone

func (b *SSKBlock) Clone() *SSKBlock

Clone creates a deep copy of the block

func (*SSKBlock) Equals

func (b *SSKBlock) Equals(other StorableBlock) bool

Equals checks if two SSKBlocks are equal

func (*SSKBlock) GetEncryptedHeaders

func (b *SSKBlock) GetEncryptedHeaders() []byte

GetEncryptedHeaders returns the encrypted portion of headers

func (*SSKBlock) GetFullKey

func (b *SSKBlock) GetFullKey() []byte

GetFullKey returns the full key (type + ehDocname + pubKeyHash)

func (*SSKBlock) GetHashIdentifier

func (b *SSKBlock) GetHashIdentifier() int16

GetHashIdentifier returns the hash algorithm identifier

func (*SSKBlock) GetKey

func (b *SSKBlock) GetKey() keys.Key

GetKey returns the underlying NodeSSK

func (*SSKBlock) GetPubKey

func (b *SSKBlock) GetPubKey() *dsa.PublicKey

GetPubKey returns the DSA public key

func (*SSKBlock) GetPubkeyBytes

func (b *SSKBlock) GetPubkeyBytes() []byte

GetPubkeyBytes returns the serialized public key

func (*SSKBlock) GetRawData

func (b *SSKBlock) GetRawData() []byte

GetRawData returns the raw data bytes

func (*SSKBlock) GetRawHeaders

func (b *SSKBlock) GetRawHeaders() []byte

GetRawHeaders returns the raw header bytes

func (*SSKBlock) GetRoutingKey

func (b *SSKBlock) GetRoutingKey() []byte

GetRoutingKey returns the routing key

func (*SSKBlock) GetSymCipherIdentifier

func (b *SSKBlock) GetSymCipherIdentifier() int16

GetSymCipherIdentifier returns the symmetric cipher identifier

func (*SSKBlock) GetTotalLength

func (b *SSKBlock) GetTotalLength() int

GetTotalLength returns the total block length (headers + data)

func (*SSKBlock) VerifySignature

func (b *SSKBlock) VerifySignature() error

VerifySignature verifies the block's DSA signature

func (*SSKBlock) Write

func (b *SSKBlock) Write(w io.Writer) error

Write serializes the block to a writer

type SSKStoreCallback

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

SSKStoreCallback implements StoreCallback for SSK blocks

func NewSSKStoreCallback

func NewSSKStoreCallback(store FreenetStore) *SSKStoreCallback

NewSSKStoreCallback creates a new SSK store callback

func (*SSKStoreCallback) CollisionPossible

func (s *SSKStoreCallback) CollisionPossible() bool

CollisionPossible returns true - SSK blocks can be updated

func (*SSKStoreCallback) Construct

func (s *SSKStoreCallback) Construct(data, headers, routingKey, fullKey []byte,
	canReadClientCache, canReadSlashdotCache bool,
	meta *BlockMetadata, knownPubKey *dsa.PublicKey) (KeyBlock, error)

Construct creates an SSK block from raw data

func (*SSKStoreCallback) ConstructNeedsKey

func (s *SSKStoreCallback) ConstructNeedsKey() bool

ConstructNeedsKey returns true - SSK construction needs the public key

func (*SSKStoreCallback) DataLength

func (s *SSKStoreCallback) DataLength() int

DataLength returns the fixed SSK data length

func (*SSKStoreCallback) FullKeyLength

func (s *SSKStoreCallback) FullKeyLength() int

FullKeyLength returns the full SSK key length (66 bytes)

func (*SSKStoreCallback) HeaderLength

func (s *SSKStoreCallback) HeaderLength() int

HeaderLength returns the fixed SSK header length

func (*SSKStoreCallback) RoutingKeyFromFullKey

func (s *SSKStoreCallback) RoutingKeyFromFullKey(keyBuf []byte) []byte

RoutingKeyFromFullKey extracts the routing key from a full key

func (*SSKStoreCallback) RoutingKeyLength

func (s *SSKStoreCallback) RoutingKeyLength() int

RoutingKeyLength returns the SSK routing key length (32 bytes)

func (*SSKStoreCallback) StoreFullKeys

func (s *SSKStoreCallback) StoreFullKeys() bool

StoreFullKeys returns true - SSK blocks store full keys

type SaltedHashFreenetStore

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

SaltedHashFreenetStore is a persistent disk-based datastore

func NewSaltedHashFreenetStore

func NewSaltedHashFreenetStore(basePath string, callback StoreCallback, maxKeys int64) (*SaltedHashFreenetStore, error)

NewSaltedHashFreenetStore creates a new persistent datastore

func (*SaltedHashFreenetStore) Close

func (s *SaltedHashFreenetStore) Close() error

Close shuts down the store

func (*SaltedHashFreenetStore) Fetch

func (s *SaltedHashFreenetStore) Fetch(routingKey, fullKey []byte, dontPromote, canReadClientCache,
	canReadSlashdotCache, ignoreOldBlocks bool, meta *BlockMetadata) (StorableBlock, error)

Fetch retrieves a block by routing key

func (*SaltedHashFreenetStore) GetBloomFalsePositive

func (s *SaltedHashFreenetStore) GetBloomFalsePositive() int64

func (*SaltedHashFreenetStore) GetMaxKeys

func (s *SaltedHashFreenetStore) GetMaxKeys() int64

func (*SaltedHashFreenetStore) Hits

func (s *SaltedHashFreenetStore) Hits() int64

func (*SaltedHashFreenetStore) KeyCount

func (s *SaltedHashFreenetStore) KeyCount() int64

func (*SaltedHashFreenetStore) Misses

func (s *SaltedHashFreenetStore) Misses() int64

func (*SaltedHashFreenetStore) ProbablyInStore

func (s *SaltedHashFreenetStore) ProbablyInStore(routingKey []byte) bool

func (*SaltedHashFreenetStore) Put

func (s *SaltedHashFreenetStore) Put(block StorableBlock, data, header []byte, overwrite, isOldBlock bool) error

Put stores a block

func (*SaltedHashFreenetStore) SetMaxKeys

func (s *SaltedHashFreenetStore) SetMaxKeys(maxStoreKeys int64, shrinkNow bool) error

func (*SaltedHashFreenetStore) Start

func (s *SaltedHashFreenetStore) Start() error

Start initializes the store files

func (*SaltedHashFreenetStore) Writes

func (s *SaltedHashFreenetStore) Writes() int64

type StorableBlock

type StorableBlock interface {
	// GetRoutingKey returns the routing key for network routing
	GetRoutingKey() []byte

	// GetFullKey returns the complete key with type information
	GetFullKey() []byte

	// Equals checks if two blocks are equal
	Equals(other StorableBlock) bool
}

StorableBlock is the minimal interface for blocks that can be stored

type StoreCallback

type StoreCallback interface {
	// Fixed-size parameters
	DataLength() int
	HeaderLength() int
	RoutingKeyLength() int
	FullKeyLength() int

	// Storage configuration
	StoreFullKeys() bool
	CollisionPossible() bool
	ConstructNeedsKey() bool

	// Block construction from raw data
	Construct(data, headers, routingKey, fullKey []byte,
		canReadClientCache, canReadSlashdotCache bool,
		meta *BlockMetadata, knownPubKey *dsa.PublicKey) (KeyBlock, error)

	// Extract routing key from full key
	RoutingKeyFromFullKey(keyBuf []byte) []byte
}

StoreCallback defines the interface for type-specific store operations

type StoreStats

type StoreStats struct {
	Hits     int64
	Misses   int64
	Writes   int64
	KeyCount int64
	MaxKeys  int64
	HitRate  float64
	Capacity float64
}

StoreStats contains statistics about store performance

func (StoreStats) String

func (ss StoreStats) String() string

String returns a formatted string of store statistics

type StoredBlock

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

StoredBlock represents a block stored in RAM

Jump to

Keyboard shortcuts

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