make test resistant againt duplicate notifications
[oweals/gnunet.git] / src / transport / test_plugin_transport.c
index c48fc2d490022ac9887c96b257765de9ee0e9bd9..97a88beb5def7945ab15c30c024baed0262fcbd1 100644 (file)
@@ -48,7 +48,7 @@
 /**
  * Our public key.
  */
-static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
+static struct GNUNET_CRYPTO_EccPublicKey my_public_key;
 
 /**
  * Our identity.
@@ -197,6 +197,7 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct AddressWrapper *w;
   int c = 0;
+
   timeout_endbadly = GNUNET_SCHEDULER_NO_TASK;
   if (GNUNET_SCHEDULER_NO_TASK != timeout_wait)
   {
@@ -341,6 +342,7 @@ env_notify_address (void *cls,
                     const char *plugin)
 {
   struct AddressWrapper *w;
+  struct AddressWrapper *wtmp;
   void *s2a;
   size_t s2a_len;
 
@@ -350,7 +352,17 @@ env_notify_address (void *cls,
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Adding address of length %u\n", addrlen);
 
-      w = GNUNET_malloc (sizeof (struct AddressWrapper));
+      for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
+      {
+       if ((addrlen == wtmp->addrlen) && (0 == memcmp (addr, wtmp->addr, addrlen)))
+       {
+               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                      "Duplicate address notification .... \n");
+                       return;
+       }
+      }
+
+      w = GNUNET_new (struct AddressWrapper);
       w->addr = GNUNET_malloc (addrlen);
       w->addrlen = addrlen;
       memcpy (w->addr, addr, addrlen);
@@ -523,7 +535,6 @@ setup_plugin_environment ()
   env.my_identity = &my_identity;
   env.max_connections = max_connect_per_transport;
   env.stats = stats;
-
   env.receive = &env_receive;
   env.notify_address = &env_notify_address;
   env.get_address_type = &env_get_address_type;
@@ -532,6 +543,7 @@ setup_plugin_environment ()
   env.session_end = &env_session_end;
 }
 
+
 static int
 handle_helper_message (void *cls, void *client,
                        const struct GNUNET_MessageHeader *hdr)