dynamically allocate hash table buckets based on init() call
we probably should move to a more tree-like data structure than a hash table. But well, lookup is not the most computationally expensive part compared to the cryptographic operations.
This commit is contained in:
parent
bfe531b549
commit
18a74f3e38
|
@ -31,7 +31,7 @@ struct auc_rec {
|
|||
struct osmo_sub_auth_data auth;
|
||||
};
|
||||
|
||||
int auc_core_init(void *ctx);
|
||||
int auc_core_init(void *ctx, unsigned int nbuckets);
|
||||
int auc_add_rec(struct auc_rec *rec);
|
||||
int auc_gen_vecs(struct osmo_auth_vector *vec,
|
||||
const char *imsi, int n_vecs);
|
||||
|
|
|
@ -21,18 +21,25 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <osmocom/core/linuxlist.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/crypt/auth.h>
|
||||
|
||||
#include "auc.h"
|
||||
|
||||
#define NBUCKETS 1024
|
||||
static struct llist_head auc_buckets[NBUCKETS];
|
||||
static struct llist_head *auc_buckets;
|
||||
static unsigned int g_nbuckets;
|
||||
|
||||
int auc_core_init(void *ctx)
|
||||
int auc_core_init(void *ctx, unsigned int nbuckets)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NBUCKETS; i++)
|
||||
auc_buckets = talloc_array(ctx, struct llist_head, nbuckets);
|
||||
if (!auc_buckets)
|
||||
return -ENOMEM;
|
||||
|
||||
g_nbuckets = nbuckets;
|
||||
|
||||
for (i = 0; i < nbuckets; i++)
|
||||
INIT_LLIST_HEAD(&auc_buckets[i]);
|
||||
|
||||
return 0;
|
||||
|
@ -45,7 +52,7 @@ static unsigned int osmo_auc_hashfn(const char *imsi)
|
|||
|
||||
res = atoi(imsi + len - 6);
|
||||
|
||||
return res % NBUCKETS;
|
||||
return res % g_nbuckets;
|
||||
}
|
||||
|
||||
int auc_add_rec(struct auc_rec *rec)
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/crypt/auth.h>
|
||||
|
||||
#include "auc.h"
|
||||
|
||||
void *tall_ctx;
|
||||
|
||||
static int auc_test(void)
|
||||
|
@ -60,7 +62,7 @@ int main(int argc, char **argv)
|
|||
|
||||
tall_ctx = talloc_zero_size(NULL, 1);
|
||||
|
||||
rc = auc_core_init(tall_ctx);
|
||||
rc = auc_core_init(tall_ctx, 64*1024);
|
||||
if (rc < 0)
|
||||
exit(1);
|
||||
|
||||
|
|
Reference in New Issue