summaryrefslogtreecommitdiff
path: root/ecp
diff options
context:
space:
mode:
Diffstat (limited to 'ecp')
-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);