v0.7.6 - Delete more old debugging prints

This commit is contained in:
Your Name
2025-10-10 13:38:18 -04:00
parent 00d16f8615
commit 00a8f16262
7 changed files with 26 additions and 194 deletions

View File

@@ -132,7 +132,6 @@ void force_config_cache_refresh(void) {
g_unified_cache.cache_valid = 0;
g_unified_cache.cache_expires = 0;
pthread_mutex_unlock(&g_unified_cache.cache_lock);
log_info("Configuration cache forcibly invalidated");
}
// Update specific cache value without full refresh
@@ -211,7 +210,6 @@ int update_cache_value(const char* key, const char* value) {
pthread_mutex_unlock(&g_unified_cache.cache_lock);
log_info("Updated specific cache value");
printf(" Key: %s\n", key);
return 0;
}
@@ -223,8 +221,6 @@ static int refresh_unified_cache_from_table(void) {
return -1;
}
log_info("Refreshing unified configuration cache from database");
// Lock the cache for update (don't memset entire cache to avoid wiping relay_info)
pthread_mutex_lock(&g_unified_cache.cache_lock);
@@ -361,7 +357,6 @@ static int refresh_unified_cache_from_table(void) {
pthread_mutex_unlock(&g_unified_cache.cache_lock);
log_info("Unified configuration cache refreshed from database");
return 0;
}
@@ -502,7 +497,6 @@ int create_database_with_relay_pubkey(const char* relay_pubkey) {
strncpy(g_database_path, db_name, sizeof(g_database_path) - 1);
g_database_path[sizeof(g_database_path) - 1] = '\0';
log_info("Creating database with relay pubkey");
printf(" Database: %s\n", db_name);
free(db_name);
@@ -562,7 +556,6 @@ int store_config_event_in_database(const cJSON* event) {
free(tags_str);
if (rc == SQLITE_DONE) {
log_success("Configuration event stored in database");
return 0;
} else {
log_error("Failed to store configuration event");
@@ -576,7 +569,6 @@ cJSON* load_config_event_from_database(const char* relay_pubkey) {
}
// Configuration is now managed through config table, not events
log_info("Configuration events are no longer stored in events table");
return NULL;
}
@@ -793,8 +785,6 @@ int init_configuration_system(const char* config_dir_override, const char* confi
(void)config_dir_override;
(void)config_file_override;
log_info("Initializing event-based configuration system...");
// Initialize unified cache with proper structure initialization
pthread_mutex_lock(&g_unified_cache.cache_lock);
@@ -839,14 +829,11 @@ int init_configuration_system(const char* config_dir_override, const char* confi
g_unified_cache.nip70_protected_events_enabled = 0;
pthread_mutex_unlock(&g_unified_cache.cache_lock);
log_success("Event-based configuration system initialized with unified cache structures");
return 0;
}
void cleanup_configuration_system(void) {
log_info("Cleaning up configuration system...");
if (g_current_config) {
cJSON_Delete(g_current_config);
g_current_config = NULL;
@@ -907,7 +894,6 @@ void cleanup_configuration_system(void) {
memset(&g_unified_cache.expiration_config, 0, sizeof(g_unified_cache.expiration_config));
pthread_mutex_unlock(&g_unified_cache.cache_lock);
log_success("Configuration system cleaned up with proper JSON cleanup");
}
int set_database_config(const char* key, const char* value, const char* changed_by) {
@@ -1001,7 +987,6 @@ int store_relay_private_key(const char* relay_privkey_hex) {
sqlite3_finalize(stmt);
if (rc == SQLITE_DONE) {
log_success("Relay private key stored securely in database");
return 0;
} else {
log_error("Failed to store relay private key in database");
@@ -1064,8 +1049,6 @@ cJSON* create_default_config_event(const unsigned char* admin_privkey_bytes,
return NULL;
}
log_info("Creating default configuration event...");
// Create tags array with default configuration values
cJSON* tags = cJSON_CreateArray();
if (!tags) {
@@ -1101,7 +1084,6 @@ cJSON* create_default_config_event(const unsigned char* admin_privkey_bytes,
char port_str[16];
snprintf(port_str, sizeof(port_str), "%d", cli_options->port_override);
cJSON_AddItemToArray(tag, cJSON_CreateString(port_str));
log_info("Using command line port override in configuration event");
printf(" Port: %d (overriding default %s)\n", cli_options->port_override, DEFAULT_CONFIG_VALUES[i].value);
} else {
cJSON_AddItemToArray(tag, cJSON_CreateString(value));
@@ -1134,7 +1116,6 @@ cJSON* create_default_config_event(const unsigned char* admin_privkey_bytes,
cJSON* pubkey_obj = cJSON_GetObjectItem(event, "pubkey");
if (id_obj && pubkey_obj) {
log_success("Default configuration event created successfully");
printf(" Event ID: %s\n", cJSON_GetStringValue(id_obj));
printf(" Admin Public Key: %s\n", cJSON_GetStringValue(pubkey_obj));
}
@@ -1147,7 +1128,6 @@ cJSON* create_default_config_event(const unsigned char* admin_privkey_bytes,
// ================================
int first_time_startup_sequence(const cli_options_t* cli_options) {
log_info("Starting first-time startup sequence...");
// 1. Generate or use provided admin keypair
unsigned char admin_privkey_bytes[32];
@@ -1156,7 +1136,6 @@ int first_time_startup_sequence(const cli_options_t* cli_options) {
if (cli_options && strlen(cli_options->admin_pubkey_override) == 64) {
// Use provided admin public key directly - skip private key generation entirely
log_info("Using provided admin public key override - skipping private key generation");
strncpy(admin_pubkey, cli_options->admin_pubkey_override, sizeof(admin_pubkey) - 1);
admin_pubkey[sizeof(admin_pubkey) - 1] = '\0';
@@ -1178,7 +1157,6 @@ int first_time_startup_sequence(const cli_options_t* cli_options) {
generated_admin_key = 0; // Did not generate a new key
} else {
// Generate random admin keypair using /dev/urandom + nostr_core_lib
log_info("Generating random admin keypair");
if (generate_random_private_key_bytes(admin_privkey_bytes) != 0) {
log_error("Failed to generate admin private key");
return -1;
@@ -1201,7 +1179,6 @@ int first_time_startup_sequence(const cli_options_t* cli_options) {
if (cli_options && strlen(cli_options->relay_privkey_override) == 64) {
// Use provided relay private key
log_info("Using provided relay private key override");
strncpy(relay_privkey, cli_options->relay_privkey_override, sizeof(relay_privkey) - 1);
relay_privkey[sizeof(relay_privkey) - 1] = '\0';
@@ -1249,10 +1226,8 @@ int first_time_startup_sequence(const cli_options_t* cli_options) {
// 5. Store relay private key in temporary storage for later secure storage
strncpy(g_temp_relay_privkey, relay_privkey, sizeof(g_temp_relay_privkey) - 1);
g_temp_relay_privkey[sizeof(g_temp_relay_privkey) - 1] = '\0';
log_info("Relay private key cached for secure storage after database initialization");
// 6. Handle configuration setup - defaults will be populated after database initialization
log_info("Configuration setup prepared - defaults will be populated after database initialization");
// CLI overrides will be applied after database initialization in main.c
@@ -1285,7 +1260,6 @@ int first_time_startup_sequence(const cli_options_t* cli_options) {
printf("\n");
}
log_success("First-time startup sequence completed");
return 0;
}
@@ -1295,7 +1269,6 @@ int startup_existing_relay(const char* relay_pubkey) {
return -1;
}
log_info("Starting existing relay...");
printf(" Relay pubkey: %s\n", relay_pubkey);
// Store relay pubkey in unified cache
@@ -1321,12 +1294,9 @@ int startup_existing_relay(const char* relay_pubkey) {
}
// Configuration will be migrated from events to table after database initialization
log_info("Configuration migration will be performed after database is available");
// Load configuration event from database (after database is initialized)
// This will be done in apply_configuration_from_database()
log_success("Existing relay startup prepared");
return 0;
}
@@ -1724,7 +1694,6 @@ static int validate_configuration_event_fields(const cJSON* event, char* error_m
return -1;
}
log_info("Validating configuration event fields...");
cJSON* tags = cJSON_GetObjectItem(event, "tags");
if (!tags || !cJSON_IsArray(tags)) {
@@ -1779,10 +1748,7 @@ static int validate_configuration_event_fields(const cJSON* event, char* error_m
log_error(summary);
return -1;
}
char success_msg[256];
snprintf(success_msg, sizeof(success_msg), "%d configuration fields validated successfully", validated_fields);
log_success(success_msg);
return 0;
}
@@ -1817,22 +1783,19 @@ int process_configuration_event(const cJSON* event) {
}
// Comprehensive event validation using nostr_core_lib
log_info("Validating configuration event structure and signature...");
// First validate the event structure (fields, format, etc.)
if (nostr_validate_event_structure((cJSON*)event) != NOSTR_SUCCESS) {
log_error("Configuration event has invalid structure");
return -1;
}
// Then validate the cryptographic signature
if (nostr_verify_event_signature((cJSON*)event) != NOSTR_SUCCESS) {
log_error("Configuration event has invalid signature");
return -1;
}
log_success("Configuration event structure and signature validated successfully");
// NEW: Validate configuration field values
char validation_error[512];
if (validate_configuration_event_fields(event, validation_error, sizeof(validation_error)) != 0) {
@@ -2292,8 +2255,6 @@ int process_admin_event_in_config(cJSON* event, char* error_message, size_t erro
// Handle legacy Kind 33334 configuration management events
int process_admin_config_event(cJSON* event, char* error_message, size_t error_size) {
cJSON* kind_obj = cJSON_GetObjectItem(event, "kind");
int kind = kind_obj ? (int)cJSON_GetNumberValue(kind_obj) : 0;
// Parse tags to find query commands according to API specification
cJSON* tags_obj = cJSON_GetObjectItem(event, "tags");
@@ -2551,7 +2512,6 @@ cJSON* create_admin_response_event(const char* encrypted_content, const char* re
return NULL;
}
log_info("Creating signed kind 23457 admin response event");
printf(" Recipient pubkey: %.16s...\n", recipient_pubkey);
printf(" Encrypted content length: %zu\n", strlen(encrypted_content));
@@ -2610,7 +2570,6 @@ cJSON* create_admin_response_event(const char* encrypted_content, const char* re
cJSON* pubkey_obj = cJSON_GetObjectItem(response_event, "pubkey");
if (id_obj && pubkey_obj) {
log_success("Kind 23457 admin response event created and signed successfully");
printf(" Event ID: %s\n", cJSON_GetStringValue(id_obj));
printf(" Relay pubkey: %.16s...\n", cJSON_GetStringValue(pubkey_obj));
}
@@ -2625,17 +2584,15 @@ char* encrypt_admin_response_content(const cJSON* response_data, const char* rec
return NULL;
}
log_info("Encrypting admin response content with NIP-44");
printf(" Recipient pubkey: %.16s...\n", recipient_pubkey);
// Convert response data to JSON string
char* response_json = cJSON_Print(response_data);
if (!response_json) {
log_error("Failed to serialize response data for encryption");
return NULL;
}
log_info("Response data serialized for encryption");
printf(" JSON length: %zu\n", strlen(response_json));
printf(" JSON preview: %.100s%s\n", response_json,
strlen(response_json) > 100 ? "..." : "");
@@ -2683,8 +2640,7 @@ char* encrypt_admin_response_content(const cJSON* response_data, const char* rec
printf(" Encryption result code: %d\n", encrypt_result);
return NULL;
}
log_success("Admin response content encrypted successfully with NIP-44");
printf(" Encrypted content length: %zu\n", strlen(encrypted_content));
printf(" Encrypted preview: %.50s...\n", encrypted_content);
@@ -2701,7 +2657,6 @@ int send_admin_response_event(const cJSON* response_data, const char* recipient_
return -1;
}
log_info("Sending admin response as signed kind 23457 event through relay distribution system");
printf(" Recipient pubkey: %.16s...\n", recipient_pubkey);
// Step 1: Encrypt response data using NIP-44
@@ -2720,18 +2675,15 @@ int send_admin_response_event(const cJSON* response_data, const char* recipient_
return -1;
}
log_info("Admin response event created successfully");
cJSON* id_obj = cJSON_GetObjectItem(response_event, "id");
if (id_obj) {
printf(" Event ID: %s\n", cJSON_GetStringValue(id_obj));
}
// Step 3: Store event in database for persistence
extern int store_event(cJSON* event);
if (store_event(response_event) != 0) {
log_warning("Failed to store admin response event in database (continuing with broadcast)");
} else {
log_info("Admin response event stored in database successfully");
}
// Step 4: Broadcast event to all matching subscriptions using relay's standard system
@@ -2739,10 +2691,9 @@ int send_admin_response_event(const cJSON* response_data, const char* recipient_
int broadcast_count = broadcast_event_to_subscriptions(response_event);
if (broadcast_count >= 0) {
log_success("Admin response event distributed through relay subscription system");
printf(" Event kind: 23457 (admin response)\n");
printf(" Subscriptions notified: %d\n", broadcast_count);
// Clean up and return success - event creation succeeded regardless of broadcast count
cJSON_Delete(response_event);
return 0;
@@ -3148,7 +3099,6 @@ int handle_auth_query_unified(cJSON* event, const char* query_type, char* error_
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
printf("Total results: %d\n", rule_count);
log_success("Auth query completed successfully with signed response");
printf(" Response query_type: %s (mapped from %s)\n", mapped_query_type, query_type);
cJSON_Delete(response);
cJSON_Delete(results_array);
@@ -3272,7 +3222,6 @@ int handle_config_query_unified(cJSON* event, const char* query_type, char* erro
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
printf("Total results: %d\n", config_count);
log_success("Config query completed successfully with signed response");
printf(" Response query_type: %s (mapped from %s)\n", mapped_query_type, query_type);
cJSON_Delete(response);
cJSON_Delete(results_array);
@@ -3358,7 +3307,6 @@ int handle_config_set_unified(cJSON* event, const char* config_key, const char*
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Config set command completed successfully with signed response");
cJSON_Delete(response);
return 0;
}
@@ -3424,7 +3372,6 @@ int handle_system_command_unified(cJSON* event, const char* command, char* error
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Clear auth rules command completed successfully with signed response");
cJSON_Delete(response);
return 0;
}
@@ -3503,7 +3450,6 @@ int handle_system_command_unified(cJSON* event, const char* command, char* error
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Delete auth rule command completed successfully with signed response");
cJSON_Delete(response);
return 0;
}
@@ -3565,7 +3511,6 @@ int handle_system_command_unified(cJSON* event, const char* command, char* error
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("System status query completed successfully with signed response");
cJSON_Delete(response);
return 0;
}
@@ -3598,11 +3543,8 @@ int handle_system_command_unified(cJSON* event, const char* command, char* error
// Send acknowledgment response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Restart acknowledgment sent successfully - initiating shutdown");
// Trigger graceful shutdown by setting the global shutdown flag
g_shutdown_flag = 1;
log_info("Shutdown flag set - relay will restart gracefully");
cJSON_Delete(response);
return 0;
@@ -3716,7 +3658,6 @@ int handle_auth_rule_modification_unified(cJSON* event, char* error_message, siz
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Auth rule modification completed successfully with signed response");
cJSON_Delete(response);
return 0;
}
@@ -3851,7 +3792,6 @@ int handle_stats_query_unified(cJSON* event, char* error_message, size_t error_s
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Stats query completed successfully with signed response");
cJSON_Delete(response);
return 0;
}
@@ -4229,7 +4169,6 @@ int handle_config_update_unified(cJSON* event, char* error_message, size_t error
// Send response as signed kind 23457 event
if (send_admin_response_event(response, admin_pubkey, wsi) == 0) {
log_success("Config update command completed successfully with signed response");
printf(" Response query_type: config_update\n");
cJSON_Delete(response);
return 0;