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
*/
*/
size_t type;
- /**
- * The key to insert data under.
- */
- GNUNET_HashCode key;
-
/**
* The size of the data, appended to the end of this message.
*/
/**
* How long should this data persist?
*/
- struct GNUNET_TIME_Relative timeout;
+ struct GNUNET_TIME_Absolute expiration;
};
};
/**
- * 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_ */
*
* @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;
* Closure for the iterator callback
*/
void *iter_cls;
+
+ /**
+ * Main handle to this DHT api
+ */
+ struct GNUNET_DHT_Handle *dht_handle;
};
/**
transmit_pending (void *cls, size_t size, void *buf)
{
struct GNUNET_DHT_Handle *handle = cls;
- size_t ret;
size_t tsize;
if (buf == NULL)
}
handle->th = NULL;
- ret = 0;
if (handle->current != NULL)
{
"`%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;
}
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));
* @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)
{
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);
}
*
* @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;
* 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;
add_pending(handle, &put_msg->header);
- return GNUNET_YES;
+ return;
}
* 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 */
+
}
/**
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 */
}
/**
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 */
+
}
/**
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,
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,
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
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.
*
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
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
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