src/server/daemon/httplistener.c

changeset 557
e35829a3a6d8
parent 554
e0a6b761ddbc
--- a/src/server/daemon/httplistener.c	Sat Aug 24 22:37:12 2024 +0200
+++ b/src/server/daemon/httplistener.c	Fri Sep 13 23:19:04 2024 +0200
@@ -47,6 +47,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <openssl/rand.h> /* RAND_bytes, connection id */
 
 #include <cx/hash_map.h>
 
@@ -652,12 +653,16 @@
         
         // create Connection object
         Connection *conn = malloc(sizeof(Connection));
+        uint32_t conn_id;
+        RAND_bytes((unsigned char*)&conn->id, sizeof(conn->id));
+        conn->id <<= 16;
         conn->address = ca;
         conn->addr_type = addr_type;
         conn->fd = clientfd;
         conn->listener = ls;
         conn->ssl_accepted = 0;
         conn->ssl_error = 0;
+        log_ereport(LOG_DEBUG, "trace reqid: %016llx connection accepted", (unsigned long long int)conn->id);
         if(socket_ssl) {
             // SSL connections are always non-blocking 
             // set socket non blocking
@@ -666,6 +671,7 @@
                 flags = 0;
             }
             if(fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK)) {
+                log_ereport(LOG_DEBUG, "trace reqid: %016llx connection destroyed | fcntl error", (unsigned long long int)conn->id);
                 log_ereport(LOG_FAILURE, "acceptor: fcntl failed: %s", strerror(errno));
                 close(clientfd);
                 free(conn);
@@ -680,6 +686,7 @@
                     conn->write = connection_ssl_write;
                     conn->close = connection_ssl_close;
                 } else {
+                    log_ereport(LOG_DEBUG, "trace reqid: %016llx connection destroyed | SSL init error", (unsigned long long int)conn->id);
                     log_ereport(LOG_FAILURE, "acceptor: %p listener: %p SSL_new() failed", acceptor, acceptor->listener);
                     free(conn);
                     close(clientfd);

mercurial