aboutsummaryrefslogtreecommitdiff
path: root/src/dht/dht_api.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-05-04 12:57:06 +0000
committerBart Polot <bart@net.in.tum.de>2012-05-04 12:57:06 +0000
commitc0953e20856f7c29e15ef1d8bfbb308c8fecc6d6 (patch)
tree51c3599f426f88fd117eea2826b0f16e8d8d4811 /src/dht/dht_api.c
parent5cb80076be6f79e7bd58cc9e765bceec372b6e8b (diff)
Added stop operation for dht monitoring
Diffstat (limited to 'src/dht/dht_api.c')
-rw-r--r--src/dht/dht_api.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 37b65b0222..131070302d 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -1275,7 +1275,7 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
void *cb_cls)
{
struct GNUNET_DHT_MonitorHandle *h;
- struct GNUNET_DHT_MonitorStartMessage *m;
+ struct GNUNET_DHT_MonitorStartStopMessage *m;
struct PendingMessage *pending;
h = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorHandle));
@@ -1293,20 +1293,20 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
memcpy (h->key, key, sizeof(GNUNET_HashCode));
}
- pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartMessage) +
+ pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartStopMessage) +
sizeof (struct PendingMessage));
- m = (struct GNUNET_DHT_MonitorStartMessage *) &pending[1];
+ m = (struct GNUNET_DHT_MonitorStartStopMessage *) &pending[1];
pending->msg = &m->header;
pending->handle = handle;
pending->free_on_send = GNUNET_YES;
m->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_START);
- m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartMessage));
+ m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartStopMessage));
m->type = htonl(type);
- m->get = (NULL != get_cb);
- m->get_resp = (NULL != get_resp_cb);
- m->put = (NULL != put_cb);
+ m->get = htons(NULL != get_cb);
+ m->get_resp = htons(NULL != get_resp_cb);
+ m->put = htons(NULL != put_cb);
if (NULL != key) {
- m->filter_key = 1;
+ m->filter_key = htons(1);
memcpy (&m->key, key, sizeof(GNUNET_HashCode));
}
GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
@@ -1328,11 +1328,36 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle,
void
GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle)
{
- GNUNET_free_non_null (handle->key);
+ struct GNUNET_DHT_MonitorStartStopMessage *m;
+ struct PendingMessage *pending;
+
GNUNET_CONTAINER_DLL_remove (handle->dht_handle->monitor_head,
handle->dht_handle->monitor_tail,
handle);
- /* FIXME notify service of stop */
+
+ pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartStopMessage) +
+ sizeof (struct PendingMessage));
+ m = (struct GNUNET_DHT_MonitorStartStopMessage *) &pending[1];
+ pending->msg = &m->header;
+ pending->handle = handle->dht_handle;
+ pending->free_on_send = GNUNET_YES;
+ m->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP);
+ m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartStopMessage));
+ m->type = htonl(handle->type);
+ m->get = htons(NULL != handle->get_cb);
+ m->get_resp = htons(NULL != handle->get_resp_cb);
+ m->put = htons(NULL != handle->put_cb);
+ if (NULL != handle->key) {
+ m->filter_key = htons(1);
+ memcpy (&m->key, handle->key, sizeof(GNUNET_HashCode));
+ }
+ GNUNET_CONTAINER_DLL_insert (handle->dht_handle->pending_head,
+ handle->dht_handle->pending_tail,
+ pending);
+ pending->in_pending_queue = GNUNET_YES;
+ process_pending_messages (handle->dht_handle);
+
+ GNUNET_free_non_null (handle->key);
GNUNET_free (handle);
}