d->recv_buffer_length = 0;
d->transactionid_next = 0;
d->transactions_hash = NULL;
+ d->rt_ipv4 = NULL;
+ d->rt_ipv6 = NULL;
return KS_STATUS_SUCCESS;
}
dht->recv_buffer_length = 0;
dht->transactionid_next = 0;
dht->transactions_hash = NULL;
+ dht->rt_ipv4 = NULL;
+ dht->rt_ipv6 = NULL;
return KS_STATUS_SUCCESS;
}
dht->transactionid_next = 1; //rand();
ks_hash_create(&dht->transactions_hash, KS_HASH_MODE_INT, KS_HASH_FLAG_RWLOCK, dht->pool);
+
+ dht->rt_ipv4 = NULL;
+ dht->rt_ipv6 = NULL;
return KS_STATUS_SUCCESS;
}
{
ks_assert(dht);
+ if (dht->rt_ipv4) {
+ ks_dhtrt_deinitroute(dht->rt_ipv4);
+ dht->rt_ipv4 = NULL;
+ }
+ if (dht->rt_ipv6) {
+ ks_dhtrt_deinitroute(dht->rt_ipv6);
+ dht->rt_ipv6 = NULL;
+ }
dht->transactionid_next = 0;
if (dht->transactions_hash) {
ks_hash_destroy(&dht->transactions_hash);
dht->endpoints_poll[epindex].fd = ep->sock;
dht->endpoints_poll[epindex].events = POLLIN | POLLERR;
+ // @todo initialize or add local nodeid to appropriate route table
+ if (ep->addr.family == AF_INET) {
+ if (!dht->rt_ipv4) {
+ //ks_dhtrt_initroute(&dht->rt_ipv4, dht->pool, (ks_dhtrt_nodeid_t));
+ }
+ } else {
+ if (!dht->rt_ipv6) {
+ //ks_dhtrt_initroute(&dht->rt_ipv6, dht->pool);
+ }
+ }
+
if (endpoint) {
*endpoint = ep;
}
return KS_STATUS_FAIL;
}
- ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid, KS_DHT_NODEID_SIZE));
+ ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid.id, KS_DHT_NODEID_SIZE));
ks_log(KS_LOG_DEBUG, "Sending message query ping\n");
ks_q_push(dht->send_q, (void *)message);
return KS_STATUS_FAIL;
}
- ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid, KS_DHT_NODEID_SIZE));
- ben_dict_set(a, ben_blob("target", 6), ben_blob(targetid, KS_DHT_NODEID_SIZE));
+ ben_dict_set(a, ben_blob("id", 2), ben_blob(ep->nodeid.id, KS_DHT_NODEID_SIZE));
+ ben_dict_set(a, ben_blob("target", 6), ben_blob(targetid->id, KS_DHT_NODEID_SIZE));
ks_log(KS_LOG_DEBUG, "Sending message query find_node\n");
ks_q_push(dht->send_q, (void *)message);
// goto done;
//}
- ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid, KS_DHT_NODEID_SIZE));
+ ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid.id, KS_DHT_NODEID_SIZE));
ks_log(KS_LOG_DEBUG, "Sending message response ping\n");
ks_q_push(dht->send_q, (void *)response);
// goto done;
//}
- ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid, KS_DHT_NODEID_SIZE));
+ ben_dict_set(r, ben_blob("id", 2), ben_blob(message->endpoint->nodeid.id, KS_DHT_NODEID_SIZE));
// @todo populate nodes/nodes6
ben_dict_set(r, ben_blob("nodes", 5), ben_blob(buffer, buffer_length));
#include "ks.h"
#include "ks_bencode.h"
-
+#include "ks_dht_bucket.h"
KS_BEGIN_EXTERN_C
#define KS_DHT_TRANSACTION_EXPIRATION_DELAY 30
typedef struct ks_dht_s ks_dht_t;
-typedef uint8_t ks_dht_nodeid_t[KS_DHT_NODEID_SIZE];
+typedef struct ks_dht_nodeid_s ks_dht_nodeid_t;
typedef struct ks_dht_message_s ks_dht_message_t;
typedef struct ks_dht_endpoint_s ks_dht_endpoint_t;
typedef struct ks_dht_transaction_s ks_dht_transaction_t;
typedef ks_status_t (*ks_dht_message_callback_t)(ks_dht_t *dht, ks_dht_message_t *message);
+/**
+ * Note: This must remain a structure for casting from raw data
+ */
+struct ks_dht_nodeid_s {
+ uint8_t id[KS_DHT_NODEID_SIZE];
+};
struct ks_dht_message_s {
ks_pool_t *pool;
uint8_t recv_buffer[KS_DHT_RECV_BUFFER_SIZE];
ks_size_t recv_buffer_length;
- uint32_t transactionid_next;
+ volatile uint32_t transactionid_next;
ks_hash_t *transactions_hash;
+
+ ks_dhtrt_routetable *rt_ipv4;
+ ks_dhtrt_routetable *rt_ipv6;
};
/**
*
*/
KS_DECLARE(ks_status_t) ks_dht_transaction_alloc(ks_dht_transaction_t **transaction, ks_pool_t *pool);
-KS_DECLARE(ks_status_t) ks_dht_transaction_prealloc(ks_dht_transaction_t *trasnaction, ks_pool_t *pool);
+KS_DECLARE(ks_status_t) ks_dht_transaction_prealloc(ks_dht_transaction_t *transaction, ks_pool_t *pool);
KS_DECLARE(ks_status_t) ks_dht_transaction_free(ks_dht_transaction_t *transaction);
KS_DECLARE(ks_status_t) ks_dht_transaction_init(ks_dht_transaction_t *transaction,