Skip to content

Commit b064ffa

Browse files
committed
Use llu int as unique conn id, much simpler than uuid
1 parent 137f017 commit b064ffa

File tree

6 files changed

+10
-31
lines changed

6 files changed

+10
-31
lines changed

GNUmakefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ endif
117117

118118
### Autodetected features
119119

120-
# Autodetect OpenBSD, for uuid_to_string().
121-
ifeq ($(shell uname),OpenBSD)
122-
FEATURES+= -DOPENBSD
123-
endif
124-
125120
# Autodetect pf
126121
ifneq ($(wildcard /usr/include/net/pfvar.h),)
127122
FEATURES+= -DHAVE_PF

proxy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "pxythrmgr.h"
3434

3535
#include <sys/syslog.h>
36-
#include <uuid.h>
3736

3837
typedef struct proxy_ctx proxy_ctx_t;
3938

pxyconn.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,11 @@ pxy_conn_ctx_new(evutil_socket_t fd,
126126
}
127127
memset(ctx, 0, sizeof(pxy_conn_ctx_t));
128128

129-
ctx->uuid = malloc(sizeof(uuid_t));
130-
if (!ctx->uuid) {
131-
log_err_level_printf(LOG_CRIT, "Error allocating memory\n");
132-
evutil_closesocket(fd);
133-
free(ctx);
134-
return NULL;
135-
}
129+
ctx->id = thrmgr->conn_count++;
136130

137-
uuid_create(ctx->uuid, NULL);
138-
139-
#if defined (DEBUG_PROXY) && defined (OPENBSD)
140-
char *uuid_str;
141-
uuid_to_string(ctx->uuid, &uuid_str, NULL);
142-
if (uuid_str) {
143-
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_ctx_new: uuid=%s, fd=%d\n", uuid_str, fd);
144-
free(uuid_str);
145-
}
146-
#endif /* OPENBSD && DEBUG_PROXY */
131+
#if defined (DEBUG_PROXY)
132+
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_conn_ctx_new: id=%llu, fd=%d\n", ctx->id, fd);
133+
#endif /* DEBUG_PROXY */
147134

148135
ctx->fd = fd;
149136
ctx->thrmgr = thrmgr;
@@ -427,9 +414,6 @@ pxy_conn_ctx_free(pxy_conn_ctx_t *ctx, int by_requestor)
427414
if (ctx->ev) {
428415
event_free(ctx->ev);
429416
}
430-
if (ctx->uuid) {
431-
free(ctx->uuid);
432-
}
433417
if (ctx->sni) {
434418
free(ctx->sni);
435419
}

pxyconn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct pxy_conn_ctx {
130130
pxy_thr_ctx_t *thr;
131131

132132
// Unique id of the conn
133-
uuid_t *uuid;
133+
long long unsigned int id;
134134

135135
pxy_thrmgr_ctx_t *thrmgr;
136136
proxyspec_t *spec;

pxythrmgr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,19 +503,19 @@ pxy_thrmgr_remove_conn(pxy_conn_ctx_t *node, pxy_conn_ctx_t **head)
503503
assert(*head != NULL);
504504

505505
#ifdef DEBUG_PROXY
506-
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_thrmgr_remove_conn: Removing conn, fd=%d, child_fd=%d\n", node->fd, node->child_fd);
506+
log_dbg_level_printf(LOG_DBG_MODE_FINEST, "pxy_thrmgr_remove_conn: Removing conn, id=%llu, fd=%d, child_fd=%d\n", node->id, node->fd, node->child_fd);
507507
#endif /* DEBUG_PROXY */
508508

509-
// @attention We may get multiple conns with the same fd combinations, so fds cannot uniquely define a conn; hence the need for uuids.
510-
if (uuid_compare(node->uuid, (*head)->uuid, NULL) == 0) {
509+
// @attention We may get multiple conns with the same fd combinations, so fds cannot uniquely define a conn; hence the need for unique ids.
510+
if (node->id == (*head)->id) {
511511
*head = (*head)->next;
512512
return;
513513
}
514514

515515
pxy_conn_ctx_t *current = (*head)->next;
516516
pxy_conn_ctx_t *previous = *head;
517517
while (current != NULL && previous != NULL) {
518-
if (uuid_compare(node->uuid, current->uuid, NULL) == 0) {
518+
if (node->id == current->id) {
519519
previous->next = current->next;
520520
return;
521521
}

pxythrmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct pxy_thrmgr_ctx {
7272
opts_t *opts;
7373
pxy_thr_ctx_t **thr;
7474
pthread_mutex_t mutex;
75+
long long unsigned int conn_count;
7576
};
7677

7778
pxy_thrmgr_ctx_t * pxy_thrmgr_new(opts_t *) MALLOC;

0 commit comments

Comments
 (0)