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

@@ -226,7 +226,6 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
free(session_data);
lws_set_wsi_user(wsi, NULL);
log_success("NIP-11 relay information served successfully");
return 0; // Close connection after successful transmission
}
} else if (type == 1) {
@@ -238,7 +237,6 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
break;
case LWS_CALLBACK_ESTABLISHED:
log_info("WebSocket connection established");
memset(pss, 0, sizeof(*pss));
pthread_mutex_init(&pss->session_lock, NULL);
@@ -510,7 +508,6 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
// Log reception of Kind 23456 events
if (event_kind == 23456) {
log_info("Received admin event (kind 23456)");
}
if (event_kind == 23456) {
@@ -529,19 +526,13 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
error_message[copy_len] = '\0';
} else {
// Authorization successful - process through admin API
log_info("Processing authorized admin event");
char admin_error[512] = {0};
int admin_result = process_admin_event_in_config(event, admin_error, sizeof(admin_error), wsi);
// Log results for Kind 23456 events
if (event_kind == 23456) {
if (admin_result == 0) {
char success_result_msg[256];
snprintf(success_result_msg, sizeof(success_result_msg),
"SUCCESS: Kind %d event processed successfully", event_kind);
log_success(success_result_msg);
} else {
if (admin_result != 0) {
char error_result_msg[512];
snprintf(error_result_msg, sizeof(error_result_msg),
"ERROR: Kind %d event processing failed: %s", event_kind, admin_error);
@@ -557,13 +548,11 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
memcpy(error_message, admin_error, copy_len);
error_message[copy_len] = '\0';
} else {
log_success("Admin event processed successfully");
// Admin events are processed by the admin API, not broadcast to subscriptions
}
}
} else if (event_kind == 1059) {
// Check for NIP-17 gift wrap admin messages
log_info("Processing NIP-17 gift wrap event");
char nip17_error[512] = {0};
cJSON* response_event = process_nip17_admin_message(event, nip17_error, sizeof(nip17_error), wsi);
@@ -581,18 +570,14 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
} else {
// No error message means the command was already handled (plain text commands)
log_success("NIP-17 admin message processed successfully");
// Store the original gift wrap event in database
if (store_event(event) != 0) {
log_error("Failed to store gift wrap event in database");
result = -1;
strncpy(error_message, "error: failed to store gift wrap event", sizeof(error_message) - 1);
} else {
log_info("Gift wrap event stored successfully in database");
}
}
} else {
log_success("NIP-17 admin message processed successfully");
// Store the original gift wrap event in database (unlike kind 23456)
if (store_event(event) != 0) {
log_error("Failed to store gift wrap event in database");
@@ -600,18 +585,15 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
strncpy(error_message, "error: failed to store gift wrap event", sizeof(error_message) - 1);
cJSON_Delete(response_event);
} else {
log_info("Gift wrap event stored successfully in database");
// Broadcast RESPONSE event to matching persistent subscriptions
broadcast_event_to_subscriptions(response_event);
// Clean up response event
cJSON_Delete(response_event);
}
}
} else if (event_kind == 14) {
// Check for DM stats commands addressed to relay
log_info("Processing DM event");
char dm_error[512] = {0};
int dm_result = process_dm_stats_command(event, dm_error, sizeof(dm_error), wsi);
@@ -625,27 +607,23 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
error_message[copy_len] = '\0';
} else {
log_success("DM stats command processed successfully");
// Store the DM event in database
if (store_event(event) != 0) {
log_error("Failed to store DM event in database");
result = -1;
strncpy(error_message, "error: failed to store DM event", sizeof(error_message) - 1);
} else {
log_info("DM event stored successfully in database");
// Broadcast DM event to matching persistent subscriptions
broadcast_event_to_subscriptions(event);
}
}
} else {
// Regular event - store in database and broadcast
log_info("Storing regular event in database");
if (store_event(event) != 0) {
log_error("Failed to store event in database");
result = -1;
strncpy(error_message, "error: failed to store event", sizeof(error_message) - 1);
} else {
log_info("Event stored successfully in database");
// Broadcast event to matching persistent subscriptions
broadcast_event_to_subscriptions(event);
}
@@ -658,7 +636,6 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
result = -1;
strncpy(error_message, "error: failed to store event", sizeof(error_message) - 1);
} else {
log_info("Event without kind stored successfully in database");
broadcast_event_to_subscriptions(event);
}
}
@@ -802,9 +779,7 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
pthread_mutex_unlock(&pss->session_lock);
}
char debug_msg[256];
snprintf(debug_msg, sizeof(debug_msg), "Closed subscription: %s", subscription_id);
log_info(debug_msg);
// Subscription closed
}
} else if (strcmp(msg_type, "AUTH") == 0) {
// Handle NIP-42 AUTH message
@@ -842,7 +817,6 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
break;
case LWS_CALLBACK_CLOSED:
log_info("WebSocket connection closed");
// Clean up session subscriptions
if (pss) {
@@ -922,7 +896,7 @@ int check_port_available(int port) {
int start_websocket_relay(int port_override, int strict_port) {
struct lws_context_creation_info info;
log_info("Starting libwebsockets-based Nostr relay server...");
// Starting libwebsockets-based Nostr relay server
memset(&info, 0, sizeof(info));
// Use port override if provided, otherwise use configuration
@@ -950,9 +924,7 @@ int start_websocket_relay(int port_override, int strict_port) {
// Find an available port with pre-checking (or fail immediately in strict mode)
while (port_attempts < (strict_port ? 1 : max_port_attempts)) {
char attempt_msg[256];
snprintf(attempt_msg, sizeof(attempt_msg), "Checking port availability: %d", actual_port);
log_info(attempt_msg);
// Checking port availability
// Pre-check if port is available
if (!check_port_available(actual_port)) {
@@ -983,9 +955,7 @@ int start_websocket_relay(int port_override, int strict_port) {
// Port appears available, try creating libwebsockets context
info.port = actual_port;
char binding_msg[256];
snprintf(binding_msg, sizeof(binding_msg), "Attempting to bind libwebsockets to port %d", actual_port);
log_info(binding_msg);
// Attempting to bind libwebsockets
ws_context = lws_create_context(&info);
if (ws_context) {
@@ -1036,7 +1006,6 @@ int start_websocket_relay(int port_override, int strict_port) {
} else {
snprintf(startup_msg, sizeof(startup_msg), "WebSocket relay started on ws://127.0.0.1:%d", actual_port);
}
log_success(startup_msg);
// Main event loop with proper signal handling
while (g_server_running && !g_shutdown_flag) {
@@ -1048,11 +1017,8 @@ int start_websocket_relay(int port_override, int strict_port) {
}
}
log_info("Shutting down WebSocket server...");
lws_context_destroy(ws_context);
ws_context = NULL;
log_success("WebSocket relay shut down cleanly");
return 0;
}
@@ -1166,7 +1132,7 @@ int process_dm_stats_command(cJSON* dm_event, char* error_message, size_t error_
return 0;
}
log_info("Processing DM stats command from admin");
// Processing DM stats command from admin
// Generate stats JSON
char* stats_json = generate_stats_json();
@@ -1217,15 +1183,10 @@ int process_dm_stats_command(cJSON* dm_event, char* error_message, size_t error_
}
// Broadcast to subscriptions
int broadcast_count = broadcast_event_to_subscriptions(dm_response);
char broadcast_msg[128];
snprintf(broadcast_msg, sizeof(broadcast_msg),
"DM stats response broadcast to %d subscriptions", broadcast_count);
log_info(broadcast_msg);
broadcast_event_to_subscriptions(dm_response);
cJSON_Delete(dm_response);
log_success("DM stats command processed successfully");
return 0;
}
@@ -1233,7 +1194,6 @@ int process_dm_stats_command(cJSON* dm_event, char* error_message, size_t error_
// Handle NIP-45 COUNT message
int handle_count_message(const char* sub_id, cJSON* filters, struct lws *wsi, struct per_session_data *pss) {
(void)pss; // Suppress unused parameter warning
log_info("Handling COUNT message for subscription");
if (!cJSON_IsArray(filters)) {
log_error("COUNT filters is not an array");
@@ -1423,10 +1383,7 @@ int handle_count_message(const char* sub_id, cJSON* filters, struct lws *wsi, st
remaining = sizeof(sql) - strlen(sql);
}
// Debug: Log the SQL query being executed
char debug_msg[1280];
snprintf(debug_msg, sizeof(debug_msg), "Executing COUNT SQL: %s", sql);
log_info(debug_msg);
// Execute count query
// Execute count query
sqlite3_stmt* stmt;
@@ -1443,17 +1400,13 @@ int handle_count_message(const char* sub_id, cJSON* filters, struct lws *wsi, st
filter_count = sqlite3_column_int(stmt, 0);
}
char count_debug[128];
snprintf(count_debug, sizeof(count_debug), "Filter %d returned count: %d", i + 1, filter_count);
log_info(count_debug);
// Filter count calculated
sqlite3_finalize(stmt);
total_count += filter_count;
}
char total_debug[128];
snprintf(total_debug, sizeof(total_debug), "Total COUNT result: %d", total_count);
log_info(total_debug);
// Total count calculated
// Send COUNT response - NIP-45 format: ["COUNT", <subscription_id>, {"count": <count>}]
cJSON* count_response = cJSON_CreateArray();