gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10035 - in gnunet/src: core fs hostlist include testing to


From: gnunet
Subject: [GNUnet-SVN] r10035 - in gnunet/src: core fs hostlist include testing topology
Date: Mon, 18 Jan 2010 10:00:05 +0100

Author: grothoff
Date: 2010-01-18 10:00:05 +0100 (Mon, 18 Jan 2010)
New Revision: 10035

Added:
   gnunet/src/core/core_api_peer_get_info.c
Modified:
   gnunet/src/core/Makefile.am
   gnunet/src/core/core.h
   gnunet/src/core/core_api.c
   gnunet/src/core/gnunet-service-core.c
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/hostlist/gnunet-daemon-hostlist.c
   gnunet/src/include/gnunet_core_service.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/testing/testing.c
   gnunet/src/topology/gnunet-daemon-topology.c
Log:
making peer_configure API cancellable

Modified: gnunet/src/core/Makefile.am
===================================================================
--- gnunet/src/core/Makefile.am 2010-01-18 07:58:14 UTC (rev 10034)
+++ gnunet/src/core/Makefile.am 2010-01-18 09:00:05 UTC (rev 10035)
@@ -14,7 +14,8 @@
   libgnunetcore.la
 
 libgnunetcore_la_SOURCES = \
-  core_api.c core.h
+  core_api.c core.h \
+  core_api_peer_get_info.c
 libgnunetcore_la_LIBADD = \
   $(top_builddir)/src/arm/libgnunetarm.la \
   $(top_builddir)/src/util/libgnunetutil.la \

Modified: gnunet/src/core/core.h
===================================================================
--- gnunet/src/core/core.h      2010-01-18 07:58:14 UTC (rev 10034)
+++ gnunet/src/core/core.h      2010-01-18 09:00:05 UTC (rev 10035)
@@ -45,11 +45,10 @@
 #define GNUNET_CORE_OPTION_NOTHING             0
 #define GNUNET_CORE_OPTION_SEND_CONNECT        1
 #define GNUNET_CORE_OPTION_SEND_DISCONNECT     2
-#define GNUNET_CORE_OPTION_SEND_BFC            4
-#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   8
-#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND   16
-#define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 32
-#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  64
+#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND   4
+#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND    8
+#define GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND 16
+#define GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND  32
 
 
 /**
@@ -159,7 +158,7 @@
  * Message sent to the core asking for configuration
  * information and possibly preference changes.
  */
-struct RequestConfigureMessage
+struct RequestInfoMessage
 {
   /**
    * Header with type GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE
@@ -200,7 +199,7 @@
 
 
 /**
- * Response from the core to a "RequestConfigureMessage"
+ * Response from the core to a "RequestInfoMessage"
  * providing traffic status information for a peer.
  */
 struct ConfigurationInfoMessage
@@ -239,7 +238,7 @@
    * Current traffic preference for the peer.
    * 0 if we have been disconnected.
    */
-  double preference;
+  uint64_t preference;
 
   /**
    * Identity of the receiver or sender.
@@ -250,31 +249,6 @@
 
 
 /**
- * Core asking a client to generate traffic for a particular
- * target.
- */
-struct SolicitTrafficMessage
-{
-  /**
-   * Header with type GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC
-   * or GNUNET_MESSAGE_TYPE_CORE_RECV_OK
-   */
-  struct GNUNET_MessageHeader header;
-
-  /**
-   * Number of bytes of traffic being solicited.
-   */
-  uint32_t solicit_size GNUNET_PACKED;
-
-  /**
-   * Identity of the receiver or sender.
-   */
-  struct GNUNET_PeerIdentity peer;
-
-};
-
-
-/**
  * Client asking core to transmit a particular message to
  * a particular target.  Does NOT have to be solicited.
  */

Modified: gnunet/src/core/core_api.c
===================================================================
--- gnunet/src/core/core_api.c  2010-01-18 07:58:14 UTC (rev 10034)
+++ gnunet/src/core/core_api.c  2010-01-18 09:00:05 UTC (rev 10035)
@@ -66,12 +66,6 @@
   GNUNET_CORE_ClientEventHandler disconnects;
 
   /**
-   * Function to call whenever we're asked to generate traffic
-   * (data provided to be transmitted back to the service).
-   */
-  GNUNET_CORE_BufferFillCallback bfc;
-
-  /**
    * Function to call whenever we receive an inbound message.
    */
   GNUNET_CORE_MessageCallback inbound_notify;
@@ -365,86 +359,6 @@
 
 
 /**
- * cls is a pointer to a 32 bit number followed by that
- * amount of data.  If possible, copy to buf and return
- * number of bytes copied.  Always free the buffer.
- */
-static size_t
-copy_and_free (void *cls, size_t size, void *buf)
-{
-  struct GNUNET_CORE_Handle *h = cls;
-  char *cbuf = h->solicit_buffer;
-  uint32_t have;
-
-  h->solicit_transmit_req = NULL;
-  h->solicit_buffer = NULL;
-  memcpy (&have, cbuf, sizeof (uint32_t));
-  if (have > size)
-    {
-      /* timeout / error case */
-      GNUNET_free (cbuf);
-      return 0;
-    }
-  memcpy (buf, cbuf + sizeof (uint32_t), have);
-  GNUNET_free (cbuf);
-  return have;
-}
-
-
-/**
- * Call bfc callback to solicit traffic for the given peer.
- *
- * @param h our handle to the core service
- * @param peer peer for which traffic is solicited
- * @param amount number of bytes that are being solicited
- */
-static void
-solicit_traffic (struct GNUNET_CORE_Handle *h,
-                 const struct GNUNET_PeerIdentity *peer, uint32_t amount)
-{
-  char buf[amount];
-  size_t have;
-  char *cbuf;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             "Core solicited %u bytes of traffic for `%s'!\n",
-             amount,
-             GNUNET_i2s (peer));
-  if (NULL != h->solicit_transmit_req)
-    {
-      /* more than one solicitation pending */
-      GNUNET_break (0);
-      return;
-    }
-  have = h->bfc (h->cls, peer, buf, amount);
-  if (have == 0)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                 "Can not help with traffic solicitation for `%s'!\n",
-                 GNUNET_i2s (peer));
-      return;
-    }
-  GNUNET_assert (have >= sizeof (struct GNUNET_MessageHeader));
-  cbuf = GNUNET_malloc (have + sizeof (uint32_t));
-  memcpy (cbuf, &have, sizeof (uint32_t));
-  memcpy (cbuf + sizeof (uint32_t), buf, have);
-  h->solicit_buffer = cbuf;
-  h->solicit_transmit_req 
-    = GNUNET_CORE_notify_transmit_ready (h,
-                                        0,
-                                        GNUNET_TIME_UNIT_SECONDS,
-                                        peer, have, &copy_and_free, h);
-  if (h->solicit_transmit_req == NULL)
-    {
-      /* this should not happen */
-      GNUNET_break (0);
-      GNUNET_free (cbuf);
-      h->solicit_buffer = NULL;
-    }
-}
-
-
-/**
  * Handler for most messages received from the core.
  *
  * @param cls our "struct GNUNET_CORE_Handle"
@@ -458,11 +372,9 @@
   const struct ConnectNotifyMessage *cnm;
   const struct NotifyTrafficMessage *ntm;
   const struct ConfigurationInfoMessage *cim;
-  const struct SolicitTrafficMessage *stm;
   const struct GNUNET_MessageHeader *em;
   uint16_t msize;
   uint16_t et;
-  uint32_t ss;
   const struct GNUNET_CORE_MessageHandler *mh;
 
   if (msg == NULL)
@@ -601,27 +513,6 @@
       GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH?
       trigger_next_request (h);
       break;
-    case GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC:
-      if (msize != sizeof (struct SolicitTrafficMessage))
-        {
-          GNUNET_break (0);
-          break;
-        }
-      stm = (const struct SolicitTrafficMessage *) msg;
-      if (NULL == h->bfc)
-        {
-          GNUNET_break (0);
-          break;
-        }
-      ss = ntohl (stm->solicit_size);
-      if ((ss > GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
-          (ss + sizeof (struct SendMessage) > GNUNET_SERVER_MAX_MESSAGE_SIZE))
-        {
-          GNUNET_break (0);
-          break;
-        }
-      solicit_traffic (h, &stm->peer, ss);
-      break;
     default:
       GNUNET_break (0);
       break;
@@ -766,8 +657,6 @@
     opt |= GNUNET_CORE_OPTION_SEND_CONNECT;
   if (h->disconnects != NULL)
     opt |= GNUNET_CORE_OPTION_SEND_DISCONNECT;
-  if (h->bfc != NULL)
-    opt |= GNUNET_CORE_OPTION_SEND_BFC;
   if (h->inbound_notify != NULL)
     {
       if (h->inbound_hdr_only)
@@ -807,7 +696,6 @@
  *        connected to the core service; note that timeout is only meaningful 
if init is not NULL
  * @param connects function to call on peer connect, can be NULL
  * @param disconnects function to call on peer disconnect / timeout, can be 
NULL
- * @param bfc function to call to fill up spare bandwidth, can be NULL
  * @param inbound_notify function to call for all inbound messages, can be NULL
  * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read 
the
  *                GNUNET_MessageHeader and hence we do not need to give it the 
full message;
@@ -828,7 +716,6 @@
                      GNUNET_CORE_StartupCallback init,
                      GNUNET_CORE_ClientEventHandler connects,
                      GNUNET_CORE_ClientEventHandler disconnects,
-                     GNUNET_CORE_BufferFillCallback bfc,
                      GNUNET_CORE_MessageCallback inbound_notify,
                      int inbound_hdr_only,
                      GNUNET_CORE_MessageCallback outbound_notify,
@@ -844,7 +731,6 @@
   h->init = init;
   h->connects = connects;
   h->disconnects = disconnects;
-  h->bfc = bfc;
   h->inbound_notify = inbound_notify;
   h->outbound_notify = outbound_notify;
   h->inbound_hdr_only = inbound_hdr_only;
@@ -899,108 +785,6 @@
 
 
 /**
- * Build the configure message.
- */
-static size_t
-produce_configure_message (void *cls, size_t size, void *buf)
-{
-  struct GNUNET_CORE_TransmitHandle *th = cls;
-  struct GNUNET_CORE_Handle *ch = th->ch;
-
-  if (buf == NULL)
-    {
-      /* communicate handle timeout/error! */
-      if (th->info != NULL)
-        th->info (th->info_cls, NULL, 0, 0, GNUNET_TIME_UNIT_ZERO, 0, 0.0);
-      if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
-        GNUNET_CORE_notify_transmit_ready_cancel (th);
-      if (ch->submitted == th)
-        ch->submitted = NULL;
-      trigger_next_request (ch);
-      return 0;
-    }
-  GNUNET_assert (size >= sizeof (struct RequestConfigureMessage));
-  memcpy (buf, &th[1], sizeof (struct RequestConfigureMessage));
-  if (th->prev == NULL)
-    ch->pending_head = th->next;
-  else
-    th->prev->next = th->next;
-  if (th->next == NULL)
-    ch->pending_tail = th->prev;
-  else
-    th->next->prev = th->prev;
-  return sizeof (struct RequestConfigureMessage);
-}
-
-
-/**
- * Obtain statistics and/or change preferences for the given peer.
- *
- * @param handle connection to core to use
- * @param peer identifies the peer
- * @param timeout after how long should we give up (and call "info" with NULL
- *                for "peer" to signal an error)?
- * @param bpm_out set to the current bandwidth limit (sending) for this peer,
- *                caller should set "bpm_out" to "-1" to avoid changing
- *                the current value; otherwise "bpm_out" will be lowered to
- *                the specified value; passing a pointer to "0" can be used to 
force
- *                us to disconnect from the peer; "bpm_out" might not increase
- *                as specified since the upper bound is generally
- *                determined by the other peer!
- * @param amount reserve N bytes for receiving, negative
- *                amounts can be used to undo a (recent) reservation;
- * @param preference increase incoming traffic share preference by this amount;
- *                in the absence of "amount" reservations, we use this
- *                preference value to assign proportional bandwidth shares
- *                to all connected peers
- * @param info function to call with the resulting configuration information
- * @param info_cls closure for info
- */
-void
-GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle,
-                            const struct GNUNET_PeerIdentity *peer,
-                            struct GNUNET_TIME_Relative timeout,
-                            unsigned int bpm_out,
-                            int amount,
-                            unsigned long long preference,
-                            GNUNET_CORE_PeerConfigurationInfoCallback info,
-                            void *info_cls)
-{
-  struct RequestConfigureMessage *rcm;
-  struct GNUNET_CORE_TransmitHandle *th;
-
-  th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle) +
-                      sizeof (struct RequestConfigureMessage));
-  /* append to list */
-  th->prev = handle->pending_tail;
-  if (handle->pending_tail == NULL)
-    handle->pending_head = th;
-  else
-    handle->pending_tail->next = th;
-  th->ch = handle;
-  th->get_message = &produce_configure_message;
-  th->get_message_cls = th;
-  th->info = info;
-  th->info_cls = info_cls;
-  th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-  th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
-                                                   timeout,
-                                                   &timeout_request, th);
-  th->msize = sizeof (struct RequestConfigureMessage);
-  rcm = (struct RequestConfigureMessage *) &th[1];
-  rcm->header.size = htons (sizeof (struct RequestConfigureMessage));
-  rcm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE);
-  rcm->reserved = htonl (0);
-  rcm->limit_outbound_bpm = htonl (bpm_out);
-  rcm->reserve_inbound = htonl (amount);
-  rcm->preference_change = GNUNET_htonll(preference);
-  rcm->peer = *peer;
-  if (handle->pending_head == th)
-    trigger_next_request (handle);
-}
-
-
-/**
  * Build the message requesting data transmission.
  */
 static size_t

Added: gnunet/src/core/core_api_peer_get_info.c
===================================================================
--- gnunet/src/core/core_api_peer_get_info.c                            (rev 0)
+++ gnunet/src/core/core_api_peer_get_info.c    2010-01-18 09:00:05 UTC (rev 
10035)
@@ -0,0 +1,177 @@
+/*
+     This file is part of GNUnet.
+     (C) 2009, 2010 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     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.
+*/
+
+/**
+ * @file core/core_api_peer_get_info.c
+ * @brief implementation of the peer_get_info functions 
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_core_service.h"
+#include "core.h"
+
+
+struct GNUNET_CORE_InformationRequestContext 
+{
+  
+  /**
+   * Our connection to the service.
+   */
+  struct GNUNET_CLIENT_Connection *client;
+
+  /**
+   * Function to call with the information.
+   */
+  GNUNET_CORE_PeerConfigurationInfoCallback info;
+
+  /**
+   * Closure for info.
+   */
+  void *info_cls;
+
+};
+
+
+/**
+ * Receive reply from core service with information about a peer.
+ *
+ * @param cls our 'struct  GNUNET_CORE_InformationRequestContext *'
+ * @param msg NULL on error (i.e. timeout)
+ */
+static void
+receive_info (void *cls,
+             const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_CORE_InformationRequestContext *irc = cls;
+  const struct ConfigurationInfoMessage *cim;
+
+  if (msg == NULL)
+    {
+      if (irc != NULL)
+       irc->info (irc->info_cls, 
+                  NULL, 0, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0, 0);     
+      GNUNET_CLIENT_disconnect (irc->client);
+      GNUNET_free (irc);
+      return;
+    }
+  if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO) ||
+       (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage)) )
+    {
+      GNUNET_break (0);
+      if (irc != NULL)
+       irc->info (irc->info_cls, 
+                  NULL, 0, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0, 0);     
+      GNUNET_CLIENT_disconnect (irc->client);
+      GNUNET_free (irc);
+      return;
+    }
+  cim = (const struct ConfigurationInfoMessage*) msg;
+  if (irc != NULL)
+    irc->info (irc->info_cls,
+              &cim->peer,
+              ntohl (cim->bpm_in),
+              ntohl (cim->bpm_out),
+              GNUNET_TIME_relative_ntoh (cim->latency),
+              ntohl (cim->reserved_amount),
+              GNUNET_ntohll (cim->preference));  
+  GNUNET_CLIENT_disconnect (irc->client);
+  GNUNET_free (irc);
+}
+
+
+/**
+ * Obtain statistics and/or change preferences for the given peer.
+ *
+ * @param sched scheduler to use
+ * @param cfg configuration to use
+ * @param peer identifies the peer
+ * @param timeout after how long should we give up (and call "info" with NULL
+ *                for "peer" to signal an error)?
+ * @param bpm_out set to the current bandwidth limit (sending) for this peer,
+ *                caller should set "bpm_out" to "-1" to avoid changing
+ *                the current value; otherwise "bpm_out" will be lowered to
+ *                the specified value; passing a pointer to "0" can be used to 
force
+ *                us to disconnect from the peer; "bpm_out" might not increase
+ *                as specified since the upper bound is generally
+ *                determined by the other peer!
+ * @param amount reserve N bytes for receiving, negative
+ *                amounts can be used to undo a (recent) reservation;
+ * @param preference increase incoming traffic share preference by this amount;
+ *                in the absence of "amount" reservations, we use this
+ *                preference value to assign proportional bandwidth shares
+ *                to all connected peers
+ * @param info function to call with the resulting configuration information
+ * @param info_cls closure for info
+ * @return NULL on error
+ */
+struct GNUNET_CORE_InformationRequestContext *
+GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched,
+                          const struct GNUNET_CONFIGURATION_Handle *cfg,
+                          const struct GNUNET_PeerIdentity *peer,
+                          struct GNUNET_TIME_Relative timeout,
+                          uint32_t bpm_out,
+                          int32_t amount,
+                          uint64_t preference,
+                          GNUNET_CORE_PeerConfigurationInfoCallback info,
+                          void *info_cls)
+{
+  struct GNUNET_CORE_InformationRequestContext *irc;
+  struct RequestInfoMessage rim;
+  struct GNUNET_CLIENT_Connection *client;
+  int retry;
+
+  client = GNUNET_CLIENT_connect (sched, "core", cfg);
+  if (client == NULL)
+    return NULL;
+  irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
+  irc->client = client;
+  irc->info = info;
+  irc->info_cls = info_cls;
+  rim.header.size = htons (sizeof (struct RequestInfoMessage));
+  rim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
+  rim.reserved = htonl (0);
+  rim.limit_outbound_bpm = htonl (bpm_out);
+  rim.reserve_inbound = htonl (amount);
+  rim.preference_change = GNUNET_htonll(preference);
+  rim.peer = *peer;
+  retry = ( (amount == 0) && (preference == 0) ) ? GNUNET_YES : GNUNET_NO;
+  GNUNET_assert (GNUNET_OK == GNUNET_CLIENT_transmit_and_get_response (client,
+                                                                      
&rim.header,
+                                                                      timeout,
+                                                                      retry,
+                                                                      
&receive_info,
+                                                                      irc));  
+  return irc;
+}
+
+
+/**
+ * Cancel request for getting information about a peer.
+ *
+ * @param irc context returned by the original GNUNET_CORE_peer_get_info call
+ */
+void
+GNUNET_CORE_peer_get_info_cancel (struct GNUNET_CORE_InformationRequestContext 
*irc)
+{
+  GNUNET_CLIENT_disconnect (irc->client);
+  GNUNET_free (irc);
+}
+
+/* end of core_api_peer_get_info.c */

Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c       2010-01-18 07:58:14 UTC (rev 
10034)
+++ gnunet/src/core/gnunet-service-core.c       2010-01-18 09:00:05 UTC (rev 
10035)
@@ -1051,14 +1051,14 @@
 
 
 /**
- * Handle REQUEST_CONFIGURE request.
+ * Handle REQUEST_INFO request.
  */
 static void
-handle_client_request_configure (void *cls,
+handle_client_request_info (void *cls,
                                  struct GNUNET_SERVER_Client *client,
                                  const struct GNUNET_MessageHeader *message)
 {
-  const struct RequestConfigureMessage *rcm;
+  const struct RequestInfoMessage *rcm;
   struct Neighbour *n;
   struct ConfigurationInfoMessage cim;
   struct Client *c;
@@ -1067,9 +1067,9 @@
 
 #if DEBUG_CORE_CLIENT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core service receives `%s' request.\n", "CONFIGURE");
+              "Core service receives `%s' request.\n", "REQUEST_INFO");
 #endif
-  rcm = (const struct RequestConfigureMessage *) message;
+  rcm = (const struct RequestInfoMessage *) message;
   n = find_neighbour (&rcm->peer);
   memset (&cim, 0, sizeof (cim));
   if ((n != NULL) && (n->status == PEER_STATE_KEY_CONFIRMED))
@@ -1991,9 +1991,9 @@
 static struct GNUNET_SERVER_MessageHandler handlers[] = {
   {&handle_client_init, NULL,
    GNUNET_MESSAGE_TYPE_CORE_INIT, 0},
-  {&handle_client_request_configure, NULL,
-   GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE,
-   sizeof (struct RequestConfigureMessage)},
+  {&handle_client_request_info, NULL,
+   GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO,
+   sizeof (struct RequestInfoMessage)},
   {&handle_client_send, NULL,
    GNUNET_MESSAGE_TYPE_CORE_SEND, 0},
   {NULL, NULL, 0, 0}

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2010-01-18 07:58:14 UTC (rev 10034)
+++ gnunet/src/fs/gnunet-service-fs.c   2010-01-18 09:00:05 UTC (rev 10035)
@@ -417,6 +417,11 @@
   struct GNUNET_CONTAINER_BloomFilter *bf;
 
   /**
+   * Context of our GNUNET_CORE_peer_get_info call.
+   */
+  struct GNUNET_CORE_InformationRequestContext *irc;
+
+  /**
    * Replies that we have received but were unable to forward yet
    * (typically non-null only if we have a pending transmission
    * request with the client or the respective peer).
@@ -1787,6 +1792,7 @@
   uint16_t size;
   struct GNUNET_TIME_Relative maxdelay;
 
+  pr->irc = NULL;
   GNUNET_assert (peer != NULL);
   if ( (amount != DBLOCK_SIZE) ||
        (pr->cth != NULL) )
@@ -1865,17 +1871,15 @@
       return;
     }
   /* (2) reserve reply bandwidth */
-  // FIXME: need a way to cancel; this
-  // async operation is problematic (segv-problematic)
-  // if "pr" is destroyed while it happens!
-  GNUNET_CORE_peer_configure (core,
-                             &psc.target,
-                             GNUNET_CONSTANTS_SERVICE_TIMEOUT, 
-                             -1,
-                             DBLOCK_SIZE, // FIXME: make dependent on type?
-                             0,
-                             &target_reservation_cb,
-                             pr);
+  GNUNET_assert (NULL == pr->irc);
+  pr->irc = GNUNET_CORE_peer_get_info (sched, cfg,
+                                      &psc.target,
+                                      GNUNET_CONSTANTS_SERVICE_TIMEOUT, 
+                                      -1,
+                                      DBLOCK_SIZE, // FIXME: make dependent on 
type?
+                                      0,
+                                      &target_reservation_cb,
+                                      pr);
 }
 
 
@@ -2216,6 +2220,11 @@
                                        pr);
   // FIXME: not sure how this can work (efficiently)
   // also, what does the return value mean?
+  if (pr->irc != NULL)
+    {
+      GNUNET_CORE_peer_get_info_cancel (pr->irc);
+      pr->irc = NULL;
+    }
   if (pr->client == NULL)
     {
       GNUNET_CONTAINER_heap_remove_node (requests_by_expiration,
@@ -2914,10 +2923,10 @@
   if (preference < QUERY_BANDWIDTH_VALUE)
     preference = QUERY_BANDWIDTH_VALUE;
   // FIXME: also reserve bandwidth for reply?
-  GNUNET_CORE_peer_configure (core,
-                             other,
-                             GNUNET_TIME_UNIT_FOREVER_REL,
-                             0, 0, preference, NULL, NULL);
+  (void) GNUNET_CORE_peer_get_info (sched, cfg,
+                                   other,
+                                   GNUNET_TIME_UNIT_FOREVER_REL,
+                                   0, 0, preference, NULL, NULL);
   if (0 != (pgc->policy & ROUTING_POLICY_ANSWER))
     pgc->drq = queue_ds_request (BASIC_DATASTORE_REQUEST_DELAY,
                                 &ds_get_request,
@@ -3318,7 +3327,6 @@
                              NULL,
                              &peer_connect_handler,
                              &peer_disconnect_handler,
-                             NULL, 
                              NULL, GNUNET_NO,
                              NULL, GNUNET_NO,
                              p2p_handlers);

Modified: gnunet/src/hostlist/gnunet-daemon-hostlist.c
===================================================================
--- gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-01-18 07:58:14 UTC 
(rev 10034)
+++ gnunet/src/hostlist/gnunet-daemon-hostlist.c        2010-01-18 09:00:05 UTC 
(rev 10035)
@@ -192,7 +192,6 @@
                              NULL,
                              &core_init,
                              ch, dh,
-                             NULL,
                              NULL, GNUNET_NO,
                              NULL, GNUNET_NO,
                              handlers);

Modified: gnunet/src/include/gnunet_core_service.h
===================================================================
--- gnunet/src/include/gnunet_core_service.h    2010-01-18 07:58:14 UTC (rev 
10034)
+++ gnunet/src/include/gnunet_core_service.h    2010-01-18 09:00:05 UTC (rev 
10035)
@@ -63,25 +63,6 @@
 
 
 /**
- * Type of a send callback to fill up buffers.
- *
- * @param receiver the receiver of the message
- * @param position is the reference to the
- *        first unused position in the buffer where GNUnet is building
- *        the message
- * @param padding is the number of bytes left in that buffer.
- * @return the number of bytes written to
- *   that buffer (must be a positive number).
- */
-typedef unsigned int
-  (*GNUNET_CORE_BufferFillCallback) (void *cls,
-                                     const struct GNUNET_PeerIdentity *
-                                     receiver,
-                                     void *position, 
-                                    size_t padding);
-
-
-/**
  * Functions with this signature are called whenever a message is
  * received or transmitted.
  *
@@ -159,7 +140,6 @@
  *        connected to the core service; note that timeout is only meaningful 
if init is not NULL
  * @param connects function to call on peer connect, can be NULL
  * @param disconnects function to call on peer disconnect / timeout, can be 
NULL
- * @param bfc function to call to fill up spare bandwidth, can be NULL
  * @param inbound_notify function to call for all inbound messages, can be NULL
  * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read 
the
  *                GNUNET_MessageHeader and hence we do not need to give it the 
full message;
@@ -180,7 +160,6 @@
                      GNUNET_CORE_StartupCallback init,
                      GNUNET_CORE_ClientEventHandler connects,
                      GNUNET_CORE_ClientEventHandler disconnects,
-                     GNUNET_CORE_BufferFillCallback bfc,
                      GNUNET_CORE_MessageCallback inbound_notify,
                      int inbound_hdr_only,
                      GNUNET_CORE_MessageCallback outbound_notify,
@@ -219,10 +198,17 @@
                                                 unsigned long long preference);
 
 
+
 /**
+ * Context that can be used to cancel a peer information request.
+ */
+struct GNUNET_CORE_InformationRequestContext;
+
+/**
  * Obtain statistics and/or change preferences for the given peer.
  *
- * @param handle connection to core to use
+ * @param sched scheduler to use
+ * @param cfg configuration to use
  * @param peer identifies the peer
  * @param timeout after how long should we give up (and call "info" with NULL
  *                for "peer" to signal an error)?
@@ -241,17 +227,27 @@
  *                to all connected peers
  * @param info function to call with the resulting configuration information
  * @param info_cls closure for info
+ * @return NULL on error
  */
-// FIXME: should return handle for cancellation!
+struct GNUNET_CORE_InformationRequestContext *
+GNUNET_CORE_peer_get_info (struct GNUNET_SCHEDULER_Handle *sched,
+                          const struct GNUNET_CONFIGURATION_Handle *cfg,
+                          const struct GNUNET_PeerIdentity *peer,
+                          struct GNUNET_TIME_Relative timeout,
+                          uint32_t bpm_out,
+                          int32_t amount,
+                          uint64_t preference,
+                          GNUNET_CORE_PeerConfigurationInfoCallback info,
+                          void *info_cls);
+
+
+/**
+ * Cancel request for getting information about a peer.
+ *
+ * @param irc context returned by the original GNUNET_CORE_peer_get_info call
+ */
 void
-GNUNET_CORE_peer_configure (struct GNUNET_CORE_Handle *handle,
-                            const struct GNUNET_PeerIdentity *peer,
-                            struct GNUNET_TIME_Relative timeout,
-                            unsigned int bpm_out,
-                            int amount,
-                            unsigned long long preference,
-                            GNUNET_CORE_PeerConfigurationInfoCallback info,
-                            void *info_cls);
+GNUNET_CORE_peer_get_info_cancel (struct GNUNET_CORE_InformationRequestContext 
*irc);
 
 
 /**

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2010-01-18 07:58:14 UTC (rev 
10034)
+++ gnunet/src/include/gnunet_protocols.h       2010-01-18 09:00:05 UTC (rev 
10035)
@@ -276,7 +276,7 @@
 /**
  * Request from client to "configure" P2P connection.
  */
-#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONFIGURE 70
+#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO 70
 
 /**
  * Response from server about (possibly updated) P2P
@@ -285,18 +285,11 @@
 #define GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO 71
 
 /**
- * Solicitation from server for transmission (may have
- * been requested or also be transmitted without
- * client's request).
+ * Request from client with message to transmit.
  */
-#define GNUNET_MESSAGE_TYPE_CORE_SOLICIT_TRAFFIC 72
+#define GNUNET_MESSAGE_TYPE_CORE_SEND 72
 
-/**
- * Response from client with message to transmit.
- */
-#define GNUNET_MESSAGE_TYPE_CORE_SEND 73
 
-
 /**
  * Session key exchange between peers.
  */

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2010-01-18 07:58:14 UTC (rev 10034)
+++ gnunet/src/testing/testing.c        2010-01-18 09:00:05 UTC (rev 10035)
@@ -434,7 +434,7 @@
                                       ARM_START_WAIT,
                                       d,
                                       &testing_init,
-                                      NULL, NULL, NULL, 
+                                      NULL, NULL, 
                                       NULL, GNUNET_NO,
                                       NULL, GNUNET_NO,
                                       no_handlers);     

Modified: gnunet/src/topology/gnunet-daemon-topology.c
===================================================================
--- gnunet/src/topology/gnunet-daemon-topology.c        2010-01-18 07:58:14 UTC 
(rev 10034)
+++ gnunet/src/topology/gnunet-daemon-topology.c        2010-01-18 09:00:05 UTC 
(rev 10035)
@@ -238,14 +238,15 @@
 static void
 force_disconnect (const struct GNUNET_PeerIdentity *peer)
 {
-  GNUNET_CORE_peer_configure (handle,
-                             peer,
-                             GNUNET_TIME_UNIT_FOREVER_REL,
-                             0,
-                             0,
-                             0,
-                             NULL,
-                             NULL);
+  // FIXME: do something with return value!
+  GNUNET_CORE_peer_get_info (sched, cfg,
+                            peer,
+                            GNUNET_TIME_UNIT_FOREVER_REL,
+                            0,
+                            0,
+                            0,
+                            NULL,
+                            NULL);
 }
 
 
@@ -1057,6 +1058,7 @@
 }
 
 
+// FIXME: this no longer works (no solicitation!)
 /**
  * Function to fill send buffer with HELLO.
  *
@@ -1069,7 +1071,7 @@
  * @return the number of bytes written to
  *   that buffer (must be a positive number).
  */
-static unsigned int
+/* static */ unsigned int
 hello_advertising (void *cls,
                   const struct GNUNET_PeerIdentity *
                   receiver,
@@ -1275,7 +1277,6 @@
                                &core_init,
                                &connect_notify,
                                &disconnect_notify,
-                               &hello_advertising,
                                NULL, GNUNET_NO,
                                NULL, GNUNET_NO,
                                handlers);





reply via email to

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