-improve UDP logging
[oweals/gnunet.git] / src / scalarproduct / gnunet-scalarproduct.c
index c6ed365f85e71c53c9fc1de695a4283571c013e1..f44f4c518a6f1e3edf28280886b0ff901bd8f33b 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2013, 2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2013, 2014 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -84,23 +84,23 @@ responder_callback (void *cls,
 {
   switch (status)
   {
-  case GNUNET_SCALARPRODUCT_Status_Success:
+  case GNUNET_SCALARPRODUCT_STATUS_SUCCESS:
     ret = 0;
     LOG (GNUNET_ERROR_TYPE_INFO,
          "Session %s concluded.\n",
          GNUNET_h2s (&session_key));
     break;
-  case GNUNET_SCALARPRODUCT_Status_InvalidResponse:
+  case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE:
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Session %s failed: invalid response\n",
          GNUNET_h2s (&session_key));
     break;
-  case GNUNET_SCALARPRODUCT_Status_Failure:
+  case GNUNET_SCALARPRODUCT_STATUS_FAILURE:
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Session %s failed: service failure\n",
          GNUNET_h2s (&session_key));
     break;
-  case GNUNET_SCALARPRODUCT_Status_ServiceDisconnected:
+  case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED:
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Session %s failed: service disconnect!\n",
          GNUNET_h2s (&session_key));
@@ -133,30 +133,33 @@ requester_callback (void *cls,
 
   switch (status)
   {
-  case GNUNET_SCALARPRODUCT_Status_Success:
+  case GNUNET_SCALARPRODUCT_STATUS_SUCCESS:
     if (0 == (rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, result)))
     {
       ret = 0;
-      printf ("%s", buf);
+      fprintf (stdout,
+               "%s\n",
+               buf);
+      fflush (stdout);
     }
     else
       LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
                 "gcry_mpi_aprint",
                 rc);
     break;
-  case GNUNET_SCALARPRODUCT_Status_InvalidResponse:
+  case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE:
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Session %s with peer %s failed: invalid response received\n",
          GNUNET_h2s (&session_key),
          GNUNET_i2s (&peer_id));
     break;
-  case GNUNET_SCALARPRODUCT_Status_Failure:
+  case GNUNET_SCALARPRODUCT_STATUS_FAILURE:
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Session %s with peer %s failed: API failure\n",
          GNUNET_h2s (&session_key),
          GNUNET_i2s (&peer_id));
     break;
-  case GNUNET_SCALARPRODUCT_Status_ServiceDisconnected:
+  case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED:
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "Session %s with peer %s was disconnected from service.\n",
          GNUNET_h2s (&session_key),
@@ -240,13 +243,20 @@ run (void *cls,
          input_peer_id);
     return;
   }
-
+  if ( ('\'' == *begin) &&
+       ('\'' == begin[strlen(begin)-1]) )
+  {
+    begin[strlen(begin)-1] = '\0';
+    if (strlen (begin) > 0)
+      begin++;
+  }
   for (end = begin; 0 != *end; end++)
     if (*end == ';')
       element_count++;
-  if (0 == element_count) {
+  if (0 == element_count)
+  {
     LOG (GNUNET_ERROR_TYPE_ERROR,
-         _("Need elements to compute the vectorproduct, got none.\n"));
+         _("Need elements to compute the scalarproduct, got none.\n"));
     return;
   }
 
@@ -273,9 +283,8 @@ run (void *cls,
       GNUNET_free (elements);
       return;
     }
-
-    /* read the element's key */
     *separator = 0;
+    /* read the element's key */
     GNUNET_CRYPTO_hash (begin,
                         strlen (begin),
                         &element.key);
@@ -289,9 +298,10 @@ run (void *cls,
       LOG (GNUNET_ERROR_TYPE_ERROR,
            _("Could not convert `%s' to int64_t.\n"),
            begin);
-      GNUNET_free(elements);
+      GNUNET_free (elements);
       return;
     }
+    element.value = GNUNET_htonll (element.value);
     elements[i] = element;
     begin = end + 1;
   }
@@ -312,7 +322,8 @@ run (void *cls,
                                                               &responder_callback,
                                                               NULL))) ) )
   {
-    GNUNET_break (0);
+    fprintf (stderr,
+             _("Failed to initiate computation, were all keys unique?\n"));
     GNUNET_free (elements);
     return;
   }