client

package module
v0.0.0-...-cc2b456 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: GPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// InitialPheromone is assigned to freshly discovered or untested nodes.
	InitialPheromone = 1.0
	// MinPheromone sets the absolute floor to prevent node starvation.
	MinPheromone = 0.05
	// MaxPheromone bounds the highest reputation a node can accumulate.
	MaxPheromone = 10.0
	// EvaporationFactor decays historical trails over time (tau *= 0.95).
	EvaporationFactor = 0.95
	// FailurePenaltyFactor aggressively reduces the trail upon dial or transfer failure (tau *= 0.2).
	FailurePenaltyFactor = 0.2
	// EvaporationInterval controls how frequently lazy evaporation triggers.
	EvaporationInterval = 1 * time.Second
)

Pheromone constants for Ant Colony Optimization (§3 in ADAPTIVE_SYSTEMS.md).

Variables

View Source
var DefaultRouter = NewPheromoneRouter()

DefaultRouter is a shared, package-level PheromoneRouter singleton for client downloads.

Functions

func Connect

func Connect(wg *sync.WaitGroup, cfg common.Configuration, filePath string, remotePath string, serverId int, timestamp int64, requestedMode int, replicationFactor int) (err error)

Connect establishes connections with daemon(s) and sends a file. It first connects to a specified daemon to determine the replication mode. If splay replication is active, it connects to all other daemons. Finally, it sends the file to all established connections concurrently.

func ConnectStream

func ConnectStream(cfg common.Configuration, content io.Reader, name string, hash string, size int64, remotePath string, s3Headers map[string]string, serverId int, timestamp int64, requestedMode int, replicationFactor int) error

ConnectStream establishes a connection with a daemon and sends file content from an io.Reader with pre-computed metadata. This is used by the server for replication forwarding when the blob may not be on the local filesystem (e.g., S3 or raw device backends). s3Headers carries preserved S3 object metadata (Content-Type, x-amz-meta-*) to replicated peers (issue #772); it may be nil.

func Download

func Download(cfg common.Configuration, encryptedName string, contentHash string, serverId int, dst io.Writer) (err error)

Download retrieves an encrypted file from a daemon, decrypts it, and writes the plaintext to dst. The encryptedName and contentHash must be the values computed during upload (HMAC of wireName and SHA-256 of ciphertext). If encryption is disabled, the content is written directly to dst.

func DownloadWithFallback

func DownloadWithFallback(cfg common.Configuration, encryptedName string, contentHash string, serverId int, dst io.Writer) error

DownloadWithFallback retrieves a file using CRUSH placement and Ant Colony Pheromone routing to select the healthiest replica, falling back to sibling replicas if any node fails or returns an error.

func DownloadWithFallbackRouter

func DownloadWithFallbackRouter(cfg common.Configuration, encryptedName string, contentHash string, serverId int, dst io.Writer, router PheromoneRouter) (err error)

DownloadWithFallbackRouter retrieves a file using the specified PheromoneRouter.

Types

type PheromoneRouter

type PheromoneRouter interface {
	// SelectReplica chooses the best replica candidate from eligible CRUSH nodes
	// using weighted probabilistic selection (roulette-wheel).
	SelectReplica(replicas []*common.Node) (*common.Node, error)

	// PrioritizeReplicas returns the candidates ordered by weighted reputation,
	// allowing resilient fallback from most preferred to least preferred.
	PrioritizeReplicas(replicas []*common.Node) ([]*common.Node, error)

	// RecordSuccess strengthens the pheromone trail of nodeID inversely proportional to RTT.
	RecordSuccess(nodeID int, rtt time.Duration)

	// RecordFailure severely penalizes the pheromone trail of nodeID.
	RecordFailure(nodeID int)

	// Evaporate applies exponential decay across all tracked pheromone trails.
	Evaporate()

	// GetPheromone returns the current pheromone level for nodeID.
	GetPheromone(nodeID int) float64
}

PheromoneRouter defines the compile-time Go interface seam (Rule 74) for adaptive replica selection inspired by ant colony foraging trails.

func NewPheromoneRouter

func NewPheromoneRouter() PheromoneRouter

NewPheromoneRouter creates a new Ant Colony PheromoneRouter.

Jump to

Keyboard shortcuts

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