log
[oweals/gnunet.git] / src / scalarproduct / gnunet-scalarproduct.c
index e812ff44404876ad9a9abc1a43ae5a7a2a1682d4..aa894b61d644f44f6a6d6f0af53c2acacd4400ee 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 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
  */
 
 /**
@@ -137,7 +137,10 @@ requester_callback (void *cls,
     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,
@@ -181,8 +184,7 @@ requester_callback (void *cls,
  * @param tc unused
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   if (NULL != computation)
   {
@@ -240,13 +242,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 +282,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);
@@ -313,14 +321,14 @@ run (void *cls,
                                                               &responder_callback,
                                                               NULL))) ) )
   {
-    GNUNET_break (0);
+    fprintf (stderr,
+             _("Failed to initiate computation, were all keys unique?\n"));
     GNUNET_free (elements);
     return;
   }
   GNUNET_free (elements);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                &shutdown_task,
-                                NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
   ret = 0;
 }