gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 25/40: Hello: Changed address and hello format to new TNG forma


From: gnunet
Subject: [gnunet] 25/40: Hello: Changed address and hello format to new TNG format.
Date: Thu, 05 Oct 2023 08:57:28 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

commit 66ecfe29c2b0ca3e68646666fa80a17797b5484b
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Tue Oct 3 11:10:50 2023 +0200

    Hello: Changed address and hello format to new TNG format.
---
 src/dhtu/plugin_dhtu_gnunet.c         |  55 ++++++++---
 src/hello/hello-uri.c                 |  20 +++-
 src/topology/gnunet-daemon-topology.c | 109 ++++++++++++++-------
 src/transport/gnunet-service-tng.c    | 176 ++++++++++++++++++++++++----------
 4 files changed, 255 insertions(+), 105 deletions(-)

diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c
index 665db4545..aca641d4e 100644
--- a/src/dhtu/plugin_dhtu_gnunet.c
+++ b/src/dhtu/plugin_dhtu_gnunet.c
@@ -193,11 +193,29 @@ gnunet_try_connect (void *cls,
 {
   struct Plugin *plugin = cls;
   enum GNUNET_NetworkType nt = 0;
-
+  char *addr;
+  const char *eou;
+  int pfx_len;
+  
+  eou = strstr (address,
+                  "://");
+  if (NULL == eou)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  pfx_len = eou - address;
+  eou += 3;
+  GNUNET_asprintf (&addr,
+                   "%.*s-%s",
+                   pfx_len,
+                   address,
+                   eou);
   GNUNET_TRANSPORT_application_validate (plugin->transport,
                                          pid,
                                          nt,
-                                         address);
+                                         addr);
+  GNUNET_free (addr);
 }
 
 
@@ -356,6 +374,22 @@ core_disconnect_cb (void *cls,
 }
 
 
+static void
+add_addr (void *cls,
+          const char *addr)
+{
+  struct Plugin *plugin = cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG ,
+              "peerinfo_cb addr %s\n",
+              addr);
+  plugin->env->address_add_cb (plugin->env->cls,
+                               addr,
+                               &plugin->src,
+                               &plugin->src.app_ctx);
+}
+
+
 /**
  * Find the @a hello for our identity and then pass
  * it to the DHT as a URL.  Note that we only
@@ -387,16 +421,11 @@ peerinfo_cb (void *cls,
                      &plugin->my_identity))
     return;
   builder = GNUNET_HELLO_builder_from_msg (hello);
-  addr = GNUNET_HELLO_builder_to_url (builder,
-                                      plugin->my_priv);
-  if (NULL == addr)
-    return;
-  plugin->env->address_add_cb (plugin->env->cls,
-                               addr,
-                               &plugin->src,
-                               &plugin->src.app_ctx);
-  GNUNET_free (addr);
-  GNUNET_HELLO_Builder_free (builder);
+  GNUNET_HELLO_builder_iterate (builder,
+                                (struct GNUNET_PeerIdentity *) peer,
+                                add_addr,
+                                plugin);
+  GNUNET_HELLO_builder_free (builder);
 }
 
 
@@ -515,7 +544,7 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls)
   if (NULL != plugin->peerstore_notify)
     GNUNET_PEERSTORE_hello_changed_notify_cancel (plugin->peerstore_notify);
   if (NULL != plugin->peerstore)
-    GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
+    GNUNET_PEERSTORE_disconnect (plugin->peerstore, GNUNET_YES);
   GPI_plugins_unload ();
   GNUNET_free (plugin->my_priv);
   GNUNET_free (plugin);
diff --git a/src/hello/hello-uri.c b/src/hello/hello-uri.c
index fb35ee353..4a8591ed1 100644
--- a/src/hello/hello-uri.c
+++ b/src/hello/hello-uri.c
@@ -446,12 +446,24 @@ GNUNET_HELLO_builder_from_block (const void *block,
 
 
 struct GNUNET_TIME_Absolute
-GNUNET_HELLO_builder_get_expiration_time (struct GNUNET_HELLO_Builder *builder,
-                                          const struct GNUNET_MessageHeader 
*msg)
+GNUNET_HELLO_builder_get_expiration_time (const struct
+                                          GNUNET_MessageHeader *msg)
 {
-  struct BlockHeader *bh = (struct BlockHeader *) &msg[1];
+  if (GNUNET_MESSAGE_TYPE_HELLO_URI == ntohs (msg->type))
+  {
+    const struct HelloUriMessage *h = (struct HelloUriMessage *) msg;
+    const struct BlockHeader *bh = (const struct BlockHeader *) &h[1];
+
+    return GNUNET_TIME_absolute_ntoh (bh->expiration_time);
+  }
+  else if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO == ntohs (msg->type))
+  {
+    const struct DhtHelloMessage *dht_hello = (struct DhtHelloMessage *) msg;
 
-  return GNUNET_TIME_absolute_ntoh (bh->expiration_time);
+    return GNUNET_TIME_absolute_ntoh (dht_hello->expiration_time);
+  }
+  else
+    GNUNET_break (0);
 }
 
 
diff --git a/src/topology/gnunet-daemon-topology.c 
b/src/topology/gnunet-daemon-topology.c
index b28269a77..efe014776 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -125,6 +125,13 @@ struct Peer
 };
 
 
+/**
+ * The task to delayed start the notification process intially. 
+ * We like to give transport some time to give us our hello to distribute it.
+ */
+struct GNUNET_SCHEDULER_Task *peerstore_notify_task;
+
+
 /**
  * Our peerstore notification context.  We use notification
  * to instantly learn about new peers as they are discovered.
@@ -353,8 +360,8 @@ make_peer (const struct GNUNET_PeerIdentity *peer,
   ret->is_friend = is_friend;
   if (NULL != hello)
   {
-    ret->hello = GNUNET_malloc (sizeof (hello));
-    GNUNET_memcpy (ret->hello, hello, sizeof (hello));
+    ret->hello = GNUNET_malloc (ntohs (hello->size));
+    GNUNET_memcpy (ret->hello, hello, ntohs (hello->size));
   }
   GNUNET_break (GNUNET_OK ==
                 GNUNET_CONTAINER_multipeermap_put (
@@ -504,10 +511,11 @@ schedule_next_hello (void *cls)
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "schedule_next_hello 3\n");
-  want = fah.result->hello->size;
+  want = ntohs (fah.result->hello->size);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Sending HELLO with %u bytes",
-              (unsigned int) want);
+              "Sending HELLO with %u bytes for peer %s\n",
+              (unsigned int) want,
+              GNUNET_i2s (&pl->pid));
   env = GNUNET_MQ_msg_copy (fah.result->hello);
   GNUNET_MQ_send (pl->mq, env);
 
@@ -543,14 +551,12 @@ reschedule_hellos (void *cls,
                    const struct GNUNET_PeerIdentity *pid,
                    void *value)
 {
+  (void *) cls;
   struct Peer *peer = value;
-  struct Peer *skip = cls;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Reschedule for `%s'\n",
               GNUNET_i2s (&peer->pid));
-  if (skip == peer)
-    return GNUNET_YES;
   if (NULL == peer->mq)
     return GNUNET_YES;
   if (NULL != peer->hello_delay_task)
@@ -712,7 +718,8 @@ address_iterator (void *cls,
 {
   int *flag = cls;
 
-  *flag = GNUNET_YES;
+  *flag = *flag + 1;
+  //*flag = GNUNET_YES;
 }
 
 
@@ -725,57 +732,76 @@ address_iterator (void *cls,
 static void
 consider_for_advertising (const struct GNUNET_MessageHeader *hello)
 {
-  int have_address;
+  int num_addresses_old;
+  int num_addresses_new;
   struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (hello);
-  struct GNUNET_PeerIdentity *pid;
+  struct GNUNET_PeerIdentity *pid = GNUNET_HELLO_builder_get_id (builder);
   struct GNUNET_TIME_Absolute dt;
   struct GNUNET_MQ_Envelope *env;
   const struct GNUNET_MessageHeader *nh;
   struct Peer *peer;
   uint16_t size;
 
-  have_address = GNUNET_NO;
   GNUNET_HELLO_builder_iterate (builder,
                                 pid,
                                 &address_iterator,
-                                &have_address);
-  if (GNUNET_NO == have_address)
+                                &num_addresses_new);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "consider 0 for %s\n",
+              GNUNET_i2s (pid));
+  if (0 == num_addresses_new)
+  {
+    GNUNET_HELLO_builder_free (builder);
     return; /* no point in advertising this one... */
-  if (NULL == pid || 0 == GNUNET_memcmp (pid, &my_identity))
-    return; /* that's me! */
-
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "consider 1\n");
+  if (NULL == pid)
+  {
+    GNUNET_HELLO_builder_free (builder);
+    return;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "consider 2\n");
   peer = GNUNET_CONTAINER_multipeermap_get (peers, pid);
   if (NULL == peer)
   {
     peer = make_peer (pid, hello, GNUNET_NO);
   }
-
-  if (NULL != peer->hello)
+  else if (NULL != peer->hello)
   {
     struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-    struct GNUNET_TIME_Absolute new_hello_exp = 
GNUNET_HELLO_builder_get_expiration_time (builder,
-                                                                               
           hello);
-    struct GNUNET_HELLO_Builder *peer_builder = GNUNET_HELLO_builder_from_msg 
(peer->hello);
-    struct GNUNET_TIME_Absolute old_hello_exp = 
GNUNET_HELLO_builder_get_expiration_time (peer_builder,
-                                                                               
           peer->hello);
-
-    if (GNUNET_TIME_absolute_cmp (new_hello_exp, > , now) && 
GNUNET_TIME_absolute_cmp (new_hello_exp, > , old_hello_exp))
+    struct GNUNET_TIME_Absolute new_hello_exp =
+      GNUNET_HELLO_builder_get_expiration_time (hello);
+    struct GNUNET_TIME_Absolute old_hello_exp =
+      GNUNET_HELLO_builder_get_expiration_time (peer->hello);
+    struct GNUNET_HELLO_Builder *builder_old = GNUNET_HELLO_builder_from_msg 
(peer->hello);
+    struct GNUNET_PeerIdentity *pid_old = GNUNET_HELLO_builder_get_id 
(builder_old);
+
+    GNUNET_HELLO_builder_iterate (builder_old,
+                                  pid_old,
+                                  &address_iterator,
+                                  &num_addresses_old);
+    if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
+        (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) ||
+         num_addresses_old < num_addresses_new))
     {
       GNUNET_free (peer->hello);
-      size = sizeof (hello);
+      size = ntohs (hello->size);
       peer->hello = GNUNET_malloc (size);
       GNUNET_memcpy (peer->hello, hello, size);
     }
     else
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "consider 3\n");
+      GNUNET_HELLO_builder_free (builder);
       return;
     }
-    GNUNET_HELLO_builder_free (builder);
-    GNUNET_HELLO_builder_free (peer_builder);
   }
   else
   {
-    size = sizeof (hello);
+    size = ntohs (hello->size);
     peer->hello = GNUNET_malloc (size);
     GNUNET_memcpy (peer->hello, hello, size);
   }
@@ -790,7 +816,8 @@ consider_for_advertising (const struct GNUNET_MessageHeader 
*hello)
   setup_filter (peer);
   /* since we have a new HELLO to pick from, re-schedule all
    * HELLO requests that are not bound by the HELLO send rate! */
-  GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer);
+  GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, NULL);
+  GNUNET_HELLO_builder_free (builder);
 }
 
 
@@ -823,8 +850,6 @@ process_peer (void *cls,
     return;
   }
   GNUNET_assert (NULL != peer);
-  if (0 == GNUNET_memcmp (&my_identity, peer))
-    return; /* that's me! */
   if (NULL == hello)
   {
     /* free existing HELLO, if any */
@@ -850,6 +875,15 @@ process_peer (void *cls,
   attempt_connect (pos);
 }
 
+static void
+start_notify (void *cls)
+{
+  (void *) cls;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to process new hellos for 
gossiping.\n");
+  peerstore_notify =
+    GNUNET_PEERSTORE_hello_changed_notify (ps, GNUNET_NO, &process_peer, NULL);
+}
 
 /**
  * Function called after #GNUNET_CORE_connect has succeeded
@@ -871,8 +905,9 @@ core_init (void *cls, const struct GNUNET_PeerIdentity 
*my_id)
   }
   my_identity = *my_id;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
-  peerstore_notify =
-    GNUNET_PEERSTORE_hello_changed_notify (ps, GNUNET_NO, &process_peer, NULL);
+  peerstore_notify_task = GNUNET_SCHEDULER_add_delayed 
(GNUNET_TIME_UNIT_MINUTES,
+                                                        start_notify,
+                                                        NULL);
 }
 
 
@@ -1030,6 +1065,10 @@ cleaning_task (void *cls)
     GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify);
     peerstore_notify = NULL;
   }
+  else if (NULL != peerstore_notify_task)
+  {
+    GNUNET_SCHEDULER_cancel (peerstore_notify_task);
+  }
   if (NULL != handle)
   {
     GNUNET_CORE_disconnect (handle);
diff --git a/src/transport/gnunet-service-tng.c 
b/src/transport/gnunet-service-tng.c
index 5f2504c70..69dab525a 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -2045,9 +2045,9 @@ struct IncomingRequest
   struct IncomingRequest *prev;
 
   /**
-   * Handle for watching the peerstore for HELLOs for this peer.
+   * Notify context for new HELLOs.
    */
-  struct GNUNET_PEERSTORE_WatchContext *wc;
+  struct GNUNET_PEERSTORE_NotifyContext *nc;
 
   /**
    * Which peer is this about?
@@ -2072,9 +2072,9 @@ struct PeerRequest
   struct TransportClient *tc;
 
   /**
-   * Handle for watching the peerstore for HELLOs for this peer.
+   * Notify context for new HELLOs.
    */
-  struct GNUNET_PEERSTORE_WatchContext *wc;
+  struct GNUNET_PEERSTORE_NotifyContext *nc;
 
   /**
    * What kind of performance preference does this @e tc have?
@@ -2924,8 +2924,8 @@ free_incoming_request (struct IncomingRequest *ir)
   GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir);
   GNUNET_assert (ir_total > 0);
   ir_total--;
-  GNUNET_PEERSTORE_watch_cancel (ir->wc);
-  ir->wc = NULL;
+  GNUNET_PEERSTORE_hello_changed_notify_cancel (ir->nc);
+  ir->nc = NULL;
   GNUNET_free (ir);
 }
 
@@ -3902,8 +3902,8 @@ stop_peer_request (void *cls,
   struct TransportClient *tc = cls;
   struct PeerRequest *pr = value;
 
-  GNUNET_PEERSTORE_watch_cancel (pr->wc);
-  pr->wc = NULL;
+  GNUNET_PEERSTORE_hello_changed_notify_cancel (pr->nc);
+  pr->nc = NULL;
   GNUNET_assert (
     GNUNET_YES ==
     GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests,
@@ -4021,8 +4021,12 @@ notify_client_connect_info (void *cls,
                             void *value)
 {
   struct TransportClient *tc = cls;
+  struct Neighbour *n = value;
+  struct VirtualLink *vl = n->vl;
+
+  if ((NULL == vl) || (GNUNET_NO == vl->confirmed))
+    return GNUNET_OK;
 
-  (void) value;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Telling new CORE client about existing connection to %s\n",
               GNUNET_i2s (pid));
@@ -5545,8 +5549,17 @@ store_pi (void *cls)
   struct GNUNET_TIME_Absolute expiration;
   enum GNUNET_GenericReturnValue add_result;
   struct GNUNET_MQ_Envelope *env;
-  const struct GNUNET_MessageHeader *msg = GNUNET_MQ_env_get_msg (env);
-
+  const struct GNUNET_MessageHeader *msg;
+  const char *dash;
+  char *prefix = GNUNET_HELLO_address_to_prefix (ale->address);
+  char *address_uri;
+
+  dash = strchr (ale->address, '-');
+  dash++;
+  GNUNET_asprintf (&address_uri,
+                     "%s://%s",
+                     prefix,
+                     dash);
   ale->st = NULL;
   expiration = GNUNET_TIME_relative_to_absolute (ale->expiration);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5554,19 +5567,23 @@ store_pi (void *cls)
               ale->address,
               GNUNET_STRINGS_absolute_time_to_string (expiration));
   add_result = GNUNET_HELLO_builder_add_address (GST_my_hello,
-                                      ale->address);
+                                                 address_uri);
   env = GNUNET_HELLO_builder_to_env (GST_my_hello,
                                      GST_my_private_key,
                                      GNUNET_TIME_UNIT_ZERO);
+  msg = GNUNET_MQ_env_get_msg (env);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "store_pi 1\n");
   if (GNUNET_YES == add_result)
     shc = GNUNET_PEERSTORE_hello_add (peerstore,
-                                msg,
-                                shc_cont,
-                                shc);
+                                      msg,
+                                      shc_cont,
+                                      shc);
   else if (GNUNET_SYSERR == add_result)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Error adding address to peerstore hello!\n");
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "store_pi 2\n");
   GNUNET_HELLO_sign_address (ale->address,
                              ale->nt,
                              hello_mono_time,
@@ -5585,6 +5602,8 @@ store_pi (void *cls)
                                     ale);
   GNUNET_free (addr);
   GNUNET_free (env);
+  GNUNET_free (prefix);
+  GNUNET_free (address_uri);
   if (NULL == ale->sc)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -8633,6 +8652,34 @@ start_address_validation (const struct 
GNUNET_PeerIdentity *pid,
 }
 
 
+static void
+hello_for_incoming_cb (void *cls,
+                       const char *uri)
+{
+  const struct GNUNET_PeerIdentity *peer = cls;
+  int pfx_len;
+  const char *eou;
+  char *address;
+
+  eou = strstr (uri,
+                "://");
+  pfx_len = eou - uri;
+  eou += 3;
+  GNUNET_asprintf (&address,
+                   "%.*s-%s",
+                   pfx_len,
+                   uri,
+                   eou);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "helo for client %s\n",
+              address);
+
+  start_address_validation (peer, address);
+  GNUNET_free (address);
+}
+
+
 /**
  * Function called by PEERSTORE for each matching record.
  *
@@ -8642,11 +8689,12 @@ start_address_validation (const struct 
GNUNET_PeerIdentity *pid,
  */
 static void
 handle_hello_for_incoming (void *cls,
-                           const struct GNUNET_PEERSTORE_Record *record,
+                           const struct GNUNET_PeerIdentity *peer,
+                           const struct GNUNET_MessageHeader *hello,
                            const char *emsg)
 {
   struct IncomingRequest *ir = cls;
-  const char *val;
+  struct GNUNET_HELLO_Builder *builder;
 
   if (NULL != emsg)
   {
@@ -8655,13 +8703,13 @@ handle_hello_for_incoming (void *cls,
                 emsg);
     return;
   }
-  val = record->value;
-  if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
-  {
-    GNUNET_break (0);
+  if (0 == GNUNET_memcmp (peer, &GST_my_identity))
     return;
-  }
-  start_address_validation (&ir->pid, (const char *) record->value);
+  builder = GNUNET_HELLO_builder_new (peer);
+  GNUNET_HELLO_builder_iterate (builder,
+                                (struct GNUNET_PeerIdentity *) peer,
+                                hello_for_incoming_cb,
+                                (struct GNUNET_PeerIdentity *) peer);
 }
 
 
@@ -8762,12 +8810,11 @@ handle_validation_challenge (
   ir = GNUNET_new (struct IncomingRequest);
   ir->pid = sender;
   GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir);
-  ir->wc = GNUNET_PEERSTORE_watch (peerstore,
-                                   "transport",
-                                   &ir->pid,
-                                   GNUNET_PEERSTORE_HELLO_KEY,
-                                   &handle_hello_for_incoming,
-                                   ir);
+
+  ir->nc = GNUNET_PEERSTORE_hello_changed_notify (peerstore,
+                                                  GNUNET_NO,
+                                                  &handle_hello_for_incoming,
+                                                  NULL);
   ir_total++;
   /* Bound attempts we do in parallel here, might otherwise get excessive */
   while (ir_total > MAX_INCOMING_REQUEST)
@@ -8789,8 +8836,6 @@ struct CheckKnownChallengeContext
    * Set to a matching validation state, if one was found.
    */
   struct ValidationState *vs;
-
-  char *address_prefix;
 };
 
 
@@ -8812,8 +8857,7 @@ check_known_challenge (void *cls,
   struct ValidationState *vs = value;
 
   (void) pid;
-  if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge) ||
-      NULL == strstr (vs->address, ckac->address_prefix))
+  if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge))
     return GNUNET_OK;
   ckac->vs = vs;
   return GNUNET_NO;
@@ -8883,14 +8927,12 @@ handle_validation_response (
   struct CommunicatorMessageContext *cmc = cls;
   struct ValidationState *vs;
   struct CheckKnownChallengeContext ckac = { .challenge = &tvr->challenge,
-                                             .vs = NULL,
-                                             .address_prefix =
-                                               cmc->tc->details.communicator.
-                                               address_prefix};
+                                             .vs = NULL};
   struct GNUNET_TIME_Absolute origin_time;
   struct Queue *q;
   struct Neighbour *n;
   struct VirtualLink *vl;
+  const struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get_monotonic 
(GST_cfg);
 
   /* check this is one of our challenges */
   (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
@@ -11210,6 +11252,34 @@ handle_suggest_cancel (void *cls, const struct 
ExpressPreferenceMessage *msg)
 }
 
 
+static void
+hello_for_client_cb (void *cls,
+                       const char *uri)
+{
+  const struct GNUNET_PeerIdentity *peer = cls;
+  int pfx_len;
+  const char *eou;
+  char *address;
+
+  eou = strstr (uri,
+                "://");
+  pfx_len = eou - uri;
+  eou += 3;
+  GNUNET_asprintf (&address,
+                   "%.*s-%s",
+                   pfx_len,
+                   uri,
+                   eou);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "hello for client %s\n",
+              address);
+  
+  start_address_validation (peer, address);
+  GNUNET_free (address);
+}
+
+
 /**
  * Function called by PEERSTORE for each matching record.
  *
@@ -11219,11 +11289,13 @@ handle_suggest_cancel (void *cls, const struct 
ExpressPreferenceMessage *msg)
  */
 static void
 handle_hello_for_client (void *cls,
-                         const struct GNUNET_PEERSTORE_Record *record,
+                         const struct GNUNET_PeerIdentity *peer,
+                         const struct GNUNET_MessageHeader *hello,
                          const char *emsg)
 {
-  struct PeerRequest *pr = cls;
+  (void *) cls;
   const char *val;
+  struct GNUNET_HELLO_Builder *builder;
 
   if (NULL != emsg)
   {
@@ -11232,13 +11304,13 @@ handle_hello_for_client (void *cls,
                 emsg);
     return;
   }
-  val = record->value;
-  if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
-  {
-    GNUNET_break (0);
+  if (0 == GNUNET_memcmp (peer, &GST_my_identity))
     return;
-  }
-  start_address_validation (&pr->pid, (const char *) record->value);
+  builder = GNUNET_HELLO_builder_new (peer);
+  GNUNET_HELLO_builder_iterate (builder,
+                                (struct GNUNET_PeerIdentity *) peer,
+                                hello_for_client_cb,
+                                NULL);
 }
 
 
@@ -11288,12 +11360,10 @@ handle_suggest (void *cls, const struct 
ExpressPreferenceMessage *msg)
     GNUNET_SERVICE_client_drop (tc->client);
     return;
   }
-  pr->wc = GNUNET_PEERSTORE_watch (peerstore,
-                                   "transport",
-                                   &pr->pid,
-                                   GNUNET_PEERSTORE_HELLO_KEY,
-                                   &handle_hello_for_client,
-                                   pr);
+  pr->nc = GNUNET_PEERSTORE_hello_changed_notify (peerstore,
+                                                  GNUNET_NO,
+                                                  &handle_hello_for_client,
+                                                  NULL);
   GNUNET_SERVICE_client_continue (tc->client);
 }
 
@@ -11592,7 +11662,6 @@ run (void *cls,
     GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
   GST_my_private_key =
     GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg);
-  GST_my_hello = GNUNET_HELLO_builder_new (&GST_my_identity);
   if (NULL == GST_my_private_key)
   {
     GNUNET_log (
@@ -11607,6 +11676,7 @@ run (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "My identity is `%s'\n",
               GNUNET_i2s_full (&GST_my_identity));
+  GST_my_hello = GNUNET_HELLO_builder_new (&GST_my_identity);
   GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg);
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
   peerstore = GNUNET_PEERSTORE_connect (GST_cfg);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]