-add missing comments, expand error checking
[oweals/gnunet.git] / src / dht / gnunet-service-dht_clients.c
index 7642dc6c3d43004262d47628413e8f01b6946164..a5ac0c32b1ac00ac6be087666949c3352404173c 100644 (file)
@@ -666,7 +666,9 @@ handle_dht_local_monitor (void *cls, struct GNUNET_SERVER_Client *client,
     r->key = GNUNET_malloc (sizeof (GNUNET_HashCode));
     memcpy (r->key, &msg->key, sizeof (GNUNET_HashCode));
   }
-
+  GNUNET_CONTAINER_DLL_insert (monitor_head, monitor_tail, r);
+  // FIXME add remove somewhere
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -1061,7 +1063,7 @@ GDS_CLIENTS_process_monitor (uint16_t mtype,
   cl_size = 0;
   for (m = monitor_head; NULL != m; m = m->next)
   {
-    if (m->type == type &&
+    if ((GNUNET_BLOCK_TYPE_ANY == m->type || m->type == type) &&
         (NULL == m->key ||
          memcmp (key, m->key, sizeof(GNUNET_HashCode)) == 0))
     {
@@ -1089,11 +1091,19 @@ GDS_CLIENTS_process_monitor (uint16_t mtype,
       mmsg->header.size = htons (msize - sizeof (struct PendingMessage));
       mmsg->header.type = htons (mtype);
       mmsg->expiration = GNUNET_TIME_absolute_hton(exp);
+      memcpy (&mmsg->key, key, sizeof (GNUNET_HashCode));
+      mmsg->put_path_length = htonl(putl);
+      mmsg->get_path_length = htonl(getl);
       path = (struct GNUNET_PeerIdentity *) &mmsg[1];
-      memcpy (path, put_path, putl * sizeof (struct GNUNET_PeerIdentity));
-      path = &path[putl];
-      memcpy (path, get_path, getl * sizeof (struct GNUNET_PeerIdentity));
-      memcpy (&path[getl], data, size);
+      if (putl > 0)
+      {
+        memcpy (path, put_path, putl * sizeof (struct GNUNET_PeerIdentity));
+        path = &path[putl];
+      }
+      if (getl > 0)
+        memcpy (path, get_path, getl * sizeof (struct GNUNET_PeerIdentity));
+      if (size > 0)
+        memcpy (&path[getl], data, size);
       add_pending_message (m->client, pm);
     }
   }