- typo
[oweals/gnunet.git] / src / multicast / multicast_api.c
index 3dbc07f5d4710ac7c588fa0d10482918c7f17e8f..31a02b96d67ea9e2805ae224b448a11808dd99b4 100644 (file)
 #include "gnunet_multicast_service.h"
 #include "multicast.h"
 
-/**
+#define LOG(kind,...) GNUNET_log_from (kind, "multicast-api",__VA_ARGS__)
+
+
+/** 
  * Handle for a request to send a message to all multicast group members
  * (from the origin).
  */
@@ -38,6 +41,7 @@ struct GNUNET_MULTICAST_OriginMessageHandle
 {
   GNUNET_MULTICAST_OriginTransmitNotify notify;
   void *notify_cls;
+  struct GNUNET_MULTICAST_Origin *origin;
 
   uint64_t message_id;
   uint64_t group_generation;
@@ -50,7 +54,7 @@ struct GNUNET_MULTICAST_OriginMessageHandle
  */
 struct GNUNET_MULTICAST_Origin
 {
-  struct GNUNET_CRYPTO_EccPrivateKey priv_key;
+  struct GNUNET_CRYPTO_EddsaPrivateKey priv_key;
   struct GNUNET_MULTICAST_OriginMessageHandle msg_handle;
 
   GNUNET_MULTICAST_JoinCallback join_cb;
@@ -96,14 +100,14 @@ struct GNUNET_MULTICAST_RequestHeader
   /**
    * Public key of the sending member.
    */
-  struct GNUNET_CRYPTO_EccPublicSignKey member_key;
+  struct GNUNET_CRYPTO_EddsaPublicKey member_key;
 
   /**
    * ECC signature of the request fragment.
    *
    * Signature must match the public key of the multicast group.
    */
-  struct GNUNET_CRYPTO_EccSignature signature;
+  struct GNUNET_CRYPTO_EddsaSignature signature;
 
   /**
    * Purpose for the signature and size of the signed data.
@@ -150,7 +154,7 @@ struct GNUNET_MULTICAST_JoinRequest
    *
    * Signature must match the public key of the joining member.
    */
-  struct GNUNET_CRYPTO_EccSignature signature;
+  struct GNUNET_CRYPTO_EddsaSignature signature;
 
   /**
    * Purpose for the signature and size of the signed data.
@@ -160,12 +164,12 @@ struct GNUNET_MULTICAST_JoinRequest
   /**
    * Public key of the target group.
    */
-  struct GNUNET_CRYPTO_EccPublicSignKey group_key;
+  struct GNUNET_CRYPTO_EddsaPublicKey group_key;
 
   /**
    * Public key of the joining member.
    */
-  struct GNUNET_CRYPTO_EccPublicSignKey member_key;
+  struct GNUNET_CRYPTO_EddsaPublicKey member_key;
 
   /**
    * Peer identity of the joining member.
@@ -325,7 +329,7 @@ GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh,
  */
 struct GNUNET_MULTICAST_Origin *
 GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                               const struct GNUNET_CRYPTO_EccPrivateKey *priv_key,
+                               const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key,
                                uint64_t next_fragment_id,
                                GNUNET_MULTICAST_JoinCallback join_cb,
                                GNUNET_MULTICAST_MembershipTestCallback mem_test_cb,
@@ -353,6 +357,7 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
 static void
 schedule_origin_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "schedule_origin_to_all()\n");
   struct GNUNET_MULTICAST_Origin *orig = cls;
   struct GNUNET_MULTICAST_OriginMessageHandle *mh = &orig->msg_handle;
 
@@ -361,12 +366,18 @@ schedule_origin_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
     = GNUNET_malloc (sizeof (*msg) + buf_size);
   int ret = mh->notify (mh->notify_cls, &buf_size, &msg[1]);
 
-  if (ret != GNUNET_YES || ret != GNUNET_NO)
+  if (! (GNUNET_YES == ret || GNUNET_NO == ret)
+      || buf_size > GNUNET_MULTICAST_FRAGMENT_MAX_SIZE)
   {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         "MasterTransmitNotify() returned error or invalid message size.\n");
     /* FIXME: handle error */
     return;
   }
 
+  if (GNUNET_NO == ret && 0 == buf_size)
+    return; /* Transmission paused. */
+
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE);
   msg->header.size = htons (buf_size);
   msg->message_id = mh->message_id;
@@ -382,7 +393,7 @@ schedule_origin_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
                              - sizeof (msg->signature));
   msg->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_MULTICAST_MESSAGE);
 
-  if (GNUNET_OK != GNUNET_CRYPTO_ecc_sign (&orig->priv_key, &msg->purpose,
+  if (GNUNET_OK != GNUNET_CRYPTO_eddsa_sign (&orig->priv_key, &msg->purpose,
                                            &msg->signature))
   {
     /* FIXME: handle error */
@@ -393,12 +404,12 @@ schedule_origin_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
    *        returned signed message.
    * FIXME: Also send to local members in this group.
    */
-  orig->message_cb (orig->cls, msg);
+  orig->message_cb (orig->cls, (const struct GNUNET_MessageHeader *) msg);
 
   if (GNUNET_NO == ret)
     GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
                                   (GNUNET_TIME_UNIT_SECONDS, 1),
-                                  schedule_origin_to_all, mh);
+                                  schedule_origin_to_all, orig);
 
 }
 
@@ -421,6 +432,7 @@ GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
                                 void *notify_cls)
 {
   struct GNUNET_MULTICAST_OriginMessageHandle *mh = &origin->msg_handle;
+  mh->origin = origin;
   mh->message_id = message_id;
   mh->group_generation = group_generation;
   mh->notify = notify;
@@ -441,7 +453,7 @@ GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
 void
 GNUNET_MULTICAST_origin_to_all_resume (struct GNUNET_MULTICAST_OriginMessageHandle *mh)
 {
-
+  GNUNET_SCHEDULER_add_now (schedule_origin_to_all, mh->origin);
 }
 
 
@@ -511,8 +523,8 @@ GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin)
  */
 struct GNUNET_MULTICAST_Member *
 GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                              const struct GNUNET_CRYPTO_EccPublicSignKey *group_key,
-                              const struct GNUNET_CRYPTO_EccPrivateKey *member_key,
+                              const struct GNUNET_CRYPTO_EddsaPublicKey *group_key,
+                              const struct GNUNET_CRYPTO_EddsaPrivateKey *member_key,
                               const struct GNUNET_PeerIdentity *origin,
                               uint32_t relay_count,
                               const struct GNUNET_PeerIdentity *relays,