143 lines
5.9 KiB
C
143 lines
5.9 KiB
C
#ifndef DEFAULT_CONFIG_EVENT_H
|
|
#define DEFAULT_CONFIG_EVENT_H
|
|
|
|
#include <cjson/cJSON.h>
|
|
#include "config.h" // For cli_options_t definition
|
|
#include "main.h" // For relay metadata constants
|
|
|
|
/*
|
|
* Default Configuration Event Template
|
|
*
|
|
* This header contains the default configuration values for the C Nostr Relay.
|
|
* These values are used to populate the config table during first-time startup.
|
|
*
|
|
* IMPORTANT: These values should never be accessed directly by other parts
|
|
* of the program. They are only used during initial configuration event creation.
|
|
*/
|
|
|
|
// Default configuration key-value pairs
|
|
static const struct {
|
|
const char* key;
|
|
const char* value;
|
|
} DEFAULT_CONFIG_VALUES[] = {
|
|
// Authentication
|
|
{"auth_enabled", "false"},
|
|
|
|
// NIP-42 Authentication Settings
|
|
{"nip42_auth_required_events", "false"},
|
|
{"nip42_auth_required_subscriptions", "false"},
|
|
{"nip42_auth_required_kinds", "4,14"}, // Default: DM kinds require auth
|
|
{"nip42_challenge_expiration", "600"}, // 10 minutes
|
|
{"nip42_challenge_timeout", "600"}, // Challenge timeout (seconds)
|
|
{"nip42_time_tolerance", "300"}, // Time tolerance (seconds)
|
|
|
|
// NIP-70 Protected Events
|
|
{"nip70_protected_events_enabled", "false"},
|
|
|
|
// Server Core Settings
|
|
{"relay_port", "8888"},
|
|
{"max_connections", "100"},
|
|
|
|
// NIP-11 Relay Information (relay keys will be populated at runtime)
|
|
{"relay_name", RELAY_NAME},
|
|
{"relay_description", RELAY_DESCRIPTION},
|
|
{"relay_contact", RELAY_CONTACT},
|
|
{"relay_software", RELAY_SOFTWARE},
|
|
{"relay_version", RELAY_VERSION},
|
|
{"supported_nips", SUPPORTED_NIPS},
|
|
{"language_tags", LANGUAGE_TAGS},
|
|
{"relay_countries", RELAY_COUNTRIES},
|
|
{"posting_policy", POSTING_POLICY},
|
|
{"payments_url", PAYMENTS_URL},
|
|
|
|
// NIP-13 Proof of Work (pow_min_difficulty = 0 means PoW disabled)
|
|
{"pow_min_difficulty", "0"},
|
|
{"pow_mode", "basic"},
|
|
|
|
// NIP-40 Expiration Timestamp
|
|
{"nip40_expiration_enabled", "true"},
|
|
{"nip40_expiration_strict", "true"},
|
|
{"nip40_expiration_filter", "true"},
|
|
{"nip40_expiration_grace_period", "300"},
|
|
|
|
// Subscription Limits
|
|
{"max_subscriptions_per_client", "25"},
|
|
{"max_total_subscriptions", "5000"},
|
|
{"max_filters_per_subscription", "10"},
|
|
|
|
// Connection Management
|
|
{"max_connection_seconds", "86400"}, // 24 hours (0 = disabled)
|
|
|
|
// Event Processing Limits
|
|
{"max_event_tags", "100"},
|
|
{"max_content_length", "8196"},
|
|
{"max_message_length", "16384"},
|
|
|
|
// Performance Settings
|
|
{"default_limit", "500"},
|
|
{"max_limit", "5000"},
|
|
|
|
// Proxy Settings
|
|
// Trust proxy headers (X-Forwarded-For, X-Real-IP) for accurate client IP detection
|
|
// Safe for informational/debugging use. Only becomes a security concern if you implement
|
|
// IP-based rate limiting or access control (which would require firewall protection anyway)
|
|
{"trust_proxy_headers", "true"},
|
|
|
|
// Debug Level (0=none, 1=errors, 2=warnings, 3=info, 4=debug, 5=trace)
|
|
// Can be changed at runtime without restart via config_set admin command
|
|
{"debug_level", "3"},
|
|
|
|
// IP Auth Failure Ban Settings
|
|
// Ban IPs that repeatedly fail NIP-42 authentication
|
|
{"auth_fail_ban_enabled", "true"},
|
|
{"auth_fail_ban_threshold", "3"}, // failures before ban
|
|
{"auth_fail_window_sec", "60"}, // window to count failures in
|
|
{"auth_fail_ban_duration_sec", "300"}, // initial ban duration (doubles each time, max 24h)
|
|
|
|
// NIP-42 Authentication Timeout
|
|
// Seconds after connection before unauthenticated clients are disconnected (0 = disabled)
|
|
// Prevents unauthenticated connections from accumulating under heavy load
|
|
{"nip42_auth_timeout_sec", "10"},
|
|
|
|
// Idle Connection Ban Settings
|
|
// Ban IPs that connect but never send REQ or EVENT (idle or early disconnect)
|
|
{"idle_connection_timeout_sec", "30"}, // Seconds before idle connection is closed (0 = disabled)
|
|
{"idle_ban_enabled", "true"}, // Whether to ban IPs with idle failures
|
|
{"idle_ban_threshold", "1"}, // Idle failures before ban (1 = ban on first offense)
|
|
{"idle_ban_window_sec", "30"}, // Window to count idle failures in
|
|
{"idle_ban_duration_sec", "300"}, // Initial ban duration (doubles each time, max 24h)
|
|
|
|
// SQLite Performance Tuning
|
|
// mmap_size: bytes of database file to memory-map (0 = disabled, 268435456 = 256MB recommended)
|
|
// Eliminates pread64 syscall overhead for database reads — significant CPU savings under load
|
|
{"sqlite_mmap_size", "268435456"},
|
|
// cache_size_kb: SQLite page cache size in KB (negative = KB, positive = pages of 4KB each)
|
|
// Default 2000KB is too small for a busy relay; 65536KB (64MB) keeps hot data in memory
|
|
{"sqlite_cache_size_kb", "65536"},
|
|
|
|
// NIP-59 Gift Wrap Timestamp Configuration
|
|
{"nip59_timestamp_max_delay_sec", "0"},
|
|
|
|
// Kind 1 Status Posts
|
|
{"kind_1_status_posts_hours", "1"},
|
|
|
|
// Web of Trust Settings
|
|
// 0 = off, 1 = write-only (followed pubkeys can publish), 2 = full (followed pubkeys can publish AND subscribe)
|
|
{"wot_enabled", "0"},
|
|
|
|
// NIP-17 Admin DM Settings
|
|
// When false (default), Kind 1059 gift wrap events are stored normally without expensive decryption attempts.
|
|
// Enable only if you intend to use NIP-17 DMs to send admin commands to the relay.
|
|
{"nip17_admin_enabled", "false"}
|
|
};
|
|
|
|
// Number of default configuration values
|
|
#define DEFAULT_CONFIG_COUNT (sizeof(DEFAULT_CONFIG_VALUES) / sizeof(DEFAULT_CONFIG_VALUES[0]))
|
|
|
|
// Function to create default configuration event
|
|
cJSON* create_default_config_event(const unsigned char* admin_privkey_bytes,
|
|
const char* relay_privkey_hex,
|
|
const char* relay_pubkey_hex,
|
|
const cli_options_t* cli_options);
|
|
|
|
#endif /* DEFAULT_CONFIG_EVENT_H */ |