summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-05-09 22:30:06 +0200
committerUros Majstorovic <majstor@majstor.org>2024-05-09 22:30:06 +0200
commitb920bef61388a73df4365035119434e10047260e (patch)
tree797fce7082143418a7fa2c633d9b791476db8c8f
parentada578323291eb51cc9524b4e07963e330b54c1d (diff)
fixed gc table seach, added gc table count
-rw-r--r--ecp/src/ecp/core.c48
-rw-r--r--ecp/src/ecp/core.h3
2 files changed, 47 insertions, 4 deletions
diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c
index 9fd857b..8ae0323 100644
--- a/ecp/src/ecp/core.c
+++ b/ecp/src/ecp/core.c
@@ -643,7 +643,7 @@ void ecp_sock_expire(ECPSocket *sock, ecp_conn_expired_t conn_expired) {
conn_table_expire(sock, conn_expired);
}
-ECPConnection *ecp_sock_search_gc(ECPSocket *sock, ecp_ecdh_public_t *public) {
+ECPConnection *ecp_sock_gct_search(ECPSocket *sock, ecp_ecdh_public_t *public) {
ECPConnection *conn = NULL;
int i, rv;
@@ -659,7 +659,7 @@ ECPConnection *ecp_sock_search_gc(ECPSocket *sock, ecp_ecdh_public_t *public) {
}
#ifdef ECP_WITH_PTHREAD
- pthread_mutex_lock(&sock->conn_table.mutex_gc);
+ pthread_mutex_unlock(&sock->conn_table.mutex_gc);
#endif
#else /* ECP_WITH_HTABLE */
#ifdef ECP_WITH_PTHREAD
@@ -687,13 +687,55 @@ ECPConnection *ecp_sock_search_gc(ECPSocket *sock, ecp_ecdh_public_t *public) {
}
#ifdef ECP_WITH_PTHREAD
- pthread_mutex_lock(&sock->conn_table.mutex);
+ pthread_mutex_unlock(&sock->conn_table.mutex);
#endif
#endif /* ECP_WITH_HTABLE */
return conn;
}
+unsigned int ecp_sock_gct_count(ECPSocket *sock) {
+ int i;
+ unsigned int rv;
+
+#ifdef ECP_WITH_HTABLE
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&sock->conn_table.mutex_gc);
+#endif
+
+ rv = ecp_ht_count(sock->conn_table.keys_gc);
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&sock->conn_table.mutex_gc);
+#endif
+#else /* ECP_WITH_HTABLE */
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&sock->conn_table.mutex);
+#endif
+
+ rv = 0;
+ for (i=0; i<sock->conn_table.size; i++) {
+ ECPConnection *conn = sock->conn_table.arr[i];
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&conn->mutex);
+#endif
+
+ if (_ecp_conn_in_gct(conn)) rv++;
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_unlock(&conn->mutex);
+#endif
+ }
+
+#ifdef ECP_WITH_PTHREAD
+ pthread_mutex_lock(&sock->conn_table.mutex);
+#endif
+#endif /* ECP_WITH_HTABLE */
+
+ return rv;
+}
+
void ecp_atag_gen(ECPSocket *sock, unsigned char *public_buf, unsigned char *atag, ecp_nonce_t *nonce) {
unsigned char msg[ECP_SIZE_ECDH_PUB+ECP_SIZE_NONCE];
ecp_hmac_key_t key;
diff --git a/ecp/src/ecp/core.h b/ecp/src/ecp/core.h
index 36c5e42..3ae635a 100644
--- a/ecp/src/ecp/core.h
+++ b/ecp/src/ecp/core.h
@@ -399,7 +399,8 @@ int ecp_sock_dhkey_new(ECPSocket *sock);
int ecp_sock_dhkey_get(ECPSocket *sock, unsigned char idx, ECPDHKey *key);
int ecp_sock_dhkey_get_pub(ECPSocket *sock, unsigned char *idx, ecp_ecdh_public_t *public);
void ecp_sock_expire(ECPSocket *sock, ecp_conn_expired_t conn_expired);
-ECPConnection *ecp_sock_search_gc(ECPSocket *sock, ecp_ecdh_public_t *public);
+ECPConnection *ecp_sock_gct_search(ECPSocket *sock, ecp_ecdh_public_t *public);
+unsigned int ecp_sock_gct_count(ECPSocket *sock);
void ecp_atag_gen(ECPSocket *sock, unsigned char *public_buf, unsigned char *atag, ecp_nonce_t *nonce);
int ecp_cookie_verify(ECPSocket *sock, unsigned char *cookie, unsigned char *public_buf);