v0.7.26 - Tidy up api
This commit is contained in:
@@ -256,6 +256,9 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
|
||||
memcpy(pss->client_ip, client_ip, copy_len);
|
||||
pss->client_ip[copy_len] = '\0';
|
||||
|
||||
// Record connection establishment time for duration tracking
|
||||
pss->connection_established = time(NULL);
|
||||
|
||||
DEBUG_LOG("WebSocket connection established from %s", pss->client_ip);
|
||||
|
||||
// Initialize NIP-42 authentication state
|
||||
@@ -913,10 +916,38 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
|
||||
|
||||
case LWS_CALLBACK_CLOSED:
|
||||
DEBUG_TRACE("WebSocket connection closed");
|
||||
DEBUG_LOG("WebSocket connection closed from %s", pss ? pss->client_ip : "unknown");
|
||||
|
||||
// Clean up session subscriptions
|
||||
|
||||
// Enhanced closure logging with detailed diagnostics
|
||||
if (pss) {
|
||||
// Calculate connection duration
|
||||
time_t now = time(NULL);
|
||||
long duration = (pss->connection_established > 0) ?
|
||||
(long)(now - pss->connection_established) : 0;
|
||||
|
||||
// Determine closure reason
|
||||
const char* reason = "client_disconnect";
|
||||
if (g_shutdown_flag || !g_server_running) {
|
||||
reason = "server_shutdown";
|
||||
}
|
||||
|
||||
// Format authentication status
|
||||
char auth_status[80];
|
||||
if (pss->authenticated && strlen(pss->authenticated_pubkey) > 0) {
|
||||
// Show first 8 chars of pubkey for identification
|
||||
snprintf(auth_status, sizeof(auth_status), "yes(%.8s...)", pss->authenticated_pubkey);
|
||||
} else {
|
||||
snprintf(auth_status, sizeof(auth_status), "no");
|
||||
}
|
||||
|
||||
// Log comprehensive closure information
|
||||
DEBUG_LOG("WebSocket CLOSED: ip=%s duration=%lds subscriptions=%d authenticated=%s reason=%s",
|
||||
pss->client_ip,
|
||||
duration,
|
||||
pss->subscription_count,
|
||||
auth_status,
|
||||
reason);
|
||||
|
||||
// Clean up session subscriptions
|
||||
pthread_mutex_lock(&pss->session_lock);
|
||||
|
||||
struct subscription* sub = pss->subscriptions;
|
||||
@@ -931,6 +962,8 @@ static int nostr_relay_callback(struct lws *wsi, enum lws_callback_reasons reaso
|
||||
|
||||
pthread_mutex_unlock(&pss->session_lock);
|
||||
pthread_mutex_destroy(&pss->session_lock);
|
||||
} else {
|
||||
DEBUG_LOG("WebSocket CLOSED: ip=unknown duration=0s subscriptions=0 authenticated=no reason=unknown");
|
||||
}
|
||||
DEBUG_TRACE("WebSocket connection cleanup complete");
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user