gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated: more work on 5385


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: more work on 5385
Date: Sat, 26 Jan 2019 21:18:11 +0100

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

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 8f884f001 more work on 5385
8f884f001 is described below

commit 8f884f001a70fee622fff0c0ac8c38a0634df789
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Jan 26 21:18:06 2019 +0100

    more work on 5385
---
 src/cadet/cadet_api_get_channel.c  |  37 ++++++----
 src/cadet/cadet_api_get_peer.c     | 140 +++++++++++++++++++------------------
 src/cadet/cadet_api_list_peers.c   | 125 ++++++++++++++++++++-------------
 src/cadet/cadet_api_list_tunnels.c |  39 ++++++++---
 4 files changed, 202 insertions(+), 139 deletions(-)

diff --git a/src/cadet/cadet_api_get_channel.c 
b/src/cadet/cadet_api_get_channel.c
index c36766a3f..cd90f5b78 100644
--- a/src/cadet/cadet_api_get_channel.c
+++ b/src/cadet/cadet_api_get_channel.c
@@ -48,28 +48,40 @@ struct GNUNET_CADET_ChannelMonitor
    */
   void *channel_cb_cls;
 
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+  struct GNUNET_MQ_Handle *mq;
+  
+  struct GNUNET_PeerIdentity peer;
+  
+  uint32_t /* UGH */ channel_number;
+
 };
 
 
-/**
- * Send message of @a type to CADET service of @a h
- *
- * @param h handle to CADET service
- * @param type message type of trivial information request to send
- */
+
 static void
-send_info_request (struct GNUNET_CADET_Handle *h,
-                   uint16_t type)
+reconnect (void *cls)
 {
+  struct GNUNET_CADET_ChannelMonitor *cm = cls;
+  struct GNUNET_MQ_MessageHandler *handlers[] = {
+  }
   struct GNUNET_MessageHeader *msg;
   struct GNUNET_MQ_Envelope *env;
 
+  cm->mq = GNUNET_CLIENT_connect (cm->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 cm);
+                                
   env = GNUNET_MQ_msg (msg,
                        type);
-  GNUNET_MQ_send (h->mq,
+  GNUNET_MQ_send (cm->mq,
                   env);
 }
 
+
 /**
  * Request information about a specific channel of the running cadet peer.
  *
@@ -82,7 +94,7 @@ send_info_request (struct GNUNET_CADET_Handle *h,
  * @param callback_cls Closure for @c callback.
  */
 struct GNUNET_CADET_ChannelMonitor *
-GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h,
+GNUNET_CADET_get_channel (const struct GNUNET_CONFIGURATION_Handle *cfg,
                           struct GNUNET_PeerIdentity *peer,
                           uint32_t /* UGH */ channel_number,
                           GNUNET_CADET_ChannelCB callback,
@@ -92,5 +104,6 @@ GNUNET_CADET_get_channel (struct GNUNET_CADET_Handle *h,
 
 
 void *
-GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm);
-
+GNUNET_CADET_get_channel_cancel (struct GNUNET_CADET_ChannelMonitor *cm)
+{
+}
diff --git a/src/cadet/cadet_api_get_peer.c b/src/cadet/cadet_api_get_peer.c
index b29b66e1c..c7d6e324b 100644
--- a/src/cadet/cadet_api_get_peer.c
+++ b/src/cadet/cadet_api_get_peer.c
@@ -31,9 +31,8 @@
 #include "cadet_protocol.h"
 
 
-
 /**
- * Ugly legacy hack.
+ * 
  */
 struct GNUNET_CADET_GetPeer
 {
@@ -48,34 +47,18 @@ struct GNUNET_CADET_GetPeer
    */
   void *peer_cb_cls;
 
+  struct GNUNET_PeerIdentity id;
 
-};
-
-
-/**
- * Send message of @a type to CADET service of @a h
- *
- * @param h handle to CADET service
- * @param type message type of trivial information request to send
- */
-static void
-send_info_request (struct GNUNET_CADET_Handle *h,
-                   uint16_t type)
-{
-  struct GNUNET_MessageHeader *msg;
-  struct GNUNET_MQ_Envelope *env;
+  struct GNUNET_MQ_Handle *mq;
 
-  env = GNUNET_MQ_msg (msg,
-                       type);
-  GNUNET_MQ_send (h->mq,
-                  env);
-}
+  const struct GNUNET_CONFIGURATION_Handle *cfg;
+};
 
 
 /**
  * Check that message received from CADET service is well-formed.
  *
- * @param cls the `struct GNUNET_CADET_Handle`
+ * @param cls unused
  * @param message the message we got
  * @return #GNUNET_OK if the message is well-formed,
  *         #GNUNET_SYSERR otherwise
@@ -106,27 +89,25 @@ check_get_peer (void *cls,
 /**
  * Process a local peer info reply, pass info to the user.
  *
- * @param cls Closure (Cadet handle).
+ * @param cls Closure 
  * @param message Message itself.
  */
 static void
 handle_get_peer (void *cls,
                  const struct GNUNET_CADET_LocalInfoPeer *message)
 {
-  struct GNUNET_CADET_Handle *h = cls;
+  struct GNUNET_CADET_GetPeer *gp = cls;
   const struct GNUNET_PeerIdentity *paths_array;
   unsigned int paths;
   unsigned int path_length;
   int neighbor;
   unsigned int peers;
 
-  if (NULL == h->info_cb.peer_cb)
-    return;
   
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-    "number of paths %u\n",
-    ntohs (message->paths));
-  
+        "number of paths %u\n",
+        ntohs (message->paths));
+
   paths = ntohs (message->paths);
   paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
   peers = (ntohs (message->header.size) - sizeof (*message))
@@ -151,25 +132,50 @@ handle_get_peer (void *cls,
 
   /* Call Callback with tunnel info. */
   paths_array = (const struct GNUNET_PeerIdentity *) &message[1];
-  h->info_cb.peer_cb (h->info_cls,
-                      &message->destination,
-                      (int) ntohs (message->tunnel),
-                      neighbor,
-                      paths,
-                      paths_array,
-                      (int) ntohs (message->offset),
-                      (int) ntohs (message->finished_with_paths));
+  gp->peer_cb (gp->peer_cb_cls,
+                &message->destination,
+                (int) ntohs (message->tunnel),
+                neighbor,
+                paths,
+                paths_array,
+                (int) ntohs (message->offset),
+                (int) ntohs (message->finished_with_paths));
+  GNUNET_CADET_get_peer_cancel (gp);
 }
 
 
+static void
+reconnect (void *cls)
+{
+  struct GNUNET_CADET_GetPeer *gp = cls;
+  struct GNUNET_MQ_MessageHandler *handlers[] = {
+    GNUNET_MQ_hd_var_size (get_peer,
+                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
+                           struct GNUNET_CADET_LocalInfoPeer,
+                           h),
+    GNUNET_MQ_handler_end ()
+  }
+  struct GNUNET_CADET_LocalInfo *msg;
+  struct GNUNET_MQ_Envelope *env;
+
+  gp->mq = GNUNET_CLIENT_connect (gp->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 gp);
+  if (NULL == gp->mq)
+    return;
+  env = GNUNET_MQ_msg (msg,
+                       GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
+  msg->peer = gp->id;
+  GNUNET_MQ_send (lt->mq,
+                  env);
+}
 
 
 /**
  * Request information about a peer known to the running cadet peer.
  * The callback will be called for the tunnel once.
- * Only one info request (of any kind) can be active at once.
- *
- * WARNING: unstable API, likely to change in the future!
  *
  * @param h Handle to the cadet peer.
  * @param id Peer whose tunnel to examine.
@@ -177,43 +183,43 @@ handle_get_peer (void *cls,
  * @param callback_cls Closure for @c callback.
  * @return #GNUNET_OK / #GNUNET_SYSERR
  */
-int
+struct GNUNET_CADET_GetPeer *
 GNUNET_CADET_get_peer (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                        const struct GNUNET_PeerIdentity *id,
+                      const struct GNUNET_PeerIdentity *id,
                        GNUNET_CADET_PeerCB callback,
                        void *callback_cls)
 {
-  struct GNUNET_CADET_LocalInfo *msg;
-  struct GNUNET_MQ_Envelope *env;
-  struct GNUNET_MQ_MessageHandler handlers[] = {
+  struct GNUNET_CADET_GetPeer *gp;
 
-    GNUNET_MQ_hd_var_size (get_peers,
-                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
-                           struct GNUNET_MessageHeader,
-                           h),
-    GNUNET_MQ_hd_var_size (get_peer,
-                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER,
-                           struct GNUNET_CADET_LocalInfoPeer,
-                           h),
-    GNUNET_MQ_handler_end ()
-
-  
-  if (NULL != h->info_cb.peer_cb)
+  if (NULL == callback)
   {
     GNUNET_break (0);
-    return GNUNET_SYSERR;
+    return NULL;
   }
-  env = GNUNET_MQ_msg (msg,
-                       GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEER);
-  msg->peer = *id;
-  GNUNET_MQ_send (h->mq,
-                  env);
-  h->info_cb.peer_cb = callback;
-  h->info_cls = callback_cls;
-  return GNUNET_OK;
+  gp = GNUNET_new (struct GNUNET_CADET_GetPeer);
+  gp->peer_cb = callback;
+  gp->peer_cb_cls = callback_cls;
+  gp->cfg = cfg;
+  gp->id = *id;
+  reconnect (gp);
+  if (NULL == gp->mq)
+  {
+    GNUNET_free (gp);
+    return NULL;
+  }
+  return gp;
 }
 
 
 
+void *
+GNUNET_CADET_get_peer_cancel (struct GNUNET_CADET_GetPeer *gp)
+{
+  void *ret = gp->peer_cb_cls;
+  
+  GNUNET_MQ_disconnect (gp->mq);
+  GNUNET_free (gp);
+  return ret;
+}
 
 
diff --git a/src/cadet/cadet_api_list_peers.c b/src/cadet/cadet_api_list_peers.c
index 4bdc8b961..f6563a290 100644
--- a/src/cadet/cadet_api_list_peers.c
+++ b/src/cadet/cadet_api_list_peers.c
@@ -70,55 +70,6 @@ send_info_request (struct GNUNET_CADET_Handle *h,
 }
 
 
-/**
- * Request information about peers known to the running cadet service.
- * The callback will be called for every peer known to the service.
- * Only one info request (of any kind) can be active at once.
- *
- * WARNING: unstable API, likely to change in the future!
- *
- * @param h Handle to the cadet peer.
- * @param callback Function to call with the requested data.
- * @param callback_cls Closure for @c callback.
- * @return #GNUNET_OK / #GNUNET_SYSERR
- */
-int
-GNUNET_CADET_list_peers (struct GNUNET_CADET_Handle *h,
-                        GNUNET_CADET_PeersCB callback,
-                        void *callback_cls)
-{
-  if (NULL != h->info_cb.peers_cb)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  send_info_request (h,
-                     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
-  h->info_cb.peers_cb = callback;
-  h->info_cls = callback_cls;
-  return GNUNET_OK;
-}
-
-
-/**
- * Cancel a peer info request. The callback will not be called (anymore).
- *
- * WARNING: unstable API, likely to change in the future!
- *
- * @param h Cadet handle.
- * @return Closure given to GNUNET_CADET_get_peers().
- */
-void *
-GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_Handle *h)
-{
-  void *cls = h->info_cls;
-
-  h->info_cb.peers_cb = NULL;
-  h->info_cls = NULL;
-  return cls;
-}
-
-
 /**
  * Check that message received from CADET service is well-formed.
  *
@@ -174,6 +125,82 @@ handle_get_peers (void *cls,
 }
 
 
+static void
+reconnect (void *cls)
+{
+  struct GNUNET_CADET_ListTunnels *lt = cls;
+  struct GNUNET_MQ_MessageHandler *handlers[] = {
+     GNUNET_MQ_hd_var_size (get_peers,
+                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS,
+                           struct GNUNET_MessageHeader,
+                           h),
+    GNUNET_MQ_handler_end ()
+  }
+  struct GNUNET_MessageHeader *msg;
+  struct GNUNET_MQ_Envelope *env;
+
+  cm->mq = GNUNET_CLIENT_connect (cm->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 cm);
+                                
+  env = GNUNET_MQ_msg (msg,
+                       type);
+  GNUNET_MQ_send (cm->mq,
+                  env);
+}
+
+
+/**
+ * Request information about peers known to the running cadet service.
+ * The callback will be called for every peer known to the service.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the cadet peer.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+struct GNUNET_CADET_PeersLister *
+GNUNET_CADET_list_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
+                        GNUNET_CADET_PeersCB callback,
+                        void *callback_cls)
+{
+  if (NULL != h->info_cb.peers_cb)
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  send_info_request (h,
+                     GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS);
+  h->info_cb.peers_cb = callback;
+  h->info_cls = callback_cls;
+  return GNUNET_OK;
+}
+
+
+/**
+ * Cancel a peer info request. The callback will not be called (anymore).
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Cadet handle.
+ * @return Closure given to GNUNET_CADET_get_peers().
+ */
+void *
+GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
+{
+  void *cls = h->info_cls;
+
+  h->info_cb.peers_cb = NULL;
+  h->info_cls = NULL;
+  return cls;
+}
+
+
 
 
 
diff --git a/src/cadet/cadet_api_list_tunnels.c 
b/src/cadet/cadet_api_list_tunnels.c
index da5f85aa0..96343bf4d 100644
--- a/src/cadet/cadet_api_list_tunnels.c
+++ b/src/cadet/cadet_api_list_tunnels.c
@@ -127,6 +127,33 @@ handle_get_tunnels (void *cls,
 }
 
 
+static void
+reconnect (void *cls)
+{
+  struct GNUNET_CADET_ListTunnels *lt = cls;
+  struct GNUNET_MQ_MessageHandler *handlers[] = {
+    GNUNET_MQ_hd_var_size (get_tunnels,
+                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
+                           struct GNUNET_MessageHeader,
+                           h),
+    GNUNET_MQ_handler_end ()
+  }
+  struct GNUNET_MessageHeader *msg;
+  struct GNUNET_MQ_Envelope *env;
+
+  cm->mq = GNUNET_CLIENT_connect (cm->cfg,
+                                 "cadet",
+                                 handlers,
+                                 &error_handler,
+                                 cm);
+                                
+  env = GNUNET_MQ_msg (msg,
+                       type);
+  GNUNET_MQ_send (cm->mq,
+                  env);
+}
+
+
 /**
  * Request information about tunnels of the running cadet peer.
  * The callback will be called for every tunnel of the service.
@@ -139,22 +166,12 @@ handle_get_tunnels (void *cls,
  * @param callback_cls Closure for @c callback.
  * @return #GNUNET_OK / #GNUNET_SYSERR
  */
-int
+struct GNUNET_CADET_ListTunnels *
 GNUNET_CADET_list_tunnels (const struct GNUNET_CONFIGURATION_Handle *cfg,
                           GNUNET_CADET_TunnelsCB callback,
                           void *callback_cls)
 {
 
-      GNUNET_MQ_hd_var_size (get_tunnels,
-                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNELS,
-                           struct GNUNET_MessageHeader,
-                           h),
-    GNUNET_MQ_hd_var_size (get_tunnel,
-                           GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_TUNNEL,
-                           struct GNUNET_CADET_LocalInfoTunnel,
-                           h),
-    GNUNET_MQ_handler_end ()
-
   if (NULL != h->info_cb.tunnels_cb)
   {
     GNUNET_break (0);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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