Files
c-relay/docs/default_config_event_template.md

3.3 KiB

Default Configuration Event Template

This document contains the template for the src/default_config_event.h file that will be created during implementation.

File: src/default_config_event.h

#ifndef DEFAULT_CONFIG_EVENT_H
#define DEFAULT_CONFIG_EVENT_H

/*
 * Default Configuration Event Template
 * 
 * This header contains the default configuration values for the C Nostr Relay.
 * These values are used to create the initial kind 33334 configuration event
 * 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"},
    
    // Server Core Settings
    {"relay_port", "8888"},
    {"max_connections", "100"},
    
    // NIP-11 Relay Information (relay keys will be populated at runtime)
    {"relay_description", "High-performance C Nostr relay with SQLite storage"},
    {"relay_contact", ""},
    {"relay_software", "https://git.laantungir.net/laantungir/c-relay.git"},
    {"relay_version", "v1.0.0"},
    
    // 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"},
    
    // Event Processing Limits
    {"max_event_tags", "100"},
    {"max_content_length", "8196"},
    {"max_message_length", "16384"},
    
    // Performance Settings
    {"default_limit", "500"},
    {"max_limit", "5000"}
};

// 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);

#endif /* DEFAULT_CONFIG_EVENT_H */

Usage Notes

  1. Isolation: These default values are completely isolated from the rest of the program
  2. Single Access Point: Only accessed during create_default_config_event()
  3. Runtime Keys: Relay keys are added at runtime, not stored as defaults
  4. No Direct Access: Other parts of the program should never include this header directly
  5. Clean Separation: Keeps default configuration separate from configuration logic

Function Implementation

The create_default_config_event() function will:

  1. Create a new cJSON event object with kind 33334
  2. Add all default configuration values as tags
  3. Add runtime-generated relay keys as tags
  4. Use nostr_core_lib to sign the event with admin private key
  5. Return the complete signed event ready for database storage

This approach ensures clean separation between default values and the configuration system logic.