aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht_clients.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/gnunet-service-dht_clients.c
parent5cb80076be6f79e7bd58cc9e765bceec372b6e8b (diff)
downloadgnunet-c0953e20856f7c29e15ef1d8bfbb308c8fecc6d6.tar.gz
gnunet-c0953e20856f7c29e15ef1d8bfbb308c8fecc6d6.zip
Added stop operation for dht monitoring
Diffstat (limited to 'src/dht/gnunet-service-dht_clients.c')
-rw-r--r--src/dht/gnunet-service-dht_clients.c74
1 files changed, 60 insertions, 14 deletions
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 */
736static void
737handle_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);