diff options
author | Bart Polot <bart@net.in.tum.de> | 2012-05-04 12:57:06 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2012-05-04 12:57:06 +0000 |
commit | c0953e20856f7c29e15ef1d8bfbb308c8fecc6d6 (patch) | |
tree | 51c3599f426f88fd117eea2826b0f16e8d8d4811 /src/dht | |
parent | 5cb80076be6f79e7bd58cc9e765bceec372b6e8b (diff) | |
download | gnunet-c0953e20856f7c29e15ef1d8bfbb308c8fecc6d6.tar.gz gnunet-c0953e20856f7c29e15ef1d8bfbb308c8fecc6d6.zip |
Added stop operation for dht monitoring
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/dht.h | 4 | ||||
-rw-r--r-- | src/dht/dht_api.c | 45 | ||||
-rw-r--r-- | src/dht/gnunet-service-dht_clients.c | 74 |
3 files changed, 97 insertions, 26 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h index 07cd18296..8adf49f5c 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h | |||
@@ -280,10 +280,10 @@ struct GNUNET_DHT_MonitorPutMessage | |||
280 | /** | 280 | /** |
281 | * Message to request monitoring messages, clients -> DHT service. | 281 | * Message to request monitoring messages, clients -> DHT service. |
282 | */ | 282 | */ |
283 | struct GNUNET_DHT_MonitorStartMessage | 283 | struct GNUNET_DHT_MonitorStartStopMessage |
284 | { | 284 | { |
285 | /** | 285 | /** |
286 | * Type: GNUNET_MESSAGE_TYPE_DHT_MONITOR_START | 286 | * Type: GNUNET_MESSAGE_TYPE_DHT_MONITOR_(START|STOP) |
287 | */ | 287 | */ |
288 | struct GNUNET_MessageHeader header; | 288 | struct GNUNET_MessageHeader header; |
289 | 289 | ||
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 37b65b022..131070302 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, | |||
1275 | void *cb_cls) | 1275 | void *cb_cls) |
1276 | { | 1276 | { |
1277 | struct GNUNET_DHT_MonitorHandle *h; | 1277 | struct GNUNET_DHT_MonitorHandle *h; |
1278 | struct GNUNET_DHT_MonitorStartMessage *m; | 1278 | struct GNUNET_DHT_MonitorStartStopMessage *m; |
1279 | struct PendingMessage *pending; | 1279 | struct PendingMessage *pending; |
1280 | 1280 | ||
1281 | h = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorHandle)); | 1281 | h = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorHandle)); |
@@ -1293,20 +1293,20 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, | |||
1293 | memcpy (h->key, key, sizeof(GNUNET_HashCode)); | 1293 | memcpy (h->key, key, sizeof(GNUNET_HashCode)); |
1294 | } | 1294 | } |
1295 | 1295 | ||
1296 | pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartMessage) + | 1296 | pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartStopMessage) + |
1297 | sizeof (struct PendingMessage)); | 1297 | sizeof (struct PendingMessage)); |
1298 | m = (struct GNUNET_DHT_MonitorStartMessage *) &pending[1]; | 1298 | m = (struct GNUNET_DHT_MonitorStartStopMessage *) &pending[1]; |
1299 | pending->msg = &m->header; | 1299 | pending->msg = &m->header; |
1300 | pending->handle = handle; | 1300 | pending->handle = handle; |
1301 | pending->free_on_send = GNUNET_YES; | 1301 | pending->free_on_send = GNUNET_YES; |
1302 | m->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_START); | 1302 | m->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_START); |
1303 | m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartMessage)); | 1303 | m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartStopMessage)); |
1304 | m->type = htonl(type); | 1304 | m->type = htonl(type); |
1305 | m->get = (NULL != get_cb); | 1305 | m->get = htons(NULL != get_cb); |
1306 | m->get_resp = (NULL != get_resp_cb); | 1306 | m->get_resp = htons(NULL != get_resp_cb); |
1307 | m->put = (NULL != put_cb); | 1307 | m->put = htons(NULL != put_cb); |
1308 | if (NULL != key) { | 1308 | if (NULL != key) { |
1309 | m->filter_key = 1; | 1309 | m->filter_key = htons(1); |
1310 | memcpy (&m->key, key, sizeof(GNUNET_HashCode)); | 1310 | memcpy (&m->key, key, sizeof(GNUNET_HashCode)); |
1311 | } | 1311 | } |
1312 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, | 1312 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, |
@@ -1328,11 +1328,36 @@ GNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, | |||
1328 | void | 1328 | void |
1329 | GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle) | 1329 | GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle) |
1330 | { | 1330 | { |
1331 | GNUNET_free_non_null (handle->key); | 1331 | struct GNUNET_DHT_MonitorStartStopMessage *m; |
1332 | struct PendingMessage *pending; | ||
1333 | |||
1332 | GNUNET_CONTAINER_DLL_remove (handle->dht_handle->monitor_head, | 1334 | GNUNET_CONTAINER_DLL_remove (handle->dht_handle->monitor_head, |
1333 | handle->dht_handle->monitor_tail, | 1335 | handle->dht_handle->monitor_tail, |
1334 | handle); | 1336 | handle); |
1335 | /* FIXME notify service of stop */ | 1337 | |
1338 | pending = GNUNET_malloc (sizeof (struct GNUNET_DHT_MonitorStartStopMessage) + | ||
1339 | sizeof (struct PendingMessage)); | ||
1340 | m = (struct GNUNET_DHT_MonitorStartStopMessage *) &pending[1]; | ||
1341 | pending->msg = &m->header; | ||
1342 | pending->handle = handle->dht_handle; | ||
1343 | pending->free_on_send = GNUNET_YES; | ||
1344 | m->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP); | ||
1345 | m->header.size = htons (sizeof (struct GNUNET_DHT_MonitorStartStopMessage)); | ||
1346 | m->type = htonl(handle->type); | ||
1347 | m->get = htons(NULL != handle->get_cb); | ||
1348 | m->get_resp = htons(NULL != handle->get_resp_cb); | ||
1349 | m->put = htons(NULL != handle->put_cb); | ||
1350 | if (NULL != handle->key) { | ||
1351 | m->filter_key = htons(1); | ||
1352 | memcpy (&m->key, handle->key, sizeof(GNUNET_HashCode)); | ||
1353 | } | ||
1354 | GNUNET_CONTAINER_DLL_insert (handle->dht_handle->pending_head, | ||
1355 | handle->dht_handle->pending_tail, | ||
1356 | pending); | ||
1357 | pending->in_pending_queue = GNUNET_YES; | ||
1358 | process_pending_messages (handle->dht_handle); | ||
1359 | |||
1360 | GNUNET_free_non_null (handle->key); | ||
1336 | GNUNET_free (handle); | 1361 | GNUNET_free (handle); |
1337 | } | 1362 | } |
1338 | 1363 | ||
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c index 9eb1ef497..a75642aa1 100644 --- a/src/dht/gnunet-service-dht_clients.c +++ b/src/dht/gnunet-service-dht_clients.c | |||
@@ -692,7 +692,7 @@ handle_dht_local_get_stop (void *cls, struct GNUNET_SERVER_Client *client, | |||
692 | 692 | ||
693 | 693 | ||
694 | /** | 694 | /** |
695 | * Handler for monitor messages | 695 | * Handler for monitor start messages |
696 | * | 696 | * |
697 | * @param cls closure for the service | 697 | * @param cls closure for the service |
698 | * @param client the client we received this message from | 698 | * @param client the client we received this message from |
@@ -704,29 +704,72 @@ handle_dht_local_monitor (void *cls, struct GNUNET_SERVER_Client *client, | |||
704 | const struct GNUNET_MessageHeader *message) | 704 | const struct GNUNET_MessageHeader *message) |
705 | { | 705 | { |
706 | struct ClientMonitorRecord *r; | 706 | struct ClientMonitorRecord *r; |
707 | const struct GNUNET_DHT_MonitorStartMessage *msg; | 707 | const struct GNUNET_DHT_MonitorStartStopMessage *msg; |
708 | unsigned int i; | ||
709 | char *c; | ||
710 | 708 | ||
711 | msg = (struct GNUNET_DHT_MonitorStartMessage *) message; | 709 | msg = (struct GNUNET_DHT_MonitorStartStopMessage *) message; |
712 | r = GNUNET_malloc (sizeof(struct ClientMonitorRecord)); | 710 | r = GNUNET_malloc (sizeof(struct ClientMonitorRecord)); |
713 | 711 | ||
714 | r->client = find_active_client(client); | 712 | r->client = find_active_client(client); |
715 | r->type = ntohl(msg->type); | 713 | r->type = ntohl(msg->type); |
716 | r->get = msg->get; | 714 | r->get = ntohs(msg->get); |
717 | r->get_resp = msg->get_resp; | 715 | r->get_resp = ntohs(msg->get_resp); |
718 | r->put = msg->put; | 716 | r->put = ntohs(msg->put); |
719 | c = (char *) &msg->key; | 717 | if (0 == ntohs(msg->filter_key)) |
720 | for (i = 0; i < sizeof (GNUNET_HashCode) && c[i] == 0; i++); | 718 | r->key = NULL; |
721 | if (sizeof (GNUNET_HashCode) == i) | ||
722 | r->key = NULL; | ||
723 | else | 719 | else |
724 | { | 720 | { |
725 | r->key = GNUNET_malloc (sizeof (GNUNET_HashCode)); | 721 | r->key = GNUNET_malloc (sizeof (GNUNET_HashCode)); |
726 | memcpy (r->key, &msg->key, sizeof (GNUNET_HashCode)); | 722 | memcpy (r->key, &msg->key, sizeof (GNUNET_HashCode)); |
727 | } | 723 | } |
728 | GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, r); | 724 | GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, r); |
729 | // FIXME add remove somewhere | 725 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
726 | } | ||
727 | |||
728 | /** | ||
729 | * Handler for monitor stop messages | ||
730 | * | ||
731 | * @param cls closure for the service | ||
732 | * @param client the client we received this message from | ||
733 | * @param message the actual message received | ||
734 | * | ||
735 | */ | ||
736 | static void | ||
737 | handle_dht_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client, | ||
738 | const struct GNUNET_MessageHeader *message) | ||
739 | { | ||
740 | struct ClientMonitorRecord *r; | ||
741 | const struct GNUNET_DHT_MonitorStartStopMessage *msg; | ||
742 | int keys_match; | ||
743 | |||
744 | msg = (struct GNUNET_DHT_MonitorStartStopMessage *) message; | ||
745 | r = monitor_head; | ||
746 | |||
747 | while (NULL != r) | ||
748 | { | ||
749 | if (NULL == r->key) | ||
750 | keys_match = (0 == ntohs(msg->filter_key)); | ||
751 | else | ||
752 | { | ||
753 | keys_match = (0 != ntohs(msg->filter_key) | ||
754 | && !memcmp(r->key, &msg->key, sizeof(GNUNET_HashCode))); | ||
755 | } | ||
756 | if (find_active_client(client) == r->client | ||
757 | && ntohl(msg->type) == r->type | ||
758 | && r->get == msg->get | ||
759 | && r->get_resp == msg->get_resp | ||
760 | && r->put == msg->put | ||
761 | && keys_match | ||
762 | ) | ||
763 | { | ||
764 | GNUNET_CONTAINER_DLL_remove (monitor_head, monitor_tail, r); | ||
765 | GNUNET_free_non_null (r->key); | ||
766 | GNUNET_free (r); | ||
767 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
768 | return; /* Delete only ONE entry */ | ||
769 | } | ||
770 | r = r->next; | ||
771 | } | ||
772 | |||
730 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 773 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
731 | } | 774 | } |
732 | 775 | ||
@@ -1301,7 +1344,10 @@ GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) | |||
1301 | sizeof (struct GNUNET_DHT_ClientGetStopMessage)}, | 1344 | sizeof (struct GNUNET_DHT_ClientGetStopMessage)}, |
1302 | {&handle_dht_local_monitor, NULL, | 1345 | {&handle_dht_local_monitor, NULL, |
1303 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, | 1346 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, |
1304 | sizeof (struct GNUNET_DHT_MonitorStartMessage)}, | 1347 | sizeof (struct GNUNET_DHT_MonitorStartStopMessage)}, |
1348 | {&handle_dht_local_monitor_stop, NULL, | ||
1349 | GNUNET_MESSAGE_TYPE_DHT_MONITOR_STOP, | ||
1350 | sizeof (struct GNUNET_DHT_MonitorStartStopMessage)}, | ||
1305 | {NULL, NULL, 0, 0} | 1351 | {NULL, NULL, 0, 0} |
1306 | }; | 1352 | }; |
1307 | forward_map = GNUNET_CONTAINER_multihashmap_create (1024); | 1353 | forward_map = GNUNET_CONTAINER_multihashmap_create (1024); |