From: Nathan S. Evans Date: Wed, 17 Mar 2010 17:19:30 +0000 (+0000) Subject: beginning of changes X-Git-Tag: initial-import-from-subversion-38251~22427 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a48e8f508403c9d8641a0c9eb47d88f98cb47f28;p=oweals%2Fgnunet.git beginning of changes --- diff --git a/src/dht/dht.h b/src/dht/dht.h index 5293bf6bd..82b0df9a2 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -32,6 +32,43 @@ typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, struct GNUNET_MessageHeader *msg); +/** + * Generic DHT message, wrapper for other message types + */ +struct GNUNET_DHT_Message +{ + /** + * Type: GNUNET_MESSAGE_TYPE_DHT_MESSAGE + */ + struct GNUNET_MessageHeader header; + + /** + * The key to search for + */ + GNUNET_HashCode key; + + /** + * Replication level for this message + */ + uint16_t desired_replication_level; + + /** + * Message options + */ + uint16_t options; + + /** + * Is this message uniquely identified? If so it has + * a unique_id appended to it. + */ + /* uint16_t unique; I don't think we need this, it should be held in the encapsulated message */ + + /* uint64_t unique_id*/ + /* */ + /* GNUNET_MessageHeader *enc actual DHT message, copied to end of this dealy do */ + +}; + /** * Message to insert data into the DHT */ @@ -47,11 +84,6 @@ struct GNUNET_DHT_PutMessage */ size_t type; - /** - * The key to insert data under. - */ - GNUNET_HashCode key; - /** * The size of the data, appended to the end of this message. */ @@ -60,7 +92,7 @@ struct GNUNET_DHT_PutMessage /** * How long should this data persist? */ - struct GNUNET_TIME_Relative timeout; + struct GNUNET_TIME_Absolute expiration; }; @@ -115,32 +147,44 @@ struct GNUNET_DHT_GetResultMessage }; /** - * Response to PUT request from the DHT + * Message to request data from the DHT */ -struct GNUNET_DHT_PutResultMessage +struct GNUNET_DHT_FindPeerMessage { /** - * Type: GNUNET_MESSAGE_TYPE_DHT_PUT_RESULT + * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER */ struct GNUNET_MessageHeader header; /** - * The type for the data for the GET request + * The key being looked up */ - size_t type; + GNUNET_HashCode key; + +}; +/** + * Message to return data from the DHT + */ +struct GNUNET_DHT_FindPeerResultMessage +{ /** - * The key to search for + * Type: GNUNET_MESSAGE_TYPE_DHT_FIND_PEER_RESULT */ - GNUNET_HashCode key; + struct GNUNET_MessageHeader header; /** - * Was the put successful? GNUNET_YES or GNUNET_NO + * The peer that was searched for */ - size_t result; - -}; + struct GNUNET_PeerIdentity peer; + /** + * The size of the HELLO for the returned peer, + * appended to the end of this message, 0 if + * no hello. + */ + size_t data_size; +}; #endif /* DHT_H_ */ diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index db25379fa..a55508b07 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -135,11 +135,14 @@ void service_message_handler (void *cls, * * @param cfg configuration to use * @param sched scheduler to use + * @param ht_len size of the internal hash table to use for + * processing multiple GET/FIND requests in parallel * @return NULL on error */ struct GNUNET_DHT_Handle * GNUNET_DHT_connect (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg) + const struct GNUNET_CONFIGURATION_Handle *cfg, + unsigned int ht_len) { struct GNUNET_DHT_Handle *handle; @@ -233,6 +236,11 @@ struct GNUNET_DHT_GetHandle * Closure for the iterator callback */ void *iter_cls; + + /** + * Main handle to this DHT api + */ + struct GNUNET_DHT_Handle *dht_handle; }; /** @@ -303,7 +311,6 @@ static size_t transmit_pending (void *cls, size_t size, void *buf) { struct GNUNET_DHT_Handle *handle = cls; - size_t ret; size_t tsize; if (buf == NULL) @@ -318,7 +325,6 @@ transmit_pending (void *cls, size_t size, void *buf) } handle->th = NULL; - ret = 0; if (handle->current != NULL) { @@ -330,14 +336,15 @@ transmit_pending (void *cls, size_t size, void *buf) "`%s': Sending message size %d\n", "DHT API", tsize); #endif memcpy(buf, handle->current->msg, tsize); + return tsize; } else { - return ret; + return 0; } } - - return ret; + /* Have no pending request */ + return 0; } @@ -483,6 +490,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, get_handle->iter = iter; get_handle->iter_cls = iter_cls; +#if DEBUG_DHT_API + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "`%s': Inserting pending get request with key %s\n", "DHT API", GNUNET_h2s(key)); +#endif GNUNET_CONTAINER_multihashmap_put(handle->outstanding_get_requests, key, get_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); get_msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_GetMessage)); @@ -503,9 +514,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, * @param record GET operation to stop. */ void -GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHandle *get_handle) +GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle) { struct GNUNET_DHT_GetMessage *get_msg; + struct GNUNET_DHT_Handle *handle; if (handle->do_destroy == GNUNET_NO) { @@ -517,7 +529,10 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHand add_pending(handle, &get_msg->header); } - +#if DEBUG_DHT_API + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "`%s': Removing pending get request with key %s\n", "DHT API", GNUNET_h2s(&get_handle->key)); +#endif GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(handle->outstanding_get_requests, &get_handle->key, get_handle) == GNUNET_YES); GNUNET_free(get_handle); } @@ -539,14 +554,16 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_Handle *handle, struct GNUNET_DHT_GetHand * * @return GNUNET_YES if put message is queued for transmission */ -int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, - const GNUNET_HashCode * key, - uint32_t type, - uint32_t size, - const char *data, - struct GNUNET_TIME_Relative exp, - GNUNET_SCHEDULER_Task cont, - void *cont_cls) +void +GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, + const GNUNET_HashCode * key, + uint32_t type, + uint32_t size, + const char *data, + struct GNUNET_TIME_Absolute exp, + struct GNUNET_TIME_Relative timeout, + GNUNET_SCHEDULER_Task cont, + void *cont_cls) { struct GNUNET_DHT_PutMessage *put_msg; struct GNUNET_DHT_PutHandle *put_handle; @@ -560,13 +577,18 @@ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, * A put has been previously queued, but not yet sent. * FIXME: change the continuation function and callback or something? */ - return GNUNET_NO; + return; } put_handle = GNUNET_malloc(sizeof(struct GNUNET_DHT_PutHandle)); put_handle->type = type; memcpy(&put_handle->key, key, sizeof(GNUNET_HashCode)); +#if DEBUG_DHT_API + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "`%s': Inserting pending put request with key %s\n", "DHT API", GNUNET_h2s(key)); +#endif + GNUNET_CONTAINER_multihashmap_put(handle->outstanding_put_requests, key, put_handle, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); msize = sizeof(struct GNUNET_DHT_PutMessage) + size; @@ -579,5 +601,5 @@ int GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, add_pending(handle, &put_msg->header); - return GNUNET_YES; + return; } diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 3dcb75353..5bbb2e739 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -167,13 +167,23 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { * Server handler for initiating local dht get requests */ static void handle_dht_get (void *cls, struct GNUNET_SERVER_Client * client, - const struct GNUNET_MessageHeader *message) + const struct GNUNET_MessageHeader *message) { + struct GNUNET_DHT_GetMessage *get_msg = (struct GNUNET_DHT_GetMessage *)message; + GNUNET_HashCode get_key; + size_t get_type; + + GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct GNUNET_DHT_GetMessage)); + memcpy(&get_key, &get_msg->key, sizeof(GNUNET_HashCode)); + get_type = ntohs(get_msg->type); + #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "`%s': Received `%s' request from client\n", "DHT", "GET"); + "`%s': Received `%s' request from client, message type %d, key %s\n", "DHT", "GET", get_type, GNUNET_h2s(&get_key)); #endif + /* FIXME: Implement get stop functionality here */ + } /** @@ -182,25 +192,43 @@ static void handle_dht_get (void *cls, struct GNUNET_SERVER_Client * client, static void handle_dht_get_stop (void *cls, struct GNUNET_SERVER_Client * client, const struct GNUNET_MessageHeader *message) { + struct GNUNET_DHT_GetMessage *get_msg = (struct GNUNET_DHT_GetMessage *)message; /* Get message and get stop message are the same except for type */ + GNUNET_HashCode get_key; + size_t get_type; + + GNUNET_assert(ntohs(get_msg->header.size) >= sizeof(struct GNUNET_DHT_GetMessage)); + + memcpy(&get_key, &get_msg->key, sizeof(GNUNET_HashCode)); + get_type = ntohs(get_msg->type); + #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "`%s': Received `%s' request from client\n", "DHT", "GET STOP"); + "`%s': Received `%s' request from client, message type %d, key %s\n", "DHT", "GET STOP", get_type, GNUNET_h2s(&get_key)); #endif + /* FIXME: Implement get stop functionality here */ + } /** * Server handler for initiating local dht find peer requests */ static void handle_dht_find_peer (void *cls, struct GNUNET_SERVER_Client * - client, const struct GNUNET_MessageHeader * - message) + client, const struct GNUNET_MessageHeader * + message) { + struct GNUNET_DHT_FindPeerMessage *find_msg = (struct GNUNET_DHT_FindPeerMessage *)message; + struct GNUNET_PeerIdentity peer; + + GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct GNUNET_DHT_FindPeerMessage)); + memcpy(&peer, &find_msg->peer, sizeof(struct GNUNET_PeerIdentity)); + #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "`%s': Received `%s' request from client\n", "DHT", "FIND PEER"); + "`%s': Received `%s' request from client, peer id %s\n", "DHT", "FIND PEER", GNUNET_i2s(&peer)); #endif + /* FIXME: Implement find peer functionality here */ } /** @@ -210,11 +238,19 @@ static void handle_dht_find_peer_stop (void *cls, struct GNUNET_SERVER_Client * client, const struct GNUNET_MessageHeader * message) { + struct GNUNET_DHT_FindPeerMessage *find_msg = (struct GNUNET_DHT_FindPeerMessage *)message; /* Find peer stop message is identical to find peer message */ + struct GNUNET_PeerIdentity peer; + + GNUNET_assert(ntohs(find_msg->header.size) == sizeof(struct GNUNET_DHT_FindPeerMessage)); + memcpy(&peer, &find_msg->peer, sizeof(struct GNUNET_PeerIdentity)); + #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "`%s': Received `%s' request from client\n", "DHT", "FIND PEER STOP"); + "`%s': Received `%s' request from client, for peer id %s\n", "DHT", "FIND PEER STOP", GNUNET_i2s(&peer)); #endif + /* FIXME: Implement find peer stop functionality here */ + } /** @@ -223,21 +259,42 @@ static void handle_dht_find_peer_stop (void *cls, struct GNUNET_SERVER_Client * static void handle_dht_put (void *cls, struct GNUNET_SERVER_Client * client, const struct GNUNET_MessageHeader *message) { + struct GNUNET_DHT_PutMessage *put_msg = (struct GNUNET_DHT_PutMessage *)message; + GNUNET_HashCode put_key; + size_t put_type; + size_t data_size; + char *data; + + GNUNET_assert(ntohs(put_msg->header.size) >= sizeof(struct GNUNET_DHT_PutMessage)); + + memcpy(&put_key, &put_msg->key, sizeof(GNUNET_HashCode)); + put_type = ntohs(put_msg->type); + data_size = ntohs(put_msg->data_size); + GNUNET_assert(ntohs(put_msg->header.size) == sizeof(struct GNUNET_DHT_PutMessage) + data_size); + data = GNUNET_malloc(data_size); + memcpy(data, &put_msg[1], data_size); + #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "`%s': Received `%s' request from client\n", "DHT", "PUT"); + "`%s': Received `%s' request from client, message type %d, key %s\n", "DHT", "PUT", put_type, GNUNET_h2s(&put_key)); #endif + /** + * FIXME: Implement dht put request functionality here! + */ + + GNUNET_free(data); + } /** * Core handler for p2p dht get requests. */ static int handle_dht_p2p_get (void *cls, - const struct GNUNET_PeerIdentity * peer, - const struct GNUNET_MessageHeader * message, - struct GNUNET_TIME_Relative latency, - uint32_t distance) + const struct GNUNET_PeerIdentity * peer, + const struct GNUNET_MessageHeader * message, + struct GNUNET_TIME_Relative latency, + uint32_t distance) { #if DEBUG_DHT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -340,23 +397,22 @@ run (void *cls, GNUNET_SERVER_add_handlers (server, plugin_handlers); coreAPI = - GNUNET_CORE_connect (sched, - cfg, - client_transmit_timeout, + GNUNET_CORE_connect (sched, /* Main scheduler */ + cfg, /* Main configuration */ + client_transmit_timeout, /* Delay for connecting */ NULL, /* FIXME: anything we want to pass around? */ - &core_init, + &core_init, /* Call core_init once connected */ NULL, /* Don't care about pre-connects */ NULL, /* Don't care about connects */ NULL, /* Don't care about disconnects */ - NULL, - GNUNET_NO, - NULL, - GNUNET_NO, - core_handlers); + NULL, /* Don't want notified about all incoming messages */ + GNUNET_NO, /* For header only inbound notification */ + NULL, /* Don't want notified about all outbound messages */ + GNUNET_NO, /* For header only outbound notification */ + core_handlers); /* Register these handlers */ if (coreAPI == NULL) return; - /* load (server); Huh? */ /* Scheduled the task to clean up when shutdown is called */ cleanup_task = GNUNET_SCHEDULER_add_delayed (sched, diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 9c9fcb4d0..8092d7b2e 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -51,6 +51,9 @@ struct PeerContext struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_DHT_Handle *dht_handle; struct GNUNET_PeerIdentity id; + struct GNUNET_DHT_GetHandle *get_handle; + struct GNUNET_DHT_GetHandle *find_peer_handle; + #if START_ARM pid_t arm_pid; #endif @@ -110,6 +113,54 @@ end_badly () return; } + +/** + * Signature of the main function of a task. + * + * @param cls closure + * @param tc context information (why was this task triggered now) + */ +void test_put (void *cls, + const struct GNUNET_SCHEDULER_TaskContext * tc) +{ + struct PeerContext *peer = cls; + GNUNET_HashCode hash; + char *data; + size_t data_size = 42; + memset(&hash, 42, sizeof(GNUNET_HashCode)); + data = GNUNET_malloc(data_size); + memset(data, 43, data_size); + + GNUNET_assert (peer->dht_handle != NULL); + + GNUNET_DHT_put(peer->dht_handle, &hash, 0, data_size, data, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 360), NULL, NULL); + + //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); + + GNUNET_SCHEDULER_add_now(sched, &end, NULL); +} + +/** + * Signature of the main function of a task. + * + * @param cls closure + * @param tc context information (why was this task triggered now) + */ +void test_get_stop (void *cls, + const struct GNUNET_SCHEDULER_TaskContext * tc) +{ + struct PeerContext *peer = cls; + GNUNET_HashCode hash; + memset(&hash, 42, sizeof(GNUNET_HashCode)); + + GNUNET_assert (peer->dht_handle != NULL); + + GNUNET_DHT_get_stop(peer->dht_handle, peer->get_handle); + + GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_put, &p1); + +} + /** * Signature of the main function of a task. * @@ -126,9 +177,12 @@ void test_get (void *cls, peer->dht_handle = GNUNET_DHT_connect (sched, peer->cfg); GNUNET_assert (peer->dht_handle != NULL); - GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL); + peer->get_handle = GNUNET_DHT_get_start(peer->dht_handle, 42, &hash, NULL, NULL); + + if (peer->get_handle == NULL) + GNUNET_SCHEDULER_add_now(sched, &end_badly, &p1); - GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), &end, &p1); + GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get_stop, &p1); } static void @@ -162,7 +216,7 @@ run (void *cls, setup_peer (&p1, "test_dht_api_peer1.conf"); - GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &test_get, &p1); + GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &test_get, &p1); } static int diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf index 5eb4079f4..1c5dced26 100644 --- a/src/dht/test_dht_api_peer1.conf +++ b/src/dht/test_dht_api_peer1.conf @@ -31,8 +31,9 @@ ALLOW_SHUTDOWN = YES ACCEPT_FROM6 = ::1; ACCEPT_FROM = 127.0.0.1; BINARY = gnunet-service-dht -#BINARY = /root/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht +#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht #PREFIX = xterm -T dvservice -e gdb --args +OPTIONS="" CONFIG = $DEFAULTCONFIG HOME = $SERVICEHOME HOSTNAME = localhost