summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-04-23 18:13:49 +0200
committerUros Majstorovic <majstor@majstor.org>2024-04-23 18:13:49 +0200
commitd0643c4015d6a61b0adb90cf8c48f6664e9f8019 (patch)
treedea742536939a09b318ee99ded29366e087fcfcc
parent503ac614ea91b4fdd9d5f6f467a2efcad900a7e1 (diff)
added uniqueness to connection keys
-rw-r--r--ecp/src/ecp/core.c8
-rw-r--r--ecp/src/ecp/ht.h1
-rw-r--r--ecp/src/ecp/htable/htable.c11
3 files changed, 16 insertions, 4 deletions
diff --git a/ecp/src/ecp/core.c b/ecp/src/ecp/core.c
index 1e24d0b..77017df 100644
--- a/ecp/src/ecp/core.c
+++ b/ecp/src/ecp/core.c
@@ -190,7 +190,7 @@ static int conn_table_insert(ECPConnection *conn) {
for (i=0; i<ECP_MAX_CONN_KEY; i++) {
if (conn->key[i].valid) {
- rv = ecp_ht_insert(sock->conn_table.keys, &conn->key[i].public, conn);
+ rv = ecp_ht_insert_uniq(sock->conn_table.keys, &conn->key[i].public, conn);
if (rv) {
int j;
@@ -209,7 +209,7 @@ static int conn_table_insert(ECPConnection *conn) {
} else {
for (i=0; i<ECP_MAX_NODE_KEY; i++) {
if (conn->rkey[i].valid) {
- rv = ecp_ht_insert(sock->conn_table.keys, &conn->rkey[i].public, conn);
+ rv = ecp_ht_insert_uniq(sock->conn_table.keys, &conn->rkey[i].public, conn);
if (rv) {
int j;
@@ -726,7 +726,7 @@ static int conn_dhkey_new(ECPConnection *conn, unsigned char idx, ECPDHKey *key)
if (ecp_conn_is_outb(conn) && _ecp_conn_is_reg(conn)) {
int rv;
- rv = ecp_ht_insert(sock->conn_table.keys, &conn->key[idx].public, conn);
+ rv = ecp_ht_insert_uniq(sock->conn_table.keys, &conn->key[idx].public, conn);
if (rv) return rv;
}
#endif
@@ -824,7 +824,7 @@ static int conn_dhkey_set_pub(ECPConnection *conn, unsigned char idx, ecp_ecdh_p
if (ecp_conn_is_inb(conn) && _ecp_conn_is_reg(conn)) {
int rv;
- rv = ecp_ht_insert(sock->conn_table.keys, &key->public, conn);
+ rv = ecp_ht_insert_uniq(sock->conn_table.keys, &key->public, conn);
if (rv) return rv;
}
#endif
diff --git a/ecp/src/ecp/ht.h b/ecp/src/ecp/ht.h
index 805fbda..9b0ac30 100644
--- a/ecp/src/ecp/ht.h
+++ b/ecp/src/ecp/ht.h
@@ -3,6 +3,7 @@ ecp_ht_table_t *ecp_ht_create_addrs(void);
void ecp_ht_destroy(ecp_ht_table_t *h);
int ecp_ht_insert(ecp_ht_table_t *h, void *k, void *v);
+int ecp_ht_insert_uniq(ecp_ht_table_t *h, void *k, void *v);
void *ecp_ht_remove(ecp_ht_table_t *h, void *k);
void *ecp_ht_remove_kv(ecp_ht_table_t *h, void *k, void *v);
void *ecp_ht_search(ecp_ht_table_t *h, void *k);
diff --git a/ecp/src/ecp/htable/htable.c b/ecp/src/ecp/htable/htable.c
index c22d2ab..85a9339 100644
--- a/ecp/src/ecp/htable/htable.c
+++ b/ecp/src/ecp/htable/htable.c
@@ -25,6 +25,17 @@ int ecp_ht_insert(ecp_ht_table_t *h, void *k, void *v) {
return ECP_OK;
}
+int ecp_ht_insert_uniq(ecp_ht_table_t *h, void *k, void *v) {
+ int rv;
+ void *p;
+
+ p = hashtable_search(h, k);
+ if (p) return ECP_ERR_DUP;
+ rv = hashtable_insert(h, k, v);
+ if (rv == 0) return ECP_ERR;
+ return ECP_OK;
+}
+
void *ecp_ht_remove(ecp_ht_table_t *h, void *k) {
return hashtable_remove(h, k);
}