made the service more resilient against out of order and simply incorrect messages
[oweals/gnunet.git] / src / scalarproduct / gnunet-scalarproduct.c
index 97cca3233f54b5bda4d27be64282bce761b2bc80..32ed952685c92b84c2d0a28e0d33056be36e6417 100644 (file)
@@ -77,9 +77,9 @@ static int ret = -1;
 
 /**
  * Callback called if we are initiating a new computation session
- * 
+ *
  * @param cls unused
- * @param status if our job was successfully processed 
+ * @param status if our job was successfully processed
  */
 static void
 responder_callback (void *cls,
@@ -104,19 +104,20 @@ responder_callback (void *cls,
   default:
     LOG (GNUNET_ERROR_TYPE_ERROR, "Session %s failed: return code %d\n", GNUNET_h2s (&closure->key), status);
   }
+  GNUNET_SCHEDULER_shutdown();
 }
 
 
 /**
  * Callback called if we are initiating a new computation session
- * 
+ *
  * @param cls unused
  * @param key unused
  * @param peer unused
- * @param status if our job was successfully processed 
+ * @param status if our job was successfully processed
  * @param size size of the msg returned
  * @param msg the response we got.
- * @param type of the message received 
+ * @param type of the message received
  */
 static void
 requester_callback (void *cls,
@@ -149,6 +150,7 @@ requester_callback (void *cls,
   default:
     LOG (GNUNET_ERROR_TYPE_ERROR, "Session %s with peer %s failed: return code %d\n", GNUNET_h2s (&closure->key), GNUNET_i2s (&closure->peer), status);
   }
+  GNUNET_SCHEDULER_shutdown();
 }
 
 /**
@@ -223,13 +225,13 @@ run (void *cls,
     // get the length of the current element and replace , with null
     for (end = begin; *end && *end != ','; end++);
 
-    if (1 == sscanf (begin, "%" SCNd32",", &element))
+    if (1 == sscanf (begin, "%" SCNd32 ",", &element))
     {
       //element in the middle
       element_count++;
       begin = end + 1;
     }
-    else if (*begin == 0)
+    else if (0 == *begin)
     {
       break;
     }
@@ -242,25 +244,26 @@ run (void *cls,
   while (1);
   if (0 == element_count)
   {
-
+    LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Need elements to compute the vectorproduct, got none.\n"));
     return;
   }
 
   begin = input_elements;
   elements = GNUNET_malloc (sizeof (int32_t) * element_count);
+  element_count = 0;
   /* Read input_elements_peer1, and put in elements_peer1 array */
   do
   {
     // get the length of the current element and replace , with null
     for (end = begin; *end && *end != ','; end++);
 
-    if (1 == sscanf (begin, "%" SCNd32",", &element))
+    if (1 == sscanf (begin, "%" SCNd32 ",", &elements[element_count]))
     {
       //element in the middle
       element_count++;
       begin = end + 1;
     }
-    else if (*begin == 0)
+    else if (0 == *begin)
     {
       break;
     }
@@ -268,7 +271,7 @@ run (void *cls,
   while (1);
 
   mask_bytes = element_count / 8 + (element_count % 8 ? 1 : 0);
-  mask = GNUNET_malloc ((element_count / 8) + 2);
+  mask = GNUNET_malloc ((element_count / 8) + 1);
 
   /* Read input_mask_peer1 and read in mask_peer1 array */
   if ((NULL != input_peer_id) && (NULL != input_mask))
@@ -325,7 +328,7 @@ run (void *cls,
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                 &shutdown_task,
                                 NULL);
-  
+
   ret = 0;
 }