gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r10124 - in gnunet/src: core include topology


From: gnunet
Subject: [GNUnet-SVN] r10124 - in gnunet/src: core include topology
Date: Fri, 22 Jan 2010 18:27:16 +0100

Author: grothoff
Date: 2010-01-22 18:27:16 +0100 (Fri, 22 Jan 2010)
New Revision: 10124

Modified:
   gnunet/src/core/core_api_peer_request.c
   gnunet/src/core/gnunet-service-core.c
   gnunet/src/include/gnunet_core_service.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_transport_service.h
   gnunet/src/topology/gnunet-daemon-topology.c
Log:
use new APIs for connect/disconnect

Modified: gnunet/src/core/core_api_peer_request.c
===================================================================
--- gnunet/src/core/core_api_peer_request.c     2010-01-22 17:15:29 UTC (rev 
10123)
+++ gnunet/src/core/core_api_peer_request.c     2010-01-22 17:27:16 UTC (rev 
10124)
@@ -29,8 +29,8 @@
 
 
 /**
- * Handle for a request to the core to connect or disconnect
- * from a particular peer.  Can be used to cancel the request
+ * Handle for a request to the core to connect to
+ * a particular peer.  Can be used to cancel the request
  * (before the 'cont'inuation is called).
  */
 struct GNUNET_CORE_PeerRequestHandle
@@ -57,7 +57,7 @@
   void *cont_cls;
 
   /**
-   * Identity of the peer to connect/disconnect.
+   * Identity of the peer to connect to.
    */
   struct GNUNET_PeerIdentity peer;
        
@@ -160,65 +160,13 @@
 
 
 /**
- * Request that the core should try to disconnect from a particular
- * peer.  Once the request has been transmitted to the core, the
- * continuation function will be called.  Note that this does NOT mean
- * that a connection was successfully cut -- it only means that the
- * core will now try.  Typically this will work pretty much
- * immediately, but it is at least in theory also possible that a
- * reconnect is also triggered rather quickly.  Successful creation
- * and destruction of connections will be signalled to the 'connects'
- * and 'disconnects' callback arguments of 'GNUNET_CORE_connect' only.
- * If the core service does not respond to our connection attempt
- * within the given time frame, 'cont' will be called with the TIMEOUT
- * reason code.
+ * Cancel a pending request to connect to a particular peer.  Must not
+ * be called after the 'cont' function was invoked.
  *
- * @param sched scheduler to use
- * @param cfg configuration to use
- * @param timeout how long to try to talk to core
- * @param cont function to call once the request has been completed (or timed 
out)
- * @param cont_cls closure for cont
- * @return NULL on error (cont will not be called), otherwise handle for 
cancellation
- */
-struct GNUNET_CORE_PeerRequestHandle *
-GNUNET_CORE_peer_request_disconnect (struct GNUNET_SCHEDULER_Handle *sched,
-                                    const struct GNUNET_CONFIGURATION_Handle 
*cfg,
-                                    struct GNUNET_TIME_Relative timeout,
-                                    const struct GNUNET_PeerIdentity * peer,
-                                    GNUNET_SCHEDULER_Task cont,
-                                    void *cont_cls)
-{
-  struct GNUNET_CORE_PeerRequestHandle *ret;
-  struct GNUNET_CLIENT_Connection *client;
-  
-  client = GNUNET_CLIENT_connect (sched, "core", cfg);
-  if (client == NULL)
-    return NULL;
-  ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
-  ret->client = client;
-  ret->sched = sched;
-  ret->cont = cont;
-  ret->cont_cls = cont_cls;
-  ret->peer = *peer;
-  ret->type = GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT;
-  GNUNET_CLIENT_notify_transmit_ready (client,
-                                      sizeof (struct ConnectMessage),
-                                      timeout,
-                                      GNUNET_YES,
-                                      &send_request,
-                                      ret);
-  return ret;
-}
-
-
-/**
- * Cancel a pending request to connect or disconnect from/to a particular
- * peer.   Must not be called after the 'cont' function was invoked.
- *
  * @param req request handle that was returned for the original request
  */
 void
-GNUNET_CORE_peer_request_cancel (struct GNUNET_CORE_PeerRequestHandle *req)
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle 
*req)
 {
   GNUNET_CLIENT_disconnect (req->client);
   GNUNET_free (req);

Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c       2010-01-22 17:15:29 UTC (rev 
10123)
+++ gnunet/src/core/gnunet-service-core.c       2010-01-22 17:27:16 UTC (rev 
10124)
@@ -1862,30 +1862,6 @@
 
 
 /**
- * Handle CORE_REQUEST_DISCONNECT request.
- *
- * @param cls unused
- * @param client the client issuing the request
- * @param message the "struct ConnectMessage"
- */
-static void
-handle_client_request_disconnect (void *cls,
-                                 struct GNUNET_SERVER_Client *client,
-                                 const struct GNUNET_MessageHeader *message)
-{
-  const struct ConnectMessage *cm = (const struct ConnectMessage*) message;
-  struct Neighbour *n;
-
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-  n = find_neighbour (&cm->peer);
-  if (n == NULL)
-    return; /* done */
-  /* FIXME: implement disconnect! */
-}
-
-
-
-/**
  * List of handlers for the messages understood by this
  * service.
  */
@@ -1900,9 +1876,6 @@
   {&handle_client_request_connect, NULL,
    GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT,
    sizeof (struct ConnectMessage)},
-  {&handle_client_request_disconnect, NULL,
-   GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT,
-   sizeof (struct ConnectMessage)},
   {NULL, NULL, 0, 0}
 };
 

Modified: gnunet/src/include/gnunet_core_service.h
===================================================================
--- gnunet/src/include/gnunet_core_service.h    2010-01-22 17:15:29 UTC (rev 
10123)
+++ gnunet/src/include/gnunet_core_service.h    2010-01-22 17:27:16 UTC (rev 
10124)
@@ -232,43 +232,13 @@
 
 
 /**
- * Request that the core should try to disconnect from a particular
- * peer.  Once the request has been transmitted to the core, the
- * continuation function will be called.  Note that this does NOT mean
- * that a connection was successfully cut -- it only means that the
- * core will now try.  Typically this will work pretty much
- * immediately, but it is at least in theory also possible that a
- * reconnect is also triggered rather quickly.  Successful creation
- * and destruction of connections will be signalled to the 'connects'
- * and 'disconnects' callback arguments of 'GNUNET_CORE_connect' only.
- * If the core service does not respond to our connection attempt
- * within the given time frame, 'cont' will be called with the TIMEOUT
- * reason code.
+ * Cancel a pending request to connect to a particular peer.  Must not
+ * be called after the 'cont' function was invoked.
  *
- * @param sched scheduler to use
- * @param cfg configuration to use
- * @param timeout how long to try to talk to core
- * @param cont function to call once the request has been completed (or timed 
out)
- * @param cont_cls closure for cont
- * @return NULL on error (cont will not be called), otherwise handle for 
cancellation
- */
-struct GNUNET_CORE_PeerRequestHandle *
-GNUNET_CORE_peer_request_disconnect (struct GNUNET_SCHEDULER_Handle *sched,
-                                    const struct GNUNET_CONFIGURATION_Handle 
*cfg,
-                                    struct GNUNET_TIME_Relative timeout,
-                                    const struct GNUNET_PeerIdentity * peer,
-                                    GNUNET_SCHEDULER_Task cont,
-                                    void *cont_cls);
-
-
-/**
- * Cancel a pending request to connect or disconnect from/to a particular
- * peer.   Must not be called after the 'cont' function was invoked.
- *
  * @param req request handle that was returned for the original request
  */
 void
-GNUNET_CORE_peer_request_cancel (struct GNUNET_CORE_PeerRequestHandle *req);
+GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle 
*req);
 
 
 /**

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2010-01-22 17:15:29 UTC (rev 
10123)
+++ gnunet/src/include/gnunet_protocols.h       2010-01-22 17:27:16 UTC (rev 
10124)
@@ -307,12 +307,7 @@
  */
 #define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT 74
 
-/**
- * Request from client asking to disconnect from a peer.
- */
-#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT 75
 
-
 /**
  * Session key exchange between peers.
  */

Modified: gnunet/src/include/gnunet_transport_service.h
===================================================================
--- gnunet/src/include/gnunet_transport_service.h       2010-01-22 17:15:29 UTC 
(rev 10123)
+++ gnunet/src/include/gnunet_transport_service.h       2010-01-22 17:27:16 UTC 
(rev 10124)
@@ -223,6 +223,13 @@
 
 
 
+/**
+ * Function called whenever there is an update to the
+ * HELLO of this peer.
+ *
+ * @param cls closure
+ * @param hello our updated HELLO
+ */
 typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls,
                                                     const struct 
GNUNET_MessageHeader *hello);
 

Modified: gnunet/src/topology/gnunet-daemon-topology.c
===================================================================
--- gnunet/src/topology/gnunet-daemon-topology.c        2010-01-22 17:15:29 UTC 
(rev 10123)
+++ gnunet/src/topology/gnunet-daemon-topology.c        2010-01-22 17:27:16 UTC 
(rev 10124)
@@ -87,7 +87,7 @@
    * Our handle for the request to connect to this peer; NULL if no
    * such request is pending.
    */
-  struct GNUNET_CORE_TransmitHandle *connect_req;  
+  struct GNUNET_CORE_PeerRequestHandle *connect_req;  
 
   /**
    * Pointer to the HELLO message of this peer; can be NULL.
@@ -158,8 +158,8 @@
   /**
    * Our request handle.
    */
-  struct GNUNET_CORE_PeerRequestHandle *rh;
-
+  struct GNUNET_TRANSPORT_BlacklistRequest *rh;
+  
   /**
    * Peer we tried to disconnect.
    */
@@ -268,9 +268,7 @@
 
 
 /**
- * Force a disconnect from the specified peer.  This is currently done by
- * changing the bandwidth policy to 0 bytes per second.  
- * FIXME: maybe we want a nicer CORE API for both connect and disconnect...
+ * Force a disconnect from the specified peer. 
  * FIXME: this policy change is never undone; how do we reconnect ever?
  */
 static void
@@ -283,43 +281,25 @@
   GNUNET_CONTAINER_DLL_insert (disconnect_head,
                               disconnect_tail,
                               dl);
-  dl->rh = GNUNET_CORE_peer_request_disconnect (sched, cfg,                    
                        
-                                               GNUNET_TIME_UNIT_FOREVER_REL,
-                                               peer,
-                                               &disconnect_done,
-                                               dl);
+  dl->rh = GNUNET_TRANSPORT_blacklist (sched, cfg,                             
                
+                                      peer,
+                                      GNUNET_TIME_UNIT_FOREVER_REL,
+                                      GNUNET_TIME_UNIT_FOREVER_REL,
+                                      &disconnect_done,
+                                      dl);
 }
 
 
 /**
  * Function called by core when our attempt to connect succeeded.
- * Transmits a 'DUMMY' message to trigger the session key exchange.
- * FIXME: this is an issue with the current CORE API.
  */
-static size_t
-ready_callback (void *cls,
-               size_t size, void *buf)
+static void
+connect_completed_callback (void *cls,
+                           const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct PeerList *pos = cls;
-  struct GNUNET_MessageHeader hdr;
 
   pos->connect_req = NULL;
-  if (buf == NULL)
-    {
-#if DEBUG_TOPOLOGY
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                 "Core told us that our attempt to connect failed.\n");
-#endif
-      return 0;
-    }
-#if DEBUG_TOPOLOGY
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Sending dummy message to establish connection.\n");
-#endif
-  hdr.size = htons (sizeof (struct GNUNET_MessageHeader));
-  hdr.type = htons (GNUNET_MESSAGE_TYPE_TOPOLOGY_DUMMY);
-  memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader));
-  return sizeof (struct GNUNET_MessageHeader);
 }
 
 
@@ -340,13 +320,11 @@
              "Asking core to connect to `%s'\n",
              GNUNET_i2s (&pos->id));
 #endif
-  pos->connect_req = GNUNET_CORE_notify_transmit_ready (handle,
-                                                       0 /* priority */,
-                                                       
GNUNET_TIME_UNIT_MINUTES,
-                                                       &pos->id,
-                                                       sizeof(struct 
GNUNET_MessageHeader),
-                                                       &ready_callback,
-                                                       pos);
+  pos->connect_req = GNUNET_CORE_peer_request_connect (sched, cfg,
+                                                      GNUNET_TIME_UNIT_MINUTES,
+                                                      &pos->id,
+                                                      
&connect_completed_callback,
+                                                      pos);
 }
 
 
@@ -457,7 +435,7 @@
    if (pos->hello_req != NULL)
      GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req);
    if (pos->connect_req != NULL)
-     GNUNET_CORE_notify_transmit_ready_cancel (pos->connect_req);            
+     GNUNET_CORE_peer_request_connect_cancel (pos->connect_req);             
    if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK)
      GNUNET_SCHEDULER_cancel (sched,
                              pos->hello_delay_task);
@@ -1203,7 +1181,7 @@
       GNUNET_CONTAINER_DLL_remove (disconnect_head,
                                   disconnect_tail,
                                   dl);
-      GNUNET_CORE_peer_request_cancel (dl->rh);
+      GNUNET_TRANSPORT_blacklist_cancel (dl->rh);
       GNUNET_free (dl);
     }
 }





reply via email to

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