aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-08-22 12:11:21 -0700
committerGarrett D'Amore <garrett@damore.org>2017-08-22 12:11:21 -0700
commit9b6ac0a1ea92b1ec99acdd021087f6d8fdc75f14 (patch)
tree7cac47944d1772997fd4d458b5bf6c311edd572c /src/core
parent6b66debe7532bd7c3b0c88da7332315d90a84d43 (diff)
downloadnng-9b6ac0a1ea92b1ec99acdd021087f6d8fdc75f14.tar.gz
nng-9b6ac0a1ea92b1ec99acdd021087f6d8fdc75f14.tar.bz2
nng-9b6ac0a1ea92b1ec99acdd021087f6d8fdc75f14.zip
Add support for 64-bit ids in idhash.
We intend to use this with transports where dynamic "port numbers" might be 32-bits. This would allow us to formulate a 64-bit number representing a conversation, and be able to find that conversation by the 64-bit value. Note that the hashed values are probably not perfectly optimal, as only the low order bits are particularly significant in the hash. We might want to consider XOR'ing in the upper bits to address that.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/endpt.c4
-rw-r--r--src/core/idhash.c34
-rw-r--r--src/core/idhash.h11
-rw-r--r--src/core/pipe.c4
-rw-r--r--src/core/socket.c4
5 files changed, 29 insertions, 28 deletions
diff --git a/src/core/endpt.c b/src/core/endpt.c
index f90bd068..5b56b784 100644
--- a/src/core/endpt.c
+++ b/src/core/endpt.c
@@ -18,7 +18,7 @@ struct nni_ep {
nni_tran_ep ep_ops; // transport ops
nni_tran * ep_tran; // transport pointer
void * ep_data; // transport private
- uint32_t ep_id; // endpoint id
+ uint64_t ep_id; // endpoint id
nni_list_node ep_node; // per socket list
nni_sock * ep_sock;
char ep_addr[NNG_MAXADDRLEN];
@@ -78,7 +78,7 @@ nni_ep_sys_fini(void)
uint32_t
nni_ep_id(nni_ep *ep)
{
- return (ep->ep_id);
+ return ((uint32_t) ep->ep_id);
}
static void
diff --git a/src/core/idhash.c b/src/core/idhash.c
index 03854fc8..08352ea3 100644
--- a/src/core/idhash.c
+++ b/src/core/idhash.c
@@ -13,9 +13,9 @@
#include <string.h>
struct nni_idhash_entry {
- uint32_t ihe_key;
- uint32_t ihe_skips;
+ uint64_t ihe_key;
void * ihe_val;
+ uint32_t ihe_skips;
};
struct nni_idhash {
@@ -25,9 +25,9 @@ struct nni_idhash {
size_t ih_minload; // considers placeholders
size_t ih_maxload;
uint32_t ih_walkers;
- uint32_t ih_minval;
- uint32_t ih_maxval;
- uint32_t ih_dynval;
+ uint64_t ih_minval;
+ uint64_t ih_maxval;
+ uint64_t ih_dynval;
nni_idhash_entry *ih_entries;
nni_mtx ih_mtx;
};
@@ -73,7 +73,7 @@ nni_idhash_fini(nni_idhash *h)
void
nni_idhash_set_limits(
- nni_idhash *h, uint32_t minval, uint32_t maxval, uint32_t start)
+ nni_idhash *h, uint64_t minval, uint64_t maxval, uint64_t start)
{
if (start < minval) {
start = minval;
@@ -97,7 +97,7 @@ nni_idhash_set_limits(
#define NNI_IDHASH_NEXTPROBE(h, j) ((((j) *5) + 1) & (h->ih_cap - 1))
static int
-nni_hash_find(nni_idhash *h, uint32_t id, void **valp)
+nni_hash_find(nni_idhash *h, uint64_t id, void **valp)
{
uint32_t index = id & (h->ih_cap - 1);
@@ -119,7 +119,7 @@ nni_hash_find(nni_idhash *h, uint32_t id, void **valp)
}
int
-nni_idhash_find(nni_idhash *h, uint32_t id, void **valp)
+nni_idhash_find(nni_idhash *h, uint64_t id, void **valp)
{
int rv;
@@ -195,11 +195,11 @@ nni_hash_resize(nni_idhash *h)
}
int
-nni_idhash_remove(nni_idhash *h, uint32_t id)
+nni_idhash_remove(nni_idhash *h, uint64_t id)
{
- int rv;
- void * val;
- uint32_t index;
+ int rv;
+ void * val;
+ size_t index;
nni_mtx_lock(&h->ih_mtx);
// First check that it is in the table. This may double the
@@ -240,9 +240,9 @@ nni_idhash_remove(nni_idhash *h, uint32_t id)
}
static int
-nni_hash_insert(nni_idhash *h, uint32_t id, void *val)
+nni_hash_insert(nni_idhash *h, uint64_t id, void *val)
{
- uint32_t index;
+ size_t index;
if ((id < h->ih_minval) || (id > h->ih_maxval)) {
return (NNG_EINVAL);
@@ -280,7 +280,7 @@ nni_hash_insert(nni_idhash *h, uint32_t id, void *val)
}
int
-nni_idhash_insert(nni_idhash *h, uint32_t id, void *val)
+nni_idhash_insert(nni_idhash *h, uint64_t id, void *val)
{
int rv;
@@ -291,9 +291,9 @@ nni_idhash_insert(nni_idhash *h, uint32_t id, void *val)
}
int
-nni_idhash_alloc(nni_idhash *h, uint32_t *idp, void *val)
+nni_idhash_alloc(nni_idhash *h, uint64_t *idp, void *val)
{
- uint32_t id;
+ uint64_t id;
void * scrap;
int rv;
nni_mtx_lock(&h->ih_mtx);
diff --git a/src/core/idhash.h b/src/core/idhash.h
index b21a681b..c2cecf81 100644
--- a/src/core/idhash.h
+++ b/src/core/idhash.h
@@ -28,13 +28,14 @@ typedef struct nni_idhash_entry nni_idhash_entry;
extern int nni_idhash_init(nni_idhash **);
extern void nni_idhash_fini(nni_idhash *);
-extern void nni_idhash_set_limits(nni_idhash *, uint32_t, uint32_t, uint32_t);
+extern void nni_idhash_set_limits(nni_idhash *, uint64_t, uint64_t, uint64_t);
extern int nni_idhash_create(nni_idhash **);
extern void nni_idhash_destroy(nni_idhash *);
-extern int nni_idhash_find(nni_idhash *, uint32_t, void **);
-extern int nni_idhash_remove(nni_idhash *, uint32_t);
-extern int nni_idhash_insert(nni_idhash *, uint32_t, void *);
-extern int nni_idhash_alloc(nni_idhash *, uint32_t *, void *);
+extern int nni_idhash_find(nni_idhash *, uint64_t, void **);
+extern int nni_idhash_remove(nni_idhash *, uint64_t);
+extern int nni_idhash_insert(nni_idhash *, uint64_t, void *);
+extern int nni_idhash_alloc(nni_idhash *, uint64_t *, void *);
+
extern size_t nni_idhash_count(nni_idhash *);
#endif // CORE_IDHASH_H
diff --git a/src/core/pipe.c b/src/core/pipe.c
index 94524da4..0c024c66 100644
--- a/src/core/pipe.c
+++ b/src/core/pipe.c
@@ -16,7 +16,7 @@
// performed in the context of the protocol.
struct nni_pipe {
- uint32_t p_id;
+ uint64_t p_id;
nni_tran_pipe p_tran_ops;
void * p_tran_data;
void * p_proto_data;
@@ -135,7 +135,7 @@ nni_pipe_destroy(nni_pipe *p)
uint32_t
nni_pipe_id(nni_pipe *p)
{
- return (p->p_id);
+ return ((uint32_t) p->p_id);
}
void
diff --git a/src/core/socket.c b/src/core/socket.c
index 79c1602b..765a6d0c 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -31,7 +31,7 @@ struct nni_socket {
nni_cv s_cv;
nni_cv s_close_cv;
- uint32_t s_id;
+ uint64_t s_id;
uint32_t s_flags;
unsigned s_refcnt; // protected by global lock
void * s_data; // Protocol private
@@ -81,7 +81,7 @@ nni_free_opt(nni_sockopt *opt)
uint32_t
nni_sock_id(nni_sock *s)
{
- return (s->s_id);
+ return ((uint32_t) s->s_id);
}
// nni_sock_sendq and nni_sock_recvq are called by the protocol to obtain