Documentation
¶
Overview ¶
Package common provides shared functionality for the momo application.
Index ¶
- Constants
- Variables
- func Connect(wg *sync.WaitGroup, cfg Configuration, filePath string, serverId int, ...)
- func DialSocket(servAddr string) (net.Conn, error)
- func FindStringIndex(slice []string, value string) int
- func HashFile(filePath string) (string, error)
- func LogStdOut(logApp bool)
- func PadString(input string, length int) string
- type Configuration
- type ConfigurationGlobal
- type ConfigurationMetrics
- type Daemon
- type FileMetadata
- type IdleTimeoutConn
- type ReplicationData
Constants ¶
const ( // TCPSocketBufferSize defines the standard buffer size for TCP sockets. TCPSocketBufferSize = 1024 // TimestampLength is the expected length of a timestamp string. TimestampLength = 19 // AuthTokenLength is the expected length of the authentication token. AuthTokenLength = 64 // FileInfoLength is the allocated length for file information strings. FileInfoLength = 64 // MaxFileSize is the maximum allowed size for a file transfer (1GB). MaxFileSize = 1024 * 1024 * 1024 )
const ( // ReplicationType defines the different modes of data replication. ReplicationType int = iota // ReplicationChain indicates the use of chain replication. ReplicationChain // ReplicationSplay indicates the use of splay replication. ReplicationSplay // ReplicationPrimarySplay indicates a primary-splay replication strategy. ReplicationPrimarySplay // ReplicationNone indicates that no replication is used. ReplicationNone // DummyEpoch is a placeholder epoch value for initialization. DummyEpoch = 1557906926566451195 )
Variables ¶
var GetConfigFromFile = func() (Configuration, error) { return GetConfig("conf/momo.conf") }
GetConfigFromFile is a function variable that loads the configuration from the default path "conf/momo.conf". It can be overridden in tests to load a custom configuration for testing purposes.
Functions ¶
func Connect ¶
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 DialSocket ¶
DialSocket connects to the given address. It returns a net.Conn or an error.
func FindStringIndex ¶
FindStringIndex searches for a string in a slice of strings and returns its index. If the string is not found, it returns -1. ⚡ Bolt: Use `slices.Index` from the standard library for a ~7x performance improvement over manual loops.
func HashFile ¶
HashFile calculates the SHA-256 hash of a file. It takes the file path as input and returns the SHA-256 hash as a hex-encoded string.
Types ¶
type Configuration ¶
type Configuration struct {
// Daemons is a list of daemons in the system.
Daemons []*Daemon
// Global is the global configuration.
Global ConfigurationGlobal
// Metrics is the metrics configuration.
Metrics ConfigurationMetrics
}
Configuration holds the overall configuration for the application.
func GetConfig ¶
func GetConfig(path string) (Configuration, error)
GetConfig loads and validates the configuration from the given file path.
type ConfigurationGlobal ¶
type ConfigurationGlobal struct {
// Debug enables or disables debug mode.
Debug bool
// AuthToken is the authentication token used for node-to-node and client-to-node communication.
AuthToken string
// ReplicationOrder is the order of replication modes to use.
ReplicationOrder []int
// PolymorphicSystem enables or disables the polymorphic system.
PolymorphicSystem bool
}
ConfigurationGlobal holds the global configuration for the application.
type ConfigurationMetrics ¶
type ConfigurationMetrics struct {
// Interval is the interval at which to collect metrics.
Interval int
// MaxThreshold is the maximum threshold for metrics.
MaxThreshold float64
// MinThreshold is the minimum threshold for metrics.
MinThreshold float64
// FallbackInterval is the interval at which to fall back to a lower replication mode.
FallbackInterval int
}
ConfigurationMetrics holds the metrics configuration for the application.
type Daemon ¶
type Daemon struct {
// Host is the address of the daemon.
Host string
// ChangeReplication is the endpoint for changing the replication mode.
ChangeReplication string
// Data is the endpoint for data operations.
Data string
// Drive is the drive used by the daemon.
Drive string
}
Daemon represents a daemon in the system.
type FileMetadata ¶
type FileMetadata struct {
// Name is the name of the file.
Name string
// Hash is the SHA-256 hash of the file.
Hash string
// Size is the size of the file in bytes.
Size int64
}
FileMetadata stores the metadata for a file.
type IdleTimeoutConn ¶
IdleTimeoutConn wraps a net.Conn to provide a rolling idle timeout. Every successful Read or Write resets the deadline, preventing slowloris attacks without interrupting large, active file transfers.
func NewIdleTimeoutConn ¶
func NewIdleTimeoutConn(conn net.Conn, timeout time.Duration) *IdleTimeoutConn
NewIdleTimeoutConn creates a new IdleTimeoutConn.
type ReplicationData ¶
type ReplicationData struct {
// Old is the old replication mode.
Old int `json:"old"`
// New is the new replication mode.
New int `json:"new"`
// TimeStamp is the timestamp of the replication mode change.
TimeStamp int64 `json:"timestamp"`
}
ReplicationData stores the information about a replication mode change.