Skip to content

Configuration

FuryMesh offers extensive configuration options to customize its behavior according to your needs. This guide covers all available configuration options and how to use them.

Configuration File

FuryMesh uses a YAML configuration file. By default, it looks for a file named config.yaml in the current directory, but you can specify a different path using the --config flag.

Here's a complete example of a configuration file with all available options:

# Node configuration
node:
  # Unique identifier for this node
  id: "my-node"
  # Port to listen on for incoming connections
  port: 8080
  # Directory to store data
  data_dir: "./data"
  # Maximum number of concurrent connections
  max_connections: 100
  # Enable or disable debug mode
  debug: false

# DHT configuration
dht:
  # Known peers to bootstrap with
  bootstrap_peers:
    - "peer1.example.com:8080"
    - "peer2.example.com:8080"
  # Size of the routing table buckets
  bucket_size: 20
  # Alpha parameter for Kademlia (number of parallel lookups)
  alpha: 3
  # Interval for refreshing buckets (in seconds)
  refresh_interval: 3600
  # Timeout for DHT operations (in seconds)
  operation_timeout: 30

# WebRTC configuration
webrtc:
  # STUN servers for NAT traversal
  stun_servers:
    - "stun:stun.l.google.com:19302"
    - "stun:stun1.l.google.com:19302"
  # TURN servers for fallback relay
  turn_servers:
    - url: "turn:turn.example.com:3478"
      username: "username"
      password: "password"
  # ICE candidate gathering timeout (in seconds)
  ice_gathering_timeout: 5
  # Maximum message size (in bytes)
  max_message_size: 65536

# Transfer configuration
transfer:
  # Number of concurrent transfers
  concurrent_transfers: 5
  # Size of each chunk (in bytes)
  chunk_size: 1048576  # 1MB
  # Maximum number of retries for failed chunks
  max_retries: 3
  # Request timeout (in seconds)
  request_timeout: 30
  # Enable or disable resume support
  resume_enabled: true
  # Directory to store resume data
  resume_dir: "./data/resume"
  # Chunk selection strategy (round_robin or rarest_first)
  chunk_selection_strategy: "rarest_first"

# Encryption configuration
encryption:
  # Enable or disable encryption
  enabled: true
  # Directory to store encryption keys
  keys_dir: "./data/keys"
  # Key size (in bits)
  key_size: 2048
  # Key expiration (in days)
  key_expiration: 365

# API configuration
api:
  # Enable or disable the API
  enabled: true
  # Port to listen on for API requests
  port: 8081
  # Enable or disable CORS
  cors_enabled: true
  # Allowed origins for CORS
  cors_allowed_origins:
    - "*"
  # Enable or disable authentication
  auth_enabled: false
  # Authentication token
  auth_token: ""

# Logging configuration
logging:
  # Log level (debug, info, warn, error)
  level: "info"
  # Log format (json or console)
  format: "console"
  # Log file path (empty for stdout)
  file: ""
  # Maximum log file size before rotation (in MB)
  max_size: 100
  # Maximum number of old log files to retain
  max_backups: 5
  # Maximum age of old log files (in days)
  max_age: 30

Loading Configuration

You can load the configuration in your code:

package main

import (
 "github.com/TFMV/furymesh/node"
 "go.uber.org/zap"
)

func main() {
 logger, _ := zap.NewDevelopment()
 defer logger.Sync()

 // Load configuration from file
 config, err := node.LoadConfig("config.yaml")
 if err != nil {
  logger.Fatal("Failed to load config", zap.Error(err))
 }

 // Create a node with the loaded configuration
 n, err := node.NewNodeWithConfig(logger, config)
 if err != nil {
  logger.Fatal("Failed to create node", zap.Error(err))
 }

 // Start the node
 if err := n.Start(); err != nil {
  logger.Fatal("Failed to start node", zap.Error(err))
 }
 defer n.Stop()

 // ...
}

Configuration Options

Node Configuration

Option Description Default
node.id Unique identifier for this node Random UUID
node.port Port to listen on for incoming connections 8080
node.data_dir Directory to store data "./data"
node.max_connections Maximum number of concurrent connections 100
node.debug Enable or disable debug mode false

DHT Configuration

Option Description Default
dht.bootstrap_peers Known peers to bootstrap with []
dht.bucket_size Size of the routing table buckets 20
dht.alpha Alpha parameter for Kademlia (number of parallel lookups) 3
dht.refresh_interval Interval for refreshing buckets (in seconds) 3600
dht.operation_timeout Timeout for DHT operations (in seconds) 30

WebRTC Configuration

Option Description Default
webrtc.stun_servers STUN servers for NAT traversal ["stun:stun.l.google.com:19302"]
webrtc.turn_servers TURN servers for fallback relay []
webrtc.ice_gathering_timeout ICE candidate gathering timeout (in seconds) 5
webrtc.max_message_size Maximum message size (in bytes) 65536

Transfer Configuration

Option Description Default
transfer.concurrent_transfers Number of concurrent transfers 5
transfer.chunk_size Size of each chunk (in bytes) 1048576 (1MB)
transfer.max_retries Maximum number of retries for failed chunks 3
transfer.request_timeout Request timeout (in seconds) 30
transfer.resume_enabled Enable or disable resume support true
transfer.resume_dir Directory to store resume data "./data/resume"
transfer.chunk_selection_strategy Chunk selection strategy (round_robin or rarest_first) "rarest_first"

Encryption Configuration

Option Description Default
encryption.enabled Enable or disable encryption true
encryption.keys_dir Directory to store encryption keys "./data/keys"
encryption.key_size Key size (in bits) 2048
encryption.key_expiration Key expiration (in days) 365

API Configuration

Option Description Default
api.enabled Enable or disable the API true
api.port Port to listen on for API requests 8081
api.cors_enabled Enable or disable CORS true
api.cors_allowed_origins Allowed origins for CORS ["*"]
api.auth_enabled Enable or disable authentication false
api.auth_token Authentication token ""

Logging Configuration

Option Description Default
logging.level Log level (debug, info, warn, error) "info"
logging.format Log format (json or console) "console"
logging.file Log file path (empty for stdout) ""
logging.max_size Maximum log file size before rotation (in MB) 100
logging.max_backups Maximum number of old log files to retain 5
logging.max_age Maximum age of old log files (in days) 30

Environment Variables

All configuration options can also be set using environment variables. The environment variable names are derived from the configuration keys by converting them to uppercase and replacing dots with underscores.

For example:

  • node.id becomes NODE_ID
  • dht.bootstrap_peers becomes DHT_BOOTSTRAP_PEERS
  • webrtc.stun_servers becomes WEBRTC_STUN_SERVERS

For array values, use comma-separated strings:

export DHT_BOOTSTRAP_PEERS="peer1.example.com:8080,peer2.example.com:8080"
export WEBRTC_STUN_SERVERS="stun:stun.l.google.com:19302,stun:stun1.l.google.com:19302"

Command Line Flags

FuryMesh also supports command line flags for common configuration options:

# Start a node with custom configuration
furymesh start --config /path/to/config.yaml --port 8080 --data-dir ./data

Available flags:

  • --config: Path to the configuration file
  • --port: Port to listen on for incoming connections
  • --data-dir: Directory to store data
  • --debug: Enable debug mode
  • --log-level: Log level (debug, info, warn, error)
  • --bootstrap: Comma-separated list of bootstrap peers

Command line flags take precedence over environment variables and configuration file values.

Next Steps

Now that you understand how to configure FuryMesh, you can: